Example #1
0
    def _from_db_object(context, compute, db_compute):
        special_cases = set([
            'stats',
            'supported_hv_specs',
            'host',
            'pci_device_pools',
            ])
        fields = set(compute.fields) - special_cases
        for key in fields:
            compute[key] = db_compute[key]

        stats = db_compute['stats']
        if stats:
            compute['stats'] = jsonutils.loads(stats)

        sup_insts = db_compute.get('supported_instances')
        if sup_insts:
            hv_specs = jsonutils.loads(sup_insts)
            hv_specs = [objects.HVSpec.from_list(hv_spec)
                        for hv_spec in hv_specs]
            compute['supported_hv_specs'] = hv_specs

        pci_stats = db_compute.get('pci_stats')
        compute.pci_device_pools = pci_device_pool.from_pci_stats(pci_stats)
        compute._context = context

        # Make sure that we correctly set the host field depending on either
        # host column is present in the table or not
        compute._host_from_db_object(compute, db_compute)

        compute.obj_reset_changes()
        return compute
Example #2
0
    def _from_db_object(context, compute, db_compute):
        special_cases = set([
            'stats',
            'supported_hv_specs',
            'host',
            'pci_device_pools',
        ])
        fields = set(compute.fields) - special_cases
        for key in fields:
            compute[key] = db_compute[key]

        stats = db_compute['stats']
        if stats:
            compute['stats'] = jsonutils.loads(stats)

        sup_insts = db_compute.get('supported_instances')
        if sup_insts:
            hv_specs = jsonutils.loads(sup_insts)
            hv_specs = [
                objects.HVSpec.from_list(hv_spec) for hv_spec in hv_specs
            ]
            compute['supported_hv_specs'] = hv_specs

        pci_stats = db_compute.get('pci_stats')
        compute.pci_device_pools = pci_device_pool.from_pci_stats(pci_stats)
        compute._context = context

        # Make sure that we correctly set the host field depending on either
        # host column is present in the table or not
        compute._host_from_db_object(compute, db_compute)

        compute.obj_reset_changes()
        return compute
Example #3
0
 def setUp(self):
     raise testtools.TestCase.skipException(skip_msg)
     super(ExtendedHyervisorPciSampleJsonTest, self).setUp()
     cpu_info = collections.OrderedDict([
         ('arch', 'x86_64'),
         ('model', 'Nehalem'),
         ('vendor', 'Intel'),
         ('features', ['pge', 'clflush']),
         ('topology', {
             'cores': 1,
             'threads': 1,
             'sockets': 4,
         }),
     ])
     self.fake_compute_node = objects.ComputeNode(
         cpu_info=jsonutils.dumps(cpu_info),
         current_workload=0,
         disk_available_least=0,
         host_ip="1.1.1.1",
         state="up",
         status="enabled",
         free_disk_gb=1028,
         free_ram_mb=7680,
         hypervisor_hostname="fake-mini",
         hypervisor_type="fake",
         hypervisor_version=1000,
         id=1,
         local_gb=1028,
         local_gb_used=0,
         memory_mb=8192,
         memory_mb_used=512,
         running_vms=0,
         vcpus=1,
         vcpus_used=0,
         service_id=2,
         host='043b3cacf6f34c90a7245151fc8ebcda',
         pci_device_pools=pci_device_pool.from_pci_stats({
             "count": 5,
             "vendor_id": "8086",
             "product_id": "1520",
             "keya": "valuea",
             "extra_info": {
                 "phys_function": '[["0x0000", '
                 '"0x04", "0x00",'
                 ' "0x1"]]',
                 "key1": "value1"
             }
         }),
     )
     self.fake_service = objects.Service(
         id=2,
         host='043b3cacf6f34c90a7245151fc8ebcda',
         disabled=False,
         disabled_reason=None)
