def test_pci_request_in_filter_properties(self): instance_type = {} request_spec = {"instance_type": instance_type, "instance_properties": {"project_id": 1, "os_type": "Linux"}} filter_properties = {} requests = [{"count": 1, "spec": [{"vendor_id": "8086"}]}] self.mox.StubOutWithMock(pci_request, "get_pci_requests_from_flavor") pci_request.get_pci_requests_from_flavor(instance_type).AndReturn(requests) self.mox.ReplayAll() self.driver.populate_filter_properties(request_spec, filter_properties) self.assertEqual(filter_properties.get("pci_requests"), requests)
def test_pci_request_in_filter_properties(self): instance_type = {} request_spec = {'instance_type': instance_type, 'instance_properties': {'project_id': 1, 'os_type': 'Linux'}} filter_properties = {} requests = [{'count': 1, 'spec': [{'vendor_id': '8086'}]}] self.mox.StubOutWithMock(pci_request, 'get_pci_requests_from_flavor') pci_request.get_pci_requests_from_flavor( instance_type).AndReturn(requests) self.mox.ReplayAll() self.driver.populate_filter_properties( request_spec, filter_properties) self.assertEqual(filter_properties.get('pci_requests'), requests)
def test_pci_request_in_filter_properties(self): instance_type = {} request_spec = {'instance_type': instance_type, 'instance_properties': {'project_id': 1, 'os_type': 'Linux'}} filter_properties = {} requests = [{'count': 1, 'spec': [{'vendor_id': '8086'}]}] self.mox.StubOutWithMock(pci_request, 'get_pci_requests_from_flavor') pci_request.get_pci_requests_from_flavor( instance_type).AndReturn(requests) self.mox.ReplayAll() self.driver.populate_filter_properties( request_spec, filter_properties) self.assertEqual(filter_properties.get('pci_requests'), requests)
def populate_filter_properties(self, request_spec, filter_properties): """Stuff things into filter_properties. Can be overridden in a subclass to add more data. """ # Save useful information from the request spec for filter processing: project_id = request_spec["instance_properties"]["project_id"] os_type = request_spec["instance_properties"]["os_type"] filter_properties["project_id"] = project_id filter_properties["os_type"] = os_type pci_requests = pci_request.get_pci_requests_from_flavor(request_spec.get("instance_type") or {}) if pci_requests: filter_properties["pci_requests"] = pci_requests
def populate_filter_properties(self, request_spec, filter_properties): """Stuff things into filter_properties. Can be overridden in a subclass to add more data. """ # Save useful information from the request spec for filter processing: project_id = request_spec['instance_properties']['project_id'] os_type = request_spec['instance_properties']['os_type'] filter_properties['project_id'] = project_id filter_properties['os_type'] = os_type pci_requests = pci_request.get_pci_requests_from_flavor( request_spec.get('instance_type') or {}) if pci_requests: filter_properties['pci_requests'] = pci_requests
def test_get_pci_requests_from_flavor(self): self.flags(pci_alias=[_fake_alias1, _fake_alias3]) expect_request = [ {'count': 3, 'spec': [{'vendor_id': '8086', 'product_id': '4443', 'device_type': "ACCEL", 'capability_type': 'pci'}], 'alias_name': 'QuicAssist'}, {'count': 1, 'spec': [{'vendor_id': '8086', 'product_id': '1111', 'device_type': "NIC", 'capability_type': 'pci'}], 'alias_name': 'IntelNIC'}, ] flavor = {'extra_specs': {"pci_passthrough:alias": "QuicAssist:3, IntelNIC: 1"}} requests = pci_request.get_pci_requests_from_flavor(flavor) self.assertEqual(set([1, 3]), set([p.count for p in requests.requests])) self._verify_result(expect_request, requests.requests)
def test_get_pci_requests_from_flavor(self): self.flags(pci_alias=[_fake_alias1, _fake_alias3]) expect_request = [ {'count': 3, 'spec': [{'vendor_id': '8086', 'product_id': '4443', 'device_type': "ACCEL", 'capability_type': 'pci'}], 'alias_name': 'QuicAssist'}, {'count': 1, 'spec': [{'vendor_id': '8086', 'product_id': '1111', 'device_type': "NIC", 'capability_type': 'pci'}], 'alias_name': 'IntelNIC'}, ] flavor = {'extra_specs': {"pci_passthrough:alias": "QuicAssist:3, IntelNIC: 1"}} requests = pci_request.get_pci_requests_from_flavor(flavor) self.assertEqual(set([1, 3]), set([p.count for p in requests.requests])) self._verify_result(expect_request, requests.requests)
def test_get_pci_requests_from_flavor_no_extra_spec(self): self.flags(pci_alias=[_fake_alias1, _fake_alias3]) flavor = {} requests = pci_request.get_pci_requests_from_flavor(flavor) self.assertEqual([], requests)
def test_get_pci_requests_from_flavor_no_extra_spec(self): self.flags(pci_alias=[_fake_alias1, _fake_alias3]) flavor = {} requests = pci_request.get_pci_requests_from_flavor(flavor) self.assertEqual([], requests.requests)