def test_wrong_mac(self): self.mock_get_mac.side_effect = ( exception.PciDeviceNotFoundById(self.pci_address)) net_name = utils.get_net_name_by_vf_pci_address(self.pci_address) self.assertIsNone(net_name) self.mock_get_mac.called_once_with(self.pci_address) self.mock_get_ifname.assert_not_called()
def test_wrong_mac(self): self.mock_get_mac.side_effect = ( exception.PciDeviceNotFoundById(self.pci_address)) net_name = utils.get_net_name_by_vf_pci_address(self.pci_address) self.assertIsNone(net_name) self.mock_get_mac.called_once_with(self.pci_address) self.mock_get_ifname.assert_not_called()
def test_correct_behaviour(self): ref_net_name = ('net_enp7s0f0_ca_fe_ca_fe_ca_fe', 'enp7s0f0') self.mock_get_mac.return_value = self.mac self.mock_get_ifname.return_value = self.if_name net_name = utils.get_net_name_by_vf_pci_address(self.pci_address) self.assertEqual(ref_net_name, net_name) self.mock_get_mac.called_once_with(self.pci_address) self.mock_get_ifname.called_once_with(self.pci_address)
def test_correct_behaviour(self): ref_net_name = ('net_enp7s0f0_ca_fe_ca_fe_ca_fe', 'enp7s0f0') self.mock_get_mac.return_value = self.mac self.mock_get_ifname.return_value = self.if_name net_name = utils.get_net_name_by_vf_pci_address(self.pci_address) self.assertEqual(ref_net_name, net_name) self.mock_get_mac.called_once_with(self.pci_address) self.mock_get_ifname.called_once_with(self.pci_address)
def _get_pcinet_info(self, vf_address): """Returns a dict of NET device.""" devname = pci_utils.get_net_name_by_vf_pci_address(vf_address) if not devname: return ifname = pci_utils.get_ifname_by_pci_address(vf_address) # Features from the that libvirt supported, get them by ethtool -k # Note: I cannot find the rdma feature returned by ethtool, correct me # if the string is wrong. FEATURES_LIST = [ 'rx-checksumming', 'tx-checksumming', 'scatter-gather', 'tcp-segmentation-offload', 'generic-segmentation-offload', 'generic-receive-offload', 'large-receive-offload', 'rx-vlan-offload', 'tx-vlan-offload', 'ntuple-filters', 'receive-hashing', 'tx-udp_tnl-segmentation', 'rdma' ] FEATURES_MAP = { 'rx-checksumming': 'rx', 'tx-checksumming': 'tx', 'scatter-gather': 'sg', 'tcp-segmentation-offload': 'tso', 'generic-segmentation-offload': 'gso', 'generic-receive-offload': 'gro', 'large-receive-offload': 'lro', 'rx-vlan-offload': 'rxvlan', 'tx-vlan-offload': 'txvlan', 'ntuple-filters': 'ntuple', 'receive-hashing': 'rxhash', 'tx-udp_tnl-segmentation': 'txudptnl', 'rdma': 'rdma' } features = [] try: output, status = processutils.execute('ethtool', '-k', ifname) lines = output.split('\n') for line in lines: columns = line.split(":") if columns[0].strip() in FEATURES_LIST: if "on" in columns[1].strip(): features.append(FEATURES_MAP.get(columns[0].strip())) except processutils.ProcessExecutionError: raise exception.CommandError(cmd='ethtool -k') return {'name': devname, 'capabilities': features}
def _get_pcinet_info(self, vf_address): """Returns a dict of NET device.""" devname = pci_utils.get_net_name_by_vf_pci_address(vf_address) if not devname: return ifname = pci_utils.get_ifname_by_pci_address(vf_address) # Features from the that libvirt supported, get them by ethtool -k # Note: I cannot find the rdma feature returned by ethtool, correct me # if the string is wrong. FEATURES_LIST = ['rx-checksumming', 'tx-checksumming', 'scatter-gather', 'tcp-segmentation-offload', 'generic-segmentation-offload', 'generic-receive-offload', 'large-receive-offload', 'rx-vlan-offload', 'tx-vlan-offload', 'ntuple-filters', 'receive-hashing', 'tx-udp_tnl-segmentation', 'rdma'] FEATURES_MAP = {'rx-checksumming': 'rx', 'tx-checksumming': 'tx', 'scatter-gather': 'sg', 'tcp-segmentation-offload': 'tso', 'generic-segmentation-offload': 'gso', 'generic-receive-offload': 'gro', 'large-receive-offload': 'lro', 'rx-vlan-offload': 'rxvlan', 'tx-vlan-offload': 'txvlan', 'ntuple-filters': 'ntuple', 'receive-hashing': 'rxhash', 'tx-udp_tnl-segmentation': 'txudptnl', 'rdma': 'rdma'} features = [] output, status = utils.execute('ethtool', '-k', ifname) lines = output.split('\n') for line in lines: columns = line.split(":") if columns[0].strip() in FEATURES_LIST: if "on" in columns[1].strip(): features.append(FEATURES_MAP.get(columns[0].strip())) return {'name': devname, 'capabilities': features}