def test_get_user_requested_config_empty(self): self.patch_object(pci.PCIInfo, '__init__') self.patch_object(pci.hookenv, 'config') self.config.return_value = None a = pci.PCIInfo() expect = {} self.assertEqual(a.get_user_requested_config(), expect)
def test_get_user_requested_invalid_entries(self): self.patch_object(pci.PCIInfo, '__init__') self.patch_object(pci.hookenv, 'config') self.config.return_value = ('ac=mac1;net=net1 randomstuff' ' mac=mac2;net=net1') a = pci.PCIInfo() expect = {'mac2': [{'net': 'net1'}]} self.assertEqual(a.get_user_requested_config(), expect)
def test_get_user_requested_config(self): self.patch_object(pci.PCIInfo, '__init__') self.patch_object(pci.hookenv, 'config') self.config.return_value = ('mac=mac1;net=net1 mac=mac1;net=net2' ' mac=mac2;net=net1') a = pci.PCIInfo() expect = { 'mac1': [{'net': 'net1'}, {'net': 'net2'}], 'mac2': [{'net': 'net1'}]} self.assertEqual(a.get_user_requested_config(), expect)
def test_init(self): net_dev_mocks = { 'mac1': self.dev_mock('down', 'pciaddr0', 'eth0'), 'mac2': self.dev_mock('down', 'pciaddr1', 'eth1'), 'mac3': self.dev_mock('up', 'pciaddr3', 'eth2'), } net_devs = mock.MagicMock() self.patch_object(pci.PCIInfo, 'get_user_requested_config') self.patch_object(pci, 'PCINetDevices') self.PCINetDevices.return_value = net_devs net_devs.get_macs.return_value = net_dev_mocks.keys() net_devs.get_device_from_mac.side_effect = lambda x: net_dev_mocks[x] self.get_user_requested_config.return_value = { 'mac1': [{ 'net': 'net1' }, { 'net': 'net2' }], 'mac2': [{ 'net': 'net1' }], 'mac3': [{ 'net': 'net1' }] } a = pci.PCIInfo() expect = { 'mac1': [{ 'interface': 'eth0', 'net': 'net1' }, { 'interface': 'eth0', 'net': 'net2' }], 'mac2': [{ 'interface': 'eth1', 'net': 'net1' }] } self.assertEqual(a.local_mac_nets, expect) self.assertEqual(a.vpe_dev_string, 'dev pciaddr0 dev pciaddr1')