diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-06-30 14:19:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 14:19:38 -0400 |
commit | 882f1a5f2d5bafd08e6900a2782c3affa67c9d86 (patch) | |
tree | 9cd90da0ae7068b3326617d093680ea7b5866cb8 /cloudinit/distros/tests | |
parent | 66e114a660c53400e389f119781f378311b65108 (diff) | |
download | vyos-cloud-init-882f1a5f2d5bafd08e6900a2782c3affa67c9d86.tar.gz vyos-cloud-init-882f1a5f2d5bafd08e6900a2782c3affa67c9d86.zip |
networking: refactor is_physical from cloudinit.net (#457)
As the first refactor PR, this also includes the initial structure for tests.
LP: #1884619
Diffstat (limited to 'cloudinit/distros/tests')
-rw-r--r-- | cloudinit/distros/tests/test_networking.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/cloudinit/distros/tests/test_networking.py b/cloudinit/distros/tests/test_networking.py new file mode 100644 index 00000000..2acb12f4 --- /dev/null +++ b/cloudinit/distros/tests/test_networking.py @@ -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) |