def test_get_device_from_pci_address(self): pcinetdev = mock.MagicMock() self.patch_object(pci.PCINetDevices, 'get_pci_ethernet_addresses') self.patch_object(pci, 'PCINetDevice') self.PCINetDevice.return_value = pcinetdev self.get_pci_ethernet_addresses.return_value = ['pciaddr'] pcinetdev.pci_address = 'pciaddr' a = pci.PCINetDevices() self.assertEqual(a.get_device_from_pci_address('pciaddr'), pcinetdev)
def test_get_macs(self): pcinetdev = mock.MagicMock() self.patch_object(pci.PCINetDevices, 'get_pci_ethernet_addresses') self.patch_object(pci, 'PCINetDevice') self.PCINetDevice.return_value = pcinetdev self.get_pci_ethernet_addresses.return_value = ['pciaddr'] pcinetdev.mac_address = 'mac1' a = pci.PCINetDevices() self.assertEqual(a.get_macs(), ['mac1'])
def test_update_devices(self): pcinetdev = mock.MagicMock() self.patch_object(pci.PCINetDevices, 'get_pci_ethernet_addresses') self.patch_object(pci, 'PCINetDevice') self.PCINetDevice.return_value = pcinetdev self.get_pci_ethernet_addresses.return_value = ['pciaddr'] a = pci.PCINetDevices() a.update_devices() pcinetdev.update_attributes.assert_called_once_with()
def test_get_pci_ethernet_addresses(self): self.patch_object(pci, 'subprocess') self.patch_object(pci, 'PCINetDevice') self.subprocess.check_output.side_effect = \ mocked_subprocess() a = pci.PCINetDevices() self.assertEqual( a.get_pci_ethernet_addresses(), ['0000:06:00.0', '0000:07:00.0', '0000:10:00.0', '0000:10:00.1'])
def test_rebind_orphans(self): self.patch_object(pci.PCINetDevices, 'get_pci_ethernet_addresses') self.patch_object(pci.PCINetDevices, 'unbind_orphans') self.patch_object(pci.PCINetDevices, 'bind_orphans') self.patch_object(pci, 'PCINetDevice') self.get_pci_ethernet_addresses.return_value = [] a = pci.PCINetDevices() a.rebind_orphans() self.unbind_orphans.assert_called_once_with() self.bind_orphans.assert_called_once_with()
def test_get_orphans(self): pcinetdev = mock.MagicMock() self.patch_object(pci.PCINetDevices, 'get_pci_ethernet_addresses') self.patch_object(pci, 'PCINetDevice') self.PCINetDevice.return_value = pcinetdev self.get_pci_ethernet_addresses.return_value = ['pciaddr'] pcinetdev.loaded_kmod = None pcinetdev.interface_name = None pcinetdev.mac_address = None a = pci.PCINetDevices() self.assertEqual(a.get_orphans(), [pcinetdev])
def test_unbind_orphans(self): orphan = mock.MagicMock() self.patch_object(pci.PCINetDevices, 'get_pci_ethernet_addresses') self.get_pci_ethernet_addresses.return_value = ['pciaddr'] self.patch_object(pci.PCINetDevices, 'get_orphans') self.patch_object(pci.PCINetDevices, 'update_devices') self.patch_object(pci, 'PCINetDevice') self.get_orphans.return_value = [orphan] a = pci.PCINetDevices() a.unbind_orphans() orphan.unbind.assert_called_once_with() self.update_devices.assert_called_once_with()
def test_init(self): self.patch_object(pci.PCINetDevices, 'get_pci_ethernet_addresses') self.patch_object(pci, 'PCINetDevice') self.get_pci_ethernet_addresses.return_value = ['pciaddr'] pci.PCINetDevices() self.PCINetDevice.assert_called_once_with('pciaddr')