Exemplo n.º 1
0
 def test_physical_function(self, mock_readlink, *args):
     ifname = 'eth0'
     totalvf_path = "/sys/class/net/%s/device/%s" % (ifname,
                                                     utils._SRIOV_TOTALVFS)
     mock_readlink.return_value = '../../../0000:00:00.1'
     with mock.patch.object(builtins, 'open',
                            mock.mock_open(read_data='4')) as mock_open:
         address, physical_function = utils.get_function_by_ifname('eth0')
         self.assertEqual(address, '0000:00:00.1')
         self.assertTrue(physical_function)
         mock_open.assert_called_once_with(totalvf_path)
Exemplo n.º 2
0
 def test_physical_function(self, mock_readlink, *args):
     ifname = 'eth0'
     totalvf_path = "/sys/class/net/%s/device/%s" % (ifname,
                                                     utils._SRIOV_TOTALVFS)
     mock_readlink.return_value = '../../../0000:00:00.1'
     with mock.patch.object(builtins, 'open',
                            mock.mock_open(read_data='4')) as mock_open:
         address, physical_function = utils.get_function_by_ifname('eth0')
         self.assertEqual(address, '0000:00:00.1')
         self.assertTrue(physical_function)
         mock_open.assert_called_once_with(totalvf_path)
Exemplo n.º 3
0
 def match(self, dev_dict):
     if self.dev_name:
         address_str, pf = utils.get_function_by_ifname(self.dev_name)
         if not address_str:
             return False
         # Note(moshele): In this case we always passing a string
         # of the PF pci address
         address_obj = WhitelistPciAddress(address_str, pf)
     elif self.address:
         address_obj = self.address
     return all([
         self.vendor_id in (ANY, dev_dict['vendor_id']), self.product_id
         in (ANY, dev_dict['product_id']),
         address_obj.match(dev_dict['address'], dev_dict.get('parent_addr'))
     ])
Exemplo n.º 4
0
 def test_virtual_function(self, mock_readlink, *args):
     mock_readlink.return_value = '../../../0000.00.00.1'
     with mock.patch.object(builtins, 'open', side_effect=IOError()):
         address, physical_function = utils.get_function_by_ifname('eth0')
         self.assertEqual(address, '0000.00.00.1')
         self.assertFalse(physical_function)
Exemplo n.º 5
0
 def test_exception(self, *args):
     address, physical_function = utils.get_function_by_ifname('lo')
     self.assertIsNone(address)
     self.assertFalse(physical_function)
Exemplo n.º 6
0
 def test_virtual_function(self, mock_readlink, *args):
     mock_readlink.return_value = '../../../0000.00.00.1'
     with mock.patch.object(builtins, 'open', side_effect=IOError()):
         address, physical_function = utils.get_function_by_ifname('eth0')
         self.assertEqual(address, '0000.00.00.1')
         self.assertFalse(physical_function)
Exemplo n.º 7
0
 def test_exception(self, *args):
     address, physical_function = utils.get_function_by_ifname('lo')
     self.assertIsNone(address)
     self.assertFalse(physical_function)