Exemplo n.º 1
0
 def test_allocacte_device_fail_owner(self):
     inst_2 = objects.Instance()
     inst_2.uuid = 'fake-inst-uuid-2'
     device.claim(self.devobj, self.inst)
     self.assertRaises(exception.PciDeviceInvalidOwner,
                       device.allocate,
                       self.devobj, inst_2)
Exemplo n.º 2
0
def _get_instances_with_cached_ips(orig_func, *args, **kwargs):
    """Kludge the cache into instance(s) without having to create DB
    entries
    """
    instances = orig_func(*args, **kwargs)
    context = args[0]
    fake_device = objects.PciDevice.get_by_dev_addr(context, 1, 'a')

    def _info_cache_for(instance):
        info_cache = dict(test_instance_info_cache.fake_info_cache,
                          network_info=_get_fake_cache(),
                          instance_uuid=instance['uuid'])
        if isinstance(instance, obj_base.NovaObject):
            _info_cache = objects.InstanceInfoCache(context)
            objects.InstanceInfoCache._from_db_object(context, _info_cache,
                                                      info_cache)
            info_cache = _info_cache
        instance['info_cache'] = info_cache

    if isinstance(instances, (list, obj_base.ObjectListBase)):
        for instance in instances:
            _info_cache_for(instance)
            pci_device.claim(fake_device, instance)
            pci_device.allocate(fake_device, instance)
    else:
        _info_cache_for(instances)
        pci_device.claim(fake_device, instances)
        pci_device.allocate(fake_device, instances)
    return instances
Exemplo n.º 3
0
 def setUp(self):
     super(PciServerControllerTestV21, self).setUp()
     self.controller = pci.PciServerController()
     self.fake_obj = {
         'server': {
             'addresses': {},
             'id': 'fb08',
             'name': 'a3',
             'status': 'ACTIVE',
             'tenant_id': '9a3af784c',
             'user_id': 'e992080ac0',
         }
     }
     self.fake_list = {
         'servers': [{
             'addresses': {},
             'id': 'fb08',
             'name': 'a3',
             'status': 'ACTIVE',
             'tenant_id': '9a3af784c',
             'user_id': 'e992080ac',
         }]
     }
     self._create_fake_instance()
     self._create_fake_pci_device()
     device.claim(self.pci_device, self.inst)
     device.allocate(self.pci_device, self.inst)
Exemplo n.º 4
0
def _get_instances_with_cached_ips(orig_func, *args, **kwargs):
    """Kludge the cache into instance(s) without having to create DB
    entries
    """
    instances = orig_func(*args, **kwargs)
    context = args[0]
    fake_device = objects.PciDevice.get_by_dev_addr(context, 1, 'a')

    def _info_cache_for(instance):
        info_cache = dict(test_instance_info_cache.fake_info_cache,
                          network_info=_get_fake_cache(),
                          instance_uuid=instance['uuid'])
        if isinstance(instance, obj_base.NovaObject):
            _info_cache = objects.InstanceInfoCache(context)
            objects.InstanceInfoCache._from_db_object(context, _info_cache,
                                                      info_cache)
            info_cache = _info_cache
        instance['info_cache'] = info_cache

    if isinstance(instances, (list, obj_base.ObjectListBase)):
        for instance in instances:
            _info_cache_for(instance)
            pci_device.claim(fake_device, instance)
            pci_device.allocate(fake_device, instance)
    else:
        _info_cache_for(instances)
        pci_device.claim(fake_device, instances)
        pci_device.allocate(fake_device, instances)
    return instances
Exemplo n.º 5
0
 def test_claim_device(self):
     device.claim(self.devobj, self.inst)
     self.assertEqual(self.devobj.status,
                      fields.PciDeviceStatus.CLAIMED)
     self.assertEqual(self.devobj.instance_uuid,
                      self.inst.uuid)
     self.assertEqual(len(self.inst.pci_devices), 0)
Exemplo n.º 6
0
    def _claim_instance(self, context, instance, prefix=''):
        pci_requests = objects.InstancePCIRequests.get_by_instance(
            context, instance)
        if not pci_requests.requests:
            return None
        instance_numa_topology = hardware.instance_topology_from_instance(
            instance)
        instance_cells = None
        if instance_numa_topology:
            instance_cells = instance_numa_topology.cells

        devs = self.stats.consume_requests(pci_requests.requests,
                                           instance_cells)
        if not devs:
            return None

        for dev in devs:
            device.claim(dev, instance)
        if instance_numa_topology and any(dev.numa_node is None
                                          for dev in devs):
            LOG.warning(
                _LW("Assigning a pci device without numa affinity to"
                    "instance %(instance)s which has numa topology"),
                {'instance': instance['uuid']})
        return devs
Exemplo n.º 7
0
 def test_allocate_device(self):
     device.claim(self.devobj, self.inst)
     device.allocate(self.devobj, self.inst)
     self.assertEqual(self.devobj.status, 'allocated')
     self.assertEqual(self.devobj.instance_uuid, 'fake-inst-uuid')
     self.assertEqual(len(self.inst.pci_devices), 1)
     self.assertEqual(self.inst.pci_devices[0]['vendor_id'], 'v')
     self.assertEqual(self.inst.pci_devices[0]['status'], 'allocated')
