def test_pci_pool_to_dict(self):
     tags = {'t1': 'foo', 't2': 'bar'}
     pool_obj = objects.PciDevicePool(product_id='pid', tags=tags)
     pool_dict = pool_obj.to_dict()
     self.assertEqual({
         'product_id': 'pid',
         't1': 'foo',
         't2': 'bar'
     }, pool_dict)
Esempio n. 2
0
    def test_stat_consumption_from_instance_pci(self):

        inst_topology = objects.InstanceNUMATopology(
                            cells = [objects.InstanceNUMACell(
                                                      cpuset=set([0]),
                                                      memory=512, id=0)])

        fake_requests = [{'request_id': 'fake_request1', 'count': 1,
                          'spec': [{'vendor_id': '8086'}]}]
        fake_requests_obj = objects.InstancePCIRequests(
                                requests=[objects.InstancePCIRequest(**r)
                                          for r in fake_requests],
                                instance_uuid='fake-uuid')
        instance = objects.Instance(root_gb=0, ephemeral_gb=0, memory_mb=512,
                        vcpus=1,
                        project_id='12345', vm_state=vm_states.BUILDING,
                        task_state=task_states.SCHEDULING, os_type='Linux',
                        uuid='fake-uuid',
                        numa_topology=inst_topology,
                        pci_requests=fake_requests_obj,
                        id = 1243)
        req_spec = sched_utils.build_request_spec(None,
                                                  None,
                                                  [instance],
                                                  objects.Flavor(
                                                             root_gb=0,
                                                             ephemeral_gb=0,
                                                             memory_mb=1024,
                                                             vcpus=1))
        host = host_manager.HostState("fakehost", "fakenode")
        self.assertIsNone(host.updated)
        host.pci_stats = pci_stats.PciDeviceStats(
                                      [objects.PciDevicePool(vendor_id='8086',
                                                             product_id='15ed',
                                                             numa_node=1,
                                                             count=1)])
        host.numa_topology = fakes.NUMA_TOPOLOGY
        host.consume_from_instance(req_spec['instance_properties'])
        self.assertIsInstance(req_spec['instance_properties']['numa_topology'],
                              objects.InstanceNUMATopology)

        self.assertEqual(512, host.numa_topology.cells[1].memory_usage)
        self.assertEqual(1, host.numa_topology.cells[1].cpu_usage)
        self.assertEqual(0, len(host.pci_stats.pools))
        self.assertIsNotNone(host.updated)
Esempio n. 3
0
    def test_stat_consumption_from_instance_pci(self):

        inst_topology = objects.InstanceNUMATopology(
                            cells = [objects.InstanceNUMACell(
                                                      cpuset=set([0]),
                                                      memory=512, id=0)])

        fake_requests = [{'request_id': 'fake_request1', 'count': 1,
                          'spec': [{'vendor_id': '8086'}]}]
        fake_requests_obj = objects.InstancePCIRequests(
                                requests=[objects.InstancePCIRequest(**r)
                                          for r in fake_requests],
                                instance_uuid='fake-uuid')
        req_spec = objects.RequestSpec(
            instance_uuid='fake-uuid',
            project_id='12345',
            numa_topology=inst_topology,
            pci_requests=fake_requests_obj,
            flavor=objects.Flavor(root_gb=0,
                                  ephemeral_gb=0,
                                  memory_mb=512,
                                  vcpus=1))
        host = host_manager.HostState("fakehost", "fakenode")
        self.assertIsNone(host.updated)
        host.pci_stats = pci_stats.PciDeviceStats(
                                      [objects.PciDevicePool(vendor_id='8086',
                                                             product_id='15ed',
                                                             numa_node=1,
                                                             count=1)])
        host.numa_topology = fakes.NUMA_TOPOLOGY
        host.consume_from_request(req_spec)
        self.assertIsInstance(req_spec.numa_topology,
                              objects.InstanceNUMATopology)

        self.assertEqual(512, host.numa_topology.cells[1].memory_usage)
        self.assertEqual(1, host.numa_topology.cells[1].cpu_usage)
        self.assertEqual(0, len(host.pci_stats.pools))
        self.assertIsNotNone(host.updated)
 def test_obj_make_compatible(self):
     pool_obj = objects.PciDevicePool(product_id='pid', numa_node=1)
     primitive = pool_obj.obj_to_primitive()
     self.assertIn('numa_node', primitive['nova_object.data'])
     pool_obj.obj_make_compatible(primitive['nova_object.data'], '1.0')
     self.assertNotIn('numa_node', primitive['nova_object.data'])
 def test_pci_pool_to_dict_with_tags_unset(self):
     pool_obj = objects.PciDevicePool(product_id='pid')
     pool_dict = pool_obj.to_dict()
     self.assertEqual({'product_id': 'pid'}, pool_dict)
 def test_pci_pool_to_dict_no_tags(self):
     pool_obj = objects.PciDevicePool(product_id='pid', tags={})
     pool_dict = pool_obj.to_dict()
     self.assertEqual({'product_id': 'pid'}, pool_dict)