def test_exists_argument(self, m_udevadm_settle): LinuxNetworking().settle(exists="ens3") expected_path = net.sys_dev_path("ens3") assert [ mock.call(exists=expected_path) ] == m_udevadm_settle.call_args_list
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)
def test_calls_subp_return_false(self, m_subp, m_is_up): devname = "eth0" m_is_up.return_value = False is_success = LinuxNetworking().try_set_link_up(devname) assert (mock.call(["ip", "link", "set", devname, "up"]) == m_subp.call_args_list[-1]) assert not is_success
def test_calls_subp_return_false(self, m_subp, m_is_up): devname = "eth0" m_is_up.return_value = False is_success = LinuxNetworking().try_set_link_up(devname) assert (mock.call(['ip', 'link', 'set', devname, 'up']) == m_subp.call_args_list[-1]) assert not is_success
def test_apply_v2_renames_skips_without_setname_or_mac( self, config_attr: str ): networking = LinuxNetworking() netcfg = yaml.load(getattr(self, config_attr)) with mock.patch.object( networking, "_rename_interfaces" ) as m_rename_interfaces: networking.apply_network_config_names(netcfg) m_rename_interfaces.assert_called_with([])
def test_apply_renames( self, m_device_driver, m_device_devid, config_attr: str, ): networking = LinuxNetworking() m_device_driver.return_value = "virtio_net" m_device_devid.return_value = "0x15d8" netcfg = yaml.load(getattr(self, config_attr)) with mock.patch.object( networking, "_rename_interfaces" ) as m_rename_interfaces: networking.apply_network_config_names(netcfg) assert ( mock.call( [["52:54:00:12:34:00", "interface0", "virtio_net", "0x15d8"]] ) == m_rename_interfaces.call_args_list[-1] )
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_false_by_default(self, sys_class_net): assert not LinuxNetworking().is_physical("eth0")
def test_no_arguments(self, m_udevadm_settle): LinuxNetworking().settle() assert [mock.call(exists=None)] == m_udevadm_settle.call_args_list
def test_apply_v2_renames_raises_runtime_error_on_unknown_version(self): networking = LinuxNetworking() with pytest.raises(RuntimeError): networking.apply_network_config_names(yaml.load("version: 3"))