Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Handle Missing Hostname File in DHCP Configuration #3542

Closed
wants to merge 1 commit into from

Conversation

zhihuiyuze
Copy link

Change Summary

After the initial installation of VyOS, the hostname file does not exist, which prevents DHCP configuration. I added a check for the existence of this file to resolve this issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Component(s) name

Proposed changes

How to test

Architecture:     x86_64
Boot via:         installed image
System type:      KVM guest

Hardware vendor:  QEMU
Hardware model:   Standard PC (i440FX + PIIX, 1996)
Hardware S/N:     
Hardware UUID:    6d392efb-9581-4438-925a-67f195d695ca

Traceback (most recent call last):
  File "/usr/libexec/vyos/conf_mode/interfaces_ethernet.py", line 433, in <module>
    apply(c)
  File "/usr/libexec/vyos/conf_mode/interfaces_ethernet.py", line 410, in apply
    e.update(ethernet)
  File "/usr/lib/python3/dist-packages/vyos/ifconfig/ethernet.py", line 454, in update
    super().update(config)
  File "/usr/lib/python3/dist-packages/vyos/ifconfig/interface.py", line 1603, in update
    self.add_addr(addr)
  File "/usr/lib/python3/dist-packages/vyos/ifconfig/interface.py", line 1194, in add_addr
    self.set_dhcp(True)
  File "/usr/lib/python3/dist-packages/vyos/ifconfig/interface.py", line 1361, in set_dhcp
    with open('/etc/hostname', 'r') as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/etc/hostname'

noteworthy:

After adding the check, the DHCP configuration function no longer reports errors.

Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@c-po
Copy link
Member

c-po commented May 29, 2024

Thanks for the fix!

Please see https://github.com/vyos/vyos-1x/blob/current/CONTRIBUTING.md as every fix requires a task ID which is used to generate release notes.

@c-po
Copy link
Member

c-po commented May 30, 2024

This PR lacks some more context. Which version was used while the bug occured? I've tested

  • 1.4.0-epa2 template in EVE-NG
  • 1.4.0-epa3 live cd
  • 1.4.0-epa3 fresh install and all of them come with a /etc/hostname file.

A slight chance exists that there is a race condition during boot as host-name CLI know is not called with any priority https://github.com/vyos/vyos-1x/blob/c15ee875a6ed6d2f053ad0dd6d576b93a6ea858f/interface-definitions/system_host-name.xml.in

This will be handled via https://vyos.dev/T6421 and thus will solve the potential race condition leading to the root cause for this PR.

Thanks you again for the contribution.

I referenced your initial idea here: cf07a55

@zhihuiyuze
Copy link
Author

I installed the system using vyos-1.5-rolling-202405270020-amd64, and I believe the rolling code corresponds to the current branch on GitHub

Please see https://github.com/vyos/vyos-1x/blob/current/CONTRIBUTING.md as every fix requires a task ID which is used to generate release notes.

Got it. I need to create a task ID first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants