def _create_pci_requests_for_sriov_ports(self, context, requested_networks): pci_requests = objects.ContainerPCIRequests(requests=[]) if not requested_networks: return pci_requests neutron_api = neutron.NeutronAPI(context) for request_net in requested_networks: phynet_name = None vnic_type = network_model.VNIC_TYPE_NORMAL if request_net.get('port'): vnic_type, phynet_name = self._get_port_vnic_info( context, neutron_api, request_net['port']) pci_request_id = None if vnic_type in network_model.VNIC_TYPES_SRIOV: spec = {pci_request.PCI_NET_TAG: phynet_name} dev_type = pci_request.DEVICE_TYPE_FOR_VNIC_TYPE.get(vnic_type) if dev_type: spec[pci_request.PCI_DEVICE_TYPE_TAG] = dev_type request = objects.ContainerPCIRequest( count=1, spec=[spec], request_id=uuidutils.generate_uuid()) pci_requests.requests.append(request) pci_request_id = request.request_id request_net['pci_request_id'] = pci_request_id return pci_requests
def test_pci_passthrough_with_pci_stats_none(self): request = objects.ContainerPCIRequest( count=1, spec=[{'vendor_id': '8086'}]) requests = objects.ContainerPCIRequests(requests=[request]) container = objects.Container(self.context) host = HostState('testhost') host.pci_stats = None extra_spec = {'pci_requests': requests} self.assertFalse(self.filt_cls.host_passes(host, container, extra_spec))
def test_pci_passthrough_pass(self): pci_stats_mock = mock.MagicMock() pci_stats_mock.support_requests.return_value = True request = objects.ContainerPCIRequest( count=1, spec=[{'vendor_id': '8086'}]) requests = objects.ContainerPCIRequests(requests=[request]) container = objects.Container(self.context) host = HostState('testhost') host.pci_stats = pci_stats_mock extra_spec = {'pci_requests': requests} self.assertTrue(self.filt_cls.host_passes(host, container, extra_spec)) pci_stats_mock.support_requests.assert_called_once_with( requests.requests)