-
Notifications
You must be signed in to change notification settings - Fork 1.1k
networking: refactor is_physical from cloudinit.net #457
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b792f17
refactor callsites of is_physical to use distro.networking
OddBloke 6d2c8e7
networking: refactor is_physical from cloudinit.net
OddBloke 4872659
test_opennebula: add test for get_physical_nics_by_mac
OddBloke 1e07dd4
test_opennebula: ensure distro passed to get_physical_nics_by_mac
OddBloke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
|
|
||
| from cloudinit.distros.networking import BSDNetworking, LinuxNetworking | ||
|
|
||
|
|
||
| @pytest.yield_fixture | ||
| def sys_class_net(tmpdir): | ||
| sys_class_net_path = tmpdir.join("sys/class/net") | ||
| sys_class_net_path.ensure_dir() | ||
| with mock.patch( | ||
| "cloudinit.net.get_sys_class_path", | ||
| return_value=sys_class_net_path.strpath + "/", | ||
| ): | ||
| yield sys_class_net_path | ||
|
|
||
|
|
||
| class TestBSDNetworkingIsPhysical: | ||
| def test_raises_notimplementederror(self): | ||
| with pytest.raises(NotImplementedError): | ||
| BSDNetworking().is_physical("eth0") | ||
|
|
||
|
|
||
| class TestLinuxNetworkingIsPhysical: | ||
| def test_returns_false_by_default(self, sys_class_net): | ||
| assert not LinuxNetworking().is_physical("eth0") | ||
|
|
||
| def test_returns_false_if_devname_exists_but_not_physical( | ||
| self, sys_class_net | ||
| ): | ||
| devname = "eth0" | ||
| sys_class_net.join(devname).mkdir() | ||
| assert not LinuxNetworking().is_physical(devname) | ||
|
|
||
| def test_returns_true_if_device_is_physical(self, sys_class_net): | ||
| devname = "eth0" | ||
| device_dir = sys_class_net.join(devname) | ||
| device_dir.mkdir() | ||
| device_dir.join("device").write("") | ||
|
|
||
| assert LinuxNetworking().is_physical(devname) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've had someone from #FreeBSD contribute this piece of sh code:
to list only the physical devices.
we'll have to check this under netbsd / openbsd…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NetBSD does not have
ifconfig -gbut you could perhaps use this instead (also works on FreeBSD):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the help, @suominen
so the question now is, which of these parts can we execute in the shell, and which should we execute in python
i think we could execute
ifconfig -Conly once and cache the result for the lifetime of cloud-init's run with@lru_cacheifconfig -lotoh, could be different every time, no less thanks to our doingsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the thoughts! Just to set expectations, I would expect us to land this PR without a BSD implementation as it isn't supported in the current code, and this is a refactor. Obviously the whole point of this refactoring exercise is to make it easy to identify and address the gaps in networking support (particularly on BSD), so this is an encouraging start!