Пример #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)
Пример #2
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)
Пример #3
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
Пример #4
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)
Пример #5
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')
Пример #6
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)
Пример #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')
Пример #8
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)
Пример #9
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
Пример #10
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)
Пример #11
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)
Пример #12
0
 def test_remove_device_fail(self):
     device.claim(self.devobj, self.inst)
     self.assertRaises(exception.PciDeviceInvalidStatus,
                       device.remove, self.devobj)
Пример #13
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)
Пример #14
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)
Пример #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)
Пример #16
0
 def test_remove_device_fail(self):
     device.claim(self.devobj, self.inst)
     self.assertRaises(exception.PciDeviceInvalidStatus, device.remove,
                       self.devobj)