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

vyos_net_name: T6544: Updated the vyos_net_name script (backport from current) #3806

Closed
wants to merge 2 commits into from

Conversation

zdc
Copy link
Contributor

@zdc zdc commented Jul 11, 2024

Change Summary

Updated the vyos_net_name script

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

udev, vyos_net_name

Proposed changes

Improvements in the vyos_net_name:

  • Used a new locking system, to be sure that multiple running scripts will not try to perform operations at the same time.
  • Replace logging from a file to syslog. This is common with all the rest logs, and additionally gives a better view of actions done during a boot.
  • Small bug fix in get_configfile_interfaces(): exit with an error in case a config file cannot be parsed. This resolves potentially an unbound config object.
  • Minor formatting fixes to follow our requirements.

How to test

Boot with a config like this on a device where eth0 and eth1 interfaces defined in it are connected via PCIe, and there are at least two extra onboard NICs :

interfaces {
    ethernet eth0 {
        hw-id "xx:xx:xx:xx:xx:xx"
    }
    ethernet eth1 {
        hw-id "xx:xx:xx:xx:xx:xx"
    }
    loopback lo {
    }
}

The easiest way to see a difference is to check logs - without a new locking system they are out of order:

INFO:root:lookup e3, <REDACTED>
INFO:root:lookup e2, <REDACTED>
INFO:root:lookup e5, <REDACTED>
INFO:root:lookup e4, <REDACTED>
DEBUG:root:config file entries: {'<REDACTED>: 'eth0', ' <REDACTED>': 'eth1'}
DEBUG:root:config file entries: {'<REDACTED>': 'eth0', ' <REDACTED>': 'eth1'}
DEBUG:root:config file entries: {'<REDACTED>': 'eth0', ' <REDACTED>': 'eth1'}
DEBUG:root:config file interfaces are {'<REDACTED>': 'eth0', ' <REDACTED>': 'eth1'}
DEBUG:root:config file interfaces are {'<REDACTED>': 'eth0', ' <REDACTED>': 'eth1'}
DEBUG:root:config file interfaces are {'<REDACTED>': 'eth0', ' <REDACTED>': 'eth1'}
INFO:root:use mapping from config file: '<REDACTED>' -> 'eth1'
DEBUG:root:adding assigned interfaces: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
DEBUG:root:adding assigned interfaces: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
DEBUG:root:on boot, returned name is eth1
DEBUG:root:config file entries: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
DEBUG:root:config file interfaces are {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
INFO:root:use mapping from config file: '<REDACTED>' -> 'eth0'
DEBUG:root:on boot, returned name is eth0
INFO:root:biosdevname returned 'eth1' for 'e3'
INFO:root:new name for 'e3' is 'eth2'
DEBUG:root:on boot, returned name is eth2
INFO:root:biosdevname returned 'eth0' for 'e2'
INFO:root:new name for 'e2' is 'eth2'
DEBUG:root:on boot, returned name is eth2

With an updated file, everything is in order:

Jul 03 20:15:17 c3-small-x86-01 vyos_net_name[1123]: Started with arguments: ['/lib/udev/vyos_net_name', 'e3', '<REDACTED>']
Jul 03 20:15:17 c3-small-x86-01 vyos_net_name[1133]: Started with arguments: ['/lib/udev/vyos_net_name', 'e4', '<REDACTED>']
Jul 03 20:15:17 c3-small-x86-01 vyos_net_name[1132]: Started with arguments: ['/lib/udev/vyos_net_name', 'e5', '<REDACTED>']
Jul 03 20:15:17 c3-small-x86-01 vyos_net_name[1133]: lookup e4, <REDACTED>
Jul 03 20:15:17 c3-small-x86-01 vyos_net_name[1122]: Started with arguments: ['/lib/udev/vyos_net_name', 'e2', '<REDACTED>']
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1133]: config file entries: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1133]: config file interfaces are {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1133]: use mapping from config file: '<REDACTED>' -> 'eth0'
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1133]: on boot, returned name is eth0
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1133]: Finished
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1132]: lookup e5, <REDACTED>
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1132]: config file entries: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1132]: config file interfaces are {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1132]: use mapping from config file: '<REDACTED>' -> 'eth1'
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1132]: on boot, returned name is eth1
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1132]: Finished
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1122]: lookup e2, <REDACTED>
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1122]: config file entries: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1122]: config file interfaces are {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:18 c3-small-x86-01 vyos_net_name[1122]: adding assigned interfaces: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1122]: biosdevname returned 'eth0' for 'e2'
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1122]: new name for 'e2' is 'eth2'
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1122]: on boot, returned name is eth2
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1122]: Finished
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1123]: lookup e3, <REDACTED>
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1123]: config file entries: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1123]: config file interfaces are {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1'}
Jul 03 20:15:19 c3-small-x86-01 vyos_net_name[1123]: adding assigned interfaces: {'<REDACTED>': 'eth0', '<REDACTED>': 'eth1', '<REDACTED>': 'eth2'}
Jul 03 20:15:20 c3-small-x86-01 vyos_net_name[1123]: biosdevname returned 'eth1' for 'e3'
Jul 03 20:15:20 c3-small-x86-01 vyos_net_name[1123]: new name for 'e3' is 'eth3'
Jul 03 20:15:20 c3-small-x86-01 vyos_net_name[1123]: on boot, returned name is eth3
Jul 03 20:15:20 c3-small-x86-01 vyos_net_name[1123]: Finished

Smoketest result

N/A

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

@zdc zdc requested a review from a team as a code owner July 11, 2024 09:58
@github-actions github-actions bot added the sagitta VyOS 1.4 LTS label Jul 11, 2024
Copy link

github-actions bot commented Jul 11, 2024

👍
No issues in PR Title / Commit Title

Copy link

github-actions bot commented Jul 11, 2024


warning: Unused directories imported from vyos.defaults in src/conf_mode/system_console.py:25.

@zdc
Copy link
Contributor Author

zdc commented Jul 11, 2024

@Mergifyio backport circinus

Copy link
Contributor

mergify bot commented Jul 11, 2024

backport circinus

🟠 Waiting for conditions to match

  • merged [📌 backport requirement]

if re.match("^e[0-9]+$", ifname):
intf = ifname.split("e")
"""Check interface with names eX and return ifname on the next format eth{ifindex} - 2"""
if re.match('^e[0-9]+$', ifname):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big performance problem for short strings, but I'd still do a match first, then check if the match object was None and used the match groups if it wasn't, instead of calling .split() on it, since re.match() result can already give us the substring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is old code, just reformatted according to new rules. I believe code optimization is a separate task.

@@ -95,11 +89,12 @@ def get_biosdevname(ifname: str) -> str:
try:
biosname = cmd(f'/sbin/biosdevname --policy all_ethN -i {ifname}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the missing --allow-vm argument here, if we are using biosdevname for now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this is the only reason we keep a fork of biosdevname? If so, we should add it.

@sever-sever
Copy link
Member

It should first be in the current -> circinus > sagitta
You are trying to create PR to sagitta and backport to circinus. This is the wrong way.

@dmbaturin
Copy link
Member

FIY: the PR to deprecate biosdevname is in: #3821

Copy link
Member

@sever-sever sever-sever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved as it is already in the current
If we want to change something we should change it in the current and then backport it

@zdc zdc changed the base branch from sagitta to circinus August 1, 2024 15:58
zdc added 2 commits August 1, 2024 19:02
Sometimes we need a reliable way to lock an execution until some other operation
is not done.

This commit introduces locking util, which can be used as a common lock, even
between different processes.

Usage example:

```
from vyos.utils.locking import Lock

lock = Lock('my_lock_id')
lock.acquire(timeout=10)

print(f'Lock acquired: {lock.is_locked}')

lock.release()
```
Improvements in the `vyos_net_name`:

- Used a new locking system, to be sure that multiple running scripts will not
try to perform operations at the same time.
- Replace logging from a file to syslog. This is common with all the rest logs,
and additionally gives a better view of actions done during a boot.
- Small bug fix in `get_configfile_interfaces()`: exit with an error in case a
config file cannot be parsed. This resolves potentially an unbound `config` object.
- Minor formatting fixes to follow our requirements.
@zdc
Copy link
Contributor Author

zdc commented Aug 1, 2024

@Mergifyio dequeue

Copy link
Contributor

mergify bot commented Aug 1, 2024

dequeue

☑️ The pull request is not queued

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@sever-sever
Copy link
Member

@zdc could you rebase or solve conflicts?

@sever-sever sever-sever self-requested a review October 16, 2024 13:12
@sever-sever
Copy link
Member

Backported to the circinus our org
we can close it

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

Successfully merging this pull request may close these issues.

4 participants