Exemplo n.º 1
0
    def test_numa_topology_filter_numa_instance_no_numa_host_fail(self):
        instance_topology = objects.InstanceNUMATopology(cells=[
            objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512),
            objects.InstanceNUMACell(id=1, cpuset=set([3]), memory=512)
        ])
        instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
        instance.numa_topology = instance_topology

        filter_properties = {
            'request_spec': {
                'instance_properties':
                jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
            }
        }
        host = fakes.FakeHostState('host1', 'node1', {'pci_stats': None})
        self.assertFalse(self.filt_cls.host_passes(host, filter_properties))
Exemplo n.º 2
0
    def test_numa_topology_with_pci_fail(self, mock_get):
        dev_dict = {
            'compute_node_id': 1,
            'address': 'a',
            'product_id': 'p',
            'vendor_id': 'v',
            'numa_node': 1,
            'status': 'available'
        }
        dev_dict2 = {
            'compute_node_id': 1,
            'address': 'a',
            'product_id': 'p',
            'vendor_id': 'v',
            'numa_node': 2,
            'status': 'available'
        }
        self.tracker.new_pci_tracker()
        self.tracker.pci_tracker.set_hvdevs([dev_dict, dev_dict2])

        request = objects.InstancePCIRequest(count=2,
                                             spec=[{
                                                 'vendor_id': 'v',
                                                 'product_id': 'p'
                                             }])
        mock_get.return_value = objects.InstancePCIRequests(requests=[request])

        huge_instance = objects.InstanceNUMATopology(cells=[
            objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512)
        ])

        self.assertRaises(exception.ComputeResourcesUnavailable,
                          self._claim,
                          numa_topology=huge_instance)
Exemplo n.º 3
0
 def test_update_pci_for_instance_with_numa_fail(self, mock_get):
     self._create_pci_requests_object(mock_get, fake_pci_requests)
     self.inst.numa_topology = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512)
     ])
     self.assertRaises(exception.PciDeviceRequestFailed,
                       self.tracker.update_pci_for_instance, None,
                       self.inst)
Exemplo n.º 4
0
 def test_numa_topology_passes(self, mock_get):
     huge_instance = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512)
     ])
     limit_topo = objects.NUMATopologyLimits(cpu_allocation_ratio=1,
                                             ram_allocation_ratio=1)
     self._claim(limits={'numa_topology': limit_topo},
                 numa_topology=huge_instance)
 def test_pin(self):
     inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2, 3]),
                                          cpu_pinning=None)
     inst_cell.pin(0, 14)
     self.assertEqual({0: 14}, inst_cell.cpu_pinning)
     inst_cell.pin(12, 14)
     self.assertEqual({0: 14}, inst_cell.cpu_pinning)
     inst_cell.pin(1, 16)
     self.assertEqual({0: 14, 1: 16}, inst_cell.cpu_pinning)
Exemplo n.º 6
0
 def test_numa_topology_fails(self, mock_get):
     huge_instance = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(
             id=1, cpuset=set([1, 2, 3, 4, 5]), memory=2048)
     ])
     limit_topo = objects.NUMATopologyLimits(cpu_allocation_ratio=1,
                                             ram_allocation_ratio=1)
     self.assertRaises(exception.ComputeResourcesUnavailable,
                       self._claim,
                       limits={'numa_topology': limit_topo},
                       numa_topology=huge_instance)
Exemplo n.º 7
0
    def test_numa_topology_filter_pass_set_limit(self):
        self.flags(cpu_allocation_ratio=21)
        self.flags(ram_allocation_ratio=1.3)

        instance_topology = objects.InstanceNUMATopology(cells=[
            objects.InstanceNUMACell(id=0, cpuset=set([1]), memory=512),
            objects.InstanceNUMACell(id=1, cpuset=set([3]), memory=512)
        ])
        instance = fake_instance.fake_instance_obj(mock.sentinel.ctx)
        instance.numa_topology = instance_topology
        filter_properties = {
            'request_spec': {
                'instance_properties':
                jsonutils.to_primitive(obj_base.obj_to_primitive(instance))
            }
        }
        host = fakes.FakeHostState('host1', 'node1', {
            'numa_topology': fakes.NUMA_TOPOLOGY,
            'pci_stats': None
        })
        self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
        limits = host.limits['numa_topology']
        self.assertEqual(limits.cpu_allocation_ratio, 21)
        self.assertEqual(limits.ram_allocation_ratio, 1.3)
    def test_siblings(self):
        inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2]))
        self.assertEqual([], inst_cell.siblings)

        topo = objects.VirtCPUTopology(sockets=1, cores=3, threads=0)
        inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2]),
                                             cpu_topology=topo)
        self.assertEqual([], inst_cell.siblings)

        # One thread actually means no threads
        topo = objects.VirtCPUTopology(sockets=1, cores=3, threads=1)
        inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2]),
                                             cpu_topology=topo)
        self.assertEqual([], inst_cell.siblings)

        topo = objects.VirtCPUTopology(sockets=1, cores=2, threads=2)
        inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2, 3]),
                                             cpu_topology=topo)
        self.assertEqual([set([0, 1]), set([2, 3])], inst_cell.siblings)

        topo = objects.VirtCPUTopology(sockets=1, cores=1, threads=4)
        inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2, 3]),
                                             cpu_topology=topo)
        self.assertEqual([set([0, 1, 2, 3])], inst_cell.siblings)