Exemplo n.º 8
0
 def test_allocate_device(self):
     device.claim(self.devobj, self.inst)
     device.allocate(self.devobj, self.inst)
     self.assertEqual(self.devobj.status, "allocated")
     self.assertEqual(self.devobj.instance_uuid, "fake-inst-uuid")
     self.assertEqual(len(self.inst.pci_devices), 1)
     self.assertEqual(self.inst.pci_devices[0]["vendor_id"], "v")
     self.assertEqual(self.inst.pci_devices[0]["status"], "allocated")
Exemplo n.º 9
0
 def test_free_allocated_device(self):
     device.claim(self.devobj, self.inst)
     device.allocate(self.devobj, self.inst)
     self.assertEqual(len(self.inst.pci_devices), 1)
     device.free(self.devobj, self.inst)
     self.assertEqual(len(self.inst.pci_devices), 0)
     self.assertEqual(self.devobj.status, 'available')
     self.assertIsNone(self.devobj.instance_uuid)
Exemplo n.º 10
0
 def test_free_allocated_device(self):
     device.claim(self.devobj, self.inst)
     device.allocate(self.devobj, self.inst)
     self.assertEqual(len(self.inst.pci_devices), 1)
     device.free(self.devobj, self.inst)
     self.assertEqual(len(self.inst.pci_devices), 0)
     self.assertEqual(self.devobj.status,
                      fields.PciDeviceStatus.AVAILABLE)
     self.assertIsNone(self.devobj.instance_uuid)
Exemplo n.º 11
0
 def _claim_instance(self, context, instance, prefix=''):
     pci_requests = objects.InstancePCIRequests.get_by_instance(
         context, instance)
     if not pci_requests.requests:
         return None
     devs = self.stats.consume_requests(pci_requests.requests)
     if not devs:
         raise exception.PciDeviceRequestFailed(pci_requests)
     for dev in devs:
         device.claim(dev, instance)
     return devs
Exemplo n.º 12
0
 def test_allocate_device(self):
     device.claim(self.devobj, self.inst)
     device.allocate(self.devobj, self.inst)
     self.assertEqual(self.devobj.status,
                      fields.PciDeviceStatus.ALLOCATED)
     self.assertEqual(self.devobj.instance_uuid, 'fake-inst-uuid')
     self.assertEqual(len(self.inst.pci_devices), 1)
     self.assertEqual(self.inst.pci_devices[0].vendor_id,
                      'v')
     self.assertEqual(self.inst.pci_devices[0].status,
                      fields.PciDeviceStatus.ALLOCATED)
Exemplo n.º 13
0
    def _claim_instance(self, context, instance, prefix=""):
        pci_requests = objects.InstancePCIRequests.get_by_instance(context, instance)
        if not pci_requests.requests:
            return None
        instance_numa_topology = hardware.instance_topology_from_instance(instance)
        instance_cells = None
        if instance_numa_topology:
            instance_cells = instance_numa_topology.cells

        devs = self.stats.consume_requests(pci_requests.requests, instance_cells)
        if not devs:
            raise exception.PciDeviceRequestFailed(pci_requests)
        for dev in devs:
            device.claim(dev, instance)
        if instance_numa_topology and any(dev.numa_node is None for dev in devs):
            LOG.warning(
                _LW("Assigning a pci device without numa affinity to" "instance %(instance)s which has numa topology"),
                {"instance": instance["uuid"]},
            )
        return devs
Exemplo n.º 14
0
 def setUp(self):
     super(PciServerControllerTest, self).setUp()
     self.controller = pci.PciServerController()
     self.fake_obj = {'server': {'addresses': {},
                                 'id': 'fb08',
                                 'name': 'a3',
                                 'status': 'ACTIVE',
                                 'tenant_id': '9a3af784c',
                                 'user_id': 'e992080ac0',
                                 }}
     self.fake_list = {'servers': [{'addresses': {},
                                    'id': 'fb08',
                                    'name': 'a3',
                                    'status': 'ACTIVE',
                                    'tenant_id': '9a3af784c',
                                    'user_id': 'e992080ac',
                                    }]}
     self._create_fake_instance()
     self._create_fake_pci_device()
     device.claim(self.pci_device, self.inst)
     device.allocate(self.pci_device, self.inst)
Exemplo n.º 15
0
 def test_claim_device(self):
     device.claim(self.devobj, self.inst)
     self.assertEqual(self.devobj.status, 'claimed')
     self.assertEqual(self.devobj.instance_uuid,
                      self.inst.uuid)
     self.assertEqual(len(self.inst.pci_devices), 0)
Exemplo n.º 16
0
 def test_remove_device_fail(self):
     device.claim(self.devobj, self.inst)
     self.assertRaises(exception.PciDeviceInvalidStatus,
                       device.remove, self.devobj)
Exemplo n.º 17
0
 def test_free_claimed_device(self):
     device.claim(self.devobj, self.inst)
     device.free(self.devobj, self.inst)
     self.assertEqual(self.devobj.status,
                      fields.PciDeviceStatus.AVAILABLE)
     self.assertIsNone(self.devobj.instance_uuid)
Exemplo n.º 18
0
 def test_free_claimed_device(self):
     device.claim(self.devobj, self.inst)
     device.free(self.devobj, self.inst)
     self.assertEqual(self.devobj.status, 'available')
     self.assertIsNone(self.devobj.instance_uuid)