Example #4
0
 def setUp(self):
     raise testtools.TestCase.skipException(skip_msg)
     super(ExtendedHyervisorPciSampleJsonTest, self).setUp()
     cpu_info = collections.OrderedDict(
         [
             ("arch", "x86_64"),
             ("model", "Nehalem"),
             ("vendor", "Intel"),
             ("features", ["pge", "clflush"]),
             ("topology", {"cores": 1, "threads": 1, "sockets": 4}),
         ]
     )
     self.fake_compute_node = objects.ComputeNode(
         cpu_info=jsonutils.dumps(cpu_info),
         current_workload=0,
         disk_available_least=0,
         host_ip="1.1.1.1",
         state="up",
         status="enabled",
         free_disk_gb=1028,
         free_ram_mb=7680,
         hypervisor_hostname="fake-mini",
         hypervisor_type="fake",
         hypervisor_version=1000,
         id=1,
         local_gb=1028,
         local_gb_used=0,
         memory_mb=8192,
         memory_mb_used=512,
         running_vms=0,
         vcpus=1,
         vcpus_used=0,
         service_id=2,
         host="043b3cacf6f34c90a7245151fc8ebcda",
         pci_device_pools=pci_device_pool.from_pci_stats(
             {
                 "count": 5,
                 "vendor_id": "8086",
                 "product_id": "1520",
                 "keya": "valuea",
                 "extra_info": {"phys_function": '[["0x0000", ' '"0x04", "0x00",' ' "0x1"]]', "key1": "value1"},
             }
         ),
     )
     self.fake_service = objects.Service(
         id=2, host="043b3cacf6f34c90a7245151fc8ebcda", disabled=False, disabled_reason=None
     )
Example #5
0
from patron import test
from patron.tests.unit.api.openstack import fakes
from patron.tests.unit.objects import test_pci_device

pci_stats = [{
    "count": 3,
    "vendor_id": "8086",
    "product_id": "1520",
    "numa_node": 1,
    "extra_info": {
        "phys_function": '[["0x0000", "0x04", '
        '"0x00", "0x1"]]'
    }
}]
fake_compute_node = objects.ComputeNode(
    pci_device_pools=pci_device_pool.from_pci_stats(pci_stats))


class FakeResponse(wsgi.ResponseObject):
    pass


class PciServerControllerTestV21(test.NoDBTestCase):
    def setUp(self):
        super(PciServerControllerTestV21, self).setUp()
        self.controller = pci.PciServerController()
        self.fake_obj = {
            'server': {
                'addresses': {},
                'id': 'fb08',
                'name': 'a3',
 def test_from_pci_stats_list_of_dicts(self):
     prim = fake_pci.fake_pool_dict
     pools = pci_device_pool.from_pci_stats([prim, prim])
     self.assertIsInstance(pools, pci_device_pool.PciDevicePoolList)
     self.assertEqual(len(pools), 2)
 def test_from_pci_stats_obj(self):
     prim = fake_pci.fake_pool_list_primitive
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertIsInstance(pools, pci_device_pool.PciDevicePoolList)
     self.assertEqual(len(pools), 1)
 def test_from_pci_stats_bad(self):
     prim = "not a valid json string for an object"
     pools = pci_device_pool.from_pci_stats(prim)
     self.assertIsNone(pools)
Example #9
0
from patron import objects
from patron.objects import pci_device_pool
from patron.pci import device
from patron import test
from patron.tests.unit.api.openstack import fakes
from patron.tests.unit.objects import test_pci_device


pci_stats = [{"count": 3,
              "vendor_id": "8086",
              "product_id": "1520",
              "numa_node": 1,
              "extra_info": {"phys_function": '[["0x0000", "0x04", '
                                              '"0x00", "0x1"]]'}}]
fake_compute_node = objects.ComputeNode(
    pci_device_pools=pci_device_pool.from_pci_stats(pci_stats))


class FakeResponse(wsgi.ResponseObject):
    pass


class PciServerControllerTestV21(test.NoDBTestCase):
    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',