Exemplo n.º 9
0
 def test_update_pci_for_instance_with_numa(self, mock_get):
     fake_db_dev_3 = dict(fake_db_dev_1, id=4, address='0000:00:00.4')
     fake_devs_numa = copy.deepcopy(fake_db_devs)
     fake_devs_numa.append(fake_db_dev_3)
     self.tracker = manager.PciDevTracker(1)
     self.tracker.set_hvdevs(fake_devs_numa)
     pci_requests = copy.deepcopy(fake_pci_requests)[:1]
     pci_requests[0]['count'] = 2
     self._create_pci_requests_object(mock_get, pci_requests)
     self.inst.numa_topology = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512)
     ])
     self.tracker.update_pci_for_instance(None, self.inst)
     free_devs = self.tracker.pci_stats.get_free_devs()
     self.assertEqual(2, len(free_devs))
     self.assertEqual('v1', free_devs[0]['vendor_id'])
     self.assertEqual('v1', free_devs[1]['vendor_id'])
Exemplo n.º 10
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")
        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))
Exemplo n.º 11
0
    def test_numa_topology_with_pci_no_numa_info(self, mock_get):
        dev_dict = {
            'compute_node_id': 1,
            'address': 'a',
            'product_id': 'p',
            'vendor_id': 'v',
            'numa_node': None,
            'status': 'available'
        }
        self.tracker.new_pci_tracker()
        self.tracker.pci_tracker.set_hvdevs([dev_dict])

        request = objects.InstancePCIRequest(count=1,
                                             spec=[{
                                                 'vendor_id': 'v',
                                                 'product_id': 'p'
                                             }])
        mock_get.return_value = objects.InstancePCIRequests(requests=[request])

        huge_instance = objects.InstanceNUMATopology(cells=[
            objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512)
        ])

        self._claim(numa_topology=huge_instance)
Exemplo n.º 12
0
 def test_numa_topology_no_limit(self, mock_get):
     huge_instance = objects.InstanceNUMATopology(cells=[
         objects.InstanceNUMACell(id=1, cpuset=set([1, 2]), memory=512)
     ])
     self._claim(numa_topology=huge_instance)
 def test_cpu_pinning_requested_cell(self):
     inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2, 3]),
                                          cpu_pinning=None)
     self.assertFalse(inst_cell.cpu_pinning_requested)
     inst_cell.cpu_pinning = {}
     self.assertTrue(inst_cell.cpu_pinning_requested)
 def test_default_behavior(self):
     inst_cell = objects.InstanceNUMACell()
     self.assertEqual(0, len(inst_cell.obj_get_changes()))
 def test_pin_vcpus(self):
     inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2, 3]),
                                          cpu_pinning=None)
     inst_cell.pin_vcpus((0, 14), (1, 15), (2, 16), (3, 17))
     self.assertEqual({0: 14, 1: 15, 2: 16, 3: 17}, inst_cell.cpu_pinning)
import uuid

import mock
from oslo_serialization import jsonutils

from patron import exception
from patron import objects
from patron.tests.unit.objects import test_objects

fake_instance_uuid = str(uuid.uuid4())

fake_obj_numa_topology = objects.InstanceNUMATopology(
    instance_uuid=fake_instance_uuid,
    cells=[
        objects.InstanceNUMACell(id=0,
                                 cpuset=set([1, 2]),
                                 memory=512,
                                 pagesize=2048),
        objects.InstanceNUMACell(id=1,
                                 cpuset=set([3, 4]),
                                 memory=512,
                                 pagesize=2048)
    ])

fake_numa_topology = fake_obj_numa_topology._to_dict()

fake_db_topology = {
    'created_at': None,
    'updated_at': None,
    'deleted_at': None,
    'deleted': 0,
    'id': 1,