Example #1
0
    def test__set_sriov_numvfs(self, mock_sysnet_ints):
        mock_sysnet_ints.side_effect = [{
            'interface': 'eth2',
            'mac_address': 'a8:9d:21:cf:93:fc',
            'pci_address': '0000:10:00.0',
            'state': 'up',
            'sriov': True,
            'sriov_totalvfs': 7,
            'sriov_numvfs': 0
        }], [{
            'interface': 'eth2',
            'mac_address': 'a8:9d:21:cf:93:fc',
            'pci_address': '0000:10:00.0',
            'state': 'up',
            'sriov': True,
            'sriov_totalvfs': 7,
            'sriov_numvfs': 4
        }]
        dev = pci.PCINetDevice('0000:10:00.0')
        self.assertEqual('eth2', dev.interface_name)
        self.assertTrue(dev.sriov)
        self.assertEqual(7, dev.sriov_totalvfs)
        self.assertEqual(0, dev.sriov_numvfs)

        with patch_open() as (mock_open, mock_file):
            dev._set_sriov_numvfs(4)
            mock_open.assert_called_with(
                '/sys/class/net/eth2/device/sriov_numvfs', 'w')
            mock_file.write.assert_called_with("4")
            self.assertTrue(dev.sriov)
            self.assertEqual(7, dev.sriov_totalvfs)
            self.assertEqual(4, dev.sriov_numvfs)
Example #2
0
 def test_get_sysnet_device_state(self, _update):
     device = pci.PCINetDevice('0000:10:00.1')
     with patch_open() as (_open, _file):
         super_fh = mocked_filehandle()
         _file.readlines = MagicMock()
         _open.side_effect = super_fh._setfilename
         _file.read.side_effect = super_fh._getfilecontents_read
         state = device.get_sysnet_device_state('/sys/class/net/eth3')
     self.assertEqual(state, 'down')
Example #3
0
 def test_get_sysnet_mac(self, _update):
     device = pci.PCINetDevice('0000:10:00.1')
     with patch_open() as (_open, _file):
         super_fh = mocked_filehandle()
         _file.readlines = MagicMock()
         _open.side_effect = super_fh._setfilename
         _file.read.side_effect = super_fh._getfilecontents_read
         macaddr = device.get_sysnet_mac('/sys/class/net/eth3')
     self.assertEqual(macaddr, 'a8:9d:21:cf:93:fd')
Example #4
0
    def eth_int(self, pci_address, _osrealpath, _osislink, subproc_map=None):
        self.glob.glob.side_effect = mocked_globs
        _osislink.side_effect = mocked_islink
        _osrealpath.side_effect = mocked_realpath
        self.subprocess.check_output.side_effect = mocked_subprocess(
            subproc_map=subproc_map)

        with patch_open() as (_open, _file):
            super_fh = mocked_filehandle()
            _file.readlines = MagicMock()
            _open.side_effect = super_fh._setfilename
            _file.read.side_effect = super_fh._getfilecontents_read
            _file.readlines.side_effect = super_fh._getfilecontents_readlines
            netint = pci.PCINetDevice(pci_address)
        return netint
Example #5
0
 def test_update_interface_info_eth(self, _update, _sysnet_ints):
     dev = pci.PCINetDevice('0000:10:00.0')
     _sysnet_ints.return_value = [{
         'interface': 'eth2',
         'mac_address': 'a8:9d:21:cf:93:fc',
         'pci_address': '0000:10:00.0',
         'state': 'up'
     }, {
         'interface': 'eth3',
         'mac_address': 'a8:9d:21:cf:93:fd',
         'pci_address': '0000:10:00.1',
         'state': 'down'
     }]
     dev.update_interface_info_eth()
     self.assertEqual(dev.interface_name, 'eth2')
Example #6
0
 def test_get_sysnet_interfaces_and_macs(self, _update, _interface, _mac,
                                         _state, _osrealpath, _osislink):
     dev = pci.PCINetDevice('0000:06:00.0')
     self.glob.glob.return_value = ['/sys/class/net/eth2']
     _interface.return_value = 'eth2'
     _mac.return_value = 'a8:9d:21:cf:93:fc'
     _state.return_value = 'up'
     _osrealpath.return_value = ('/sys/devices/pci0000:00/0000:00:02.0/'
                                 '0000:02:00.0/0000:03:00.0/0000:04:00.0/'
                                 '0000:05:01.0/0000:07:00.0')
     expect = {
         'interface': 'eth2',
         'mac_address': 'a8:9d:21:cf:93:fc',
         'pci_address': '0000:07:00.0',
         'state': 'up',
     }
     self.assertEqual(dev.get_sysnet_interfaces_and_macs(), [expect])
Example #7
0
 def test_get_sysnet_interface(self, _update):
     device = pci.PCINetDevice('0000:10:00.1')
     self.assertEqual(device.get_sysnet_interface('/sys/class/net/eth3'),
                      'eth3')
Example #8
0
 def test_set_sriov_numvfs_avoid_call(self, mock__set_sriov_numvfs):
     dev = pci.PCINetDevice('0000:10:00.0')
     dev.sriov = True
     dev.sriov_numvfs = 4
     dev.set_sriov_numvfs(4)
     self.assertFalse(mock__set_sriov_numvfs.called)
Example #9
0
 def test_set_sriov_numvfs(self, mock__set_sriov_numvfs):
     dev = pci.PCINetDevice('0000:10:00.0')
     dev.sriov = True
     dev.set_sriov_numvfs(4)
     mock__set_sriov_numvfs.assert_has_calls([call(0), call(4)])