Beispiel #1
0
 def test_save(self):
     ctxt = context.get_admin_context()
     self._create_fake_pci_device(ctxt=ctxt)
     return_dev = dict(fake_db_dev, status=fields.PciDeviceStatus.AVAILABLE, instance_uuid="fake-uuid-3")
     self.pci_device.status = fields.PciDeviceStatus.ALLOCATED
     self.pci_device.instance_uuid = "fake-uuid-2"
     expected_updates = dict(status=fields.PciDeviceStatus.ALLOCATED, instance_uuid="fake-uuid-2")
     self.mox.StubOutWithMock(db, "pci_device_update")
     db.pci_device_update(ctxt, 1, "a", expected_updates).AndReturn(return_dev)
     self.mox.ReplayAll()
     self.pci_device.save()
     self.assertEqual(self.pci_device.status, fields.PciDeviceStatus.AVAILABLE)
     self.assertEqual(self.pci_device.instance_uuid, "fake-uuid-3")
Beispiel #2
0
 def test_save(self):
     ctxt = context.get_admin_context()
     self._create_fake_pci_device(ctxt=ctxt)
     return_dev = dict(fake_db_dev, status="available", instance_uuid="fake-uuid-3")
     self.pci_device.status = "allocated"
     self.pci_device.instance_uuid = "fake-uuid-2"
     expected_updates = dict(status="allocated", instance_uuid="fake-uuid-2")
     self.mox.StubOutWithMock(db, "pci_device_update")
     db.pci_device_update(ctxt, 1, "a", expected_updates).AndReturn(return_dev)
     self.mox.ReplayAll()
     self.pci_device.save()
     self.assertEqual(self.pci_device.status, "available")
     self.assertEqual(self.pci_device.instance_uuid, "fake-uuid-3")
     self.assertRemotes()
Beispiel #3
0
 def test_save_RHOS_6_0_format_numa_field_set(self):
     ctxt = context.get_admin_context
     kw = {'compute_node_id': 1, 'address': 'a',
           'status': 'available', 'numa_node': 1}
     self.pci_device = pci_device.PciDevice(ctxt, **kw)
     self.pci_device.obj_reset_changes()
     self.pci_device['extra_info'] = {'numa_node': 0}
     self.mox.StubOutWithMock(db, 'pci_device_update')
     expected_updates = {'extra_info': '{}'}
     db.pci_device_update(ctxt, 1, 'a',
                          expected_updates).AndReturn(fake_db_dev_1)
     self.mox.ReplayAll()
     self.pci_device.save()
     self.assertEqual(self.pci_device.numa_node, 1)
     self.assertEqual(self.pci_device.extra_info, {})
     self.assertRemotes()
Beispiel #4
0
    def save(self):
        if self.status == fields.PciDeviceStatus.REMOVED:
            self.status = fields.PciDeviceStatus.DELETED
            db.pci_device_destroy(self._context, self.compute_node_id,
                                  self.address)
        elif self.status != fields.PciDeviceStatus.DELETED:
            updates = self.obj_get_changes()
            if not self.should_migrate_data():
                # NOTE(ndipanov): If we are not migrating data yet, make sure
                # that any changes to parent_addr are also in the old location
                # in extra_info
                if 'parent_addr' in updates and updates['parent_addr']:
                    extra_update = updates.get('extra_info', {})
                    if not extra_update and self.obj_attr_is_set('extra_info'):
                        extra_update = self.extra_info
                    extra_update['phys_function'] = updates['parent_addr']
                    updates['extra_info'] = extra_update
            else:
                # NOTE(ndipanov): Once we start migrating, meaning all control
                # plane has been upgraded - aggressively migrate on every save
                pf_extra = self.extra_info.pop('phys_function', None)
                if pf_extra and 'parent_addr' not in updates:
                    updates['parent_addr'] = pf_extra
                updates['extra_info'] = self.extra_info

            if 'extra_info' in updates:
                updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
            if updates:
                db_pci = db.pci_device_update(self._context,
                                              self.compute_node_id,
                                              self.address, updates)
                self._from_db_object(self._context, self, db_pci)
Beispiel #5
0
    def save(self):
        if self.status == fields.PciDeviceStatus.REMOVED:
            self.status = fields.PciDeviceStatus.DELETED
            db.pci_device_destroy(self._context, self.compute_node_id,
                                  self.address)
        elif self.status != fields.PciDeviceStatus.DELETED:
            updates = self.obj_get_changes()
            if not self.should_migrate_data():
                # NOTE(ndipanov): If we are not migrating data yet, make sure
                # that any changes to parent_addr are also in the old location
                # in extra_info
                if 'parent_addr' in updates and updates['parent_addr']:
                    extra_update = updates.get('extra_info', {})
                    if not extra_update and self.obj_attr_is_set('extra_info'):
                        extra_update = self.extra_info
                    extra_update['phys_function'] = updates['parent_addr']
                    updates['extra_info'] = extra_update
            else:
                # NOTE(ndipanov): Once we start migrating, meaning all control
                # plane has been upgraded - aggressively migrate on every save
                pf_extra = self.extra_info.pop('phys_function', None)
                if pf_extra and 'parent_addr' not in updates:
                    updates['parent_addr'] = pf_extra
                updates['extra_info'] = self.extra_info

            if 'extra_info' in updates:
                updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
            if updates:
                db_pci = db.pci_device_update(self._context,
                                              self.compute_node_id,
                                              self.address, updates)
                self._from_db_object(self._context, self, db_pci)
Beispiel #6
0
 def test_save(self):
     ctxt = context.get_admin_context()
     self._create_fake_pci_device(ctxt=ctxt)
     return_dev = dict(fake_db_dev,
                       status='available',
                       instance_uuid='fake-uuid-3')
     self.pci_device.status = 'allocated'
     self.pci_device.instance_uuid = 'fake-uuid-2'
     expected_updates = dict(status='allocated',
                             instance_uuid='fake-uuid-2')
     self.mox.StubOutWithMock(db, 'pci_device_update')
     db.pci_device_update(ctxt, 1, 'a',
                          expected_updates).AndReturn(return_dev)
     self.mox.ReplayAll()
     self.pci_device.save()
     self.assertEqual(self.pci_device.status, 'available')
     self.assertEqual(self.pci_device.instance_uuid, 'fake-uuid-3')
Beispiel #7
0
 def test_save(self):
     ctxt = context.get_admin_context()
     self._create_fake_pci_device(ctxt=ctxt)
     return_dev = dict(fake_db_dev, status='available',
                       instance_uuid='fake-uuid-3')
     self.pci_device.status = 'allocated'
     self.pci_device.instance_uuid = 'fake-uuid-2'
     expected_updates = dict(status='allocated',
                             instance_uuid='fake-uuid-2')
     self.mox.StubOutWithMock(db, 'pci_device_update')
     db.pci_device_update(ctxt, 1, 'a',
                          expected_updates).AndReturn(return_dev)
     self.mox.ReplayAll()
     self.pci_device.save()
     self.assertEqual(self.pci_device.status, 'available')
     self.assertEqual(self.pci_device.instance_uuid,
                      'fake-uuid-3')
Beispiel #8
0
 def test_save(self):
     ctxt = context.get_admin_context()
     self._create_fake_pci_device(ctxt=ctxt)
     return_dev = dict(fake_db_dev,
                       status=fields.PciDeviceStatus.AVAILABLE,
                       instance_uuid='fake-uuid-3')
     self.pci_device.status = fields.PciDeviceStatus.ALLOCATED
     self.pci_device.instance_uuid = 'fake-uuid-2'
     expected_updates = dict(status=fields.PciDeviceStatus.ALLOCATED,
                             instance_uuid='fake-uuid-2')
     self.mox.StubOutWithMock(db, 'pci_device_update')
     db.pci_device_update(ctxt, 1, 'a',
                          expected_updates).AndReturn(return_dev)
     self.mox.ReplayAll()
     self.pci_device.save()
     self.assertEqual(self.pci_device.status,
                      fields.PciDeviceStatus.AVAILABLE)
     self.assertEqual(self.pci_device.instance_uuid, 'fake-uuid-3')
Beispiel #9
0
 def test_save(self):
     ctxt = context.get_admin_context()
     self._create_fake_pci_device(ctxt=ctxt)
     return_dev = dict(fake_db_dev, status=fields.PciDeviceStatus.AVAILABLE,
                       instance_uuid=uuids.instance3)
     self.pci_device.status = fields.PciDeviceStatus.ALLOCATED
     self.pci_device.instance_uuid = uuids.instance2
     expected_updates = dict(status=fields.PciDeviceStatus.ALLOCATED,
                             extra_info='{}',
                             instance_uuid=uuids.instance2)
     self.mox.StubOutWithMock(db, 'pci_device_update')
     db.pci_device_update(ctxt, 1, 'a',
                          expected_updates).AndReturn(return_dev)
     self.mox.ReplayAll()
     self.pci_device.save()
     self.assertEqual(self.pci_device.status,
                      fields.PciDeviceStatus.AVAILABLE)
     self.assertEqual(self.pci_device.instance_uuid,
                      uuids.instance3)
Beispiel #10
0
 def save(self, context):
     if self.status == "removed":
         self.status = "deleted"
         db.pci_device_destroy(context, self.compute_node_id, self.address)
     elif self.status != "deleted":
         updates = self.obj_get_changes()
         if "extra_info" in updates:
             updates["extra_info"] = jsonutils.dumps(updates["extra_info"])
         if updates:
             db_pci = db.pci_device_update(context, self.compute_node_id, self.address, updates)
             self._from_db_object(context, self, db_pci)
Beispiel #11
0
 def save(self, context):
     if self.status == 'removed':
         self.status = 'deleted'
         db.pci_device_destroy(context, self.compute_node_id, self.address)
     elif self.status != 'deleted':
         updates = self.obj_get_changes()
         if 'extra_info' in updates:
             updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
         if updates:
             db_pci = db.pci_device_update(context, self.compute_node_id,
                                           self.address, updates)
             self._from_db_object(context, self, db_pci)
Beispiel #12
0
 def save(self):
     if self.status == fields.PciDeviceStatus.REMOVED:
         self.status = fields.PciDeviceStatus.DELETED
         db.pci_device_destroy(self._context, self.compute_node_id,
                               self.address)
     elif self.status != fields.PciDeviceStatus.DELETED:
         updates = self.obj_get_changes()
         if 'extra_info' in updates:
             updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
         if updates:
             db_pci = db.pci_device_update(self._context,
                                           self.compute_node_id,
                                           self.address, updates)
             self._from_db_object(self._context, self, db_pci)
Beispiel #13
0
 def save(self):
     if self.status == 'removed':
         self.status = 'deleted'
         db.pci_device_destroy(self._context, self.compute_node_id,
                               self.address)
     elif self.status != 'deleted':
         updates = self.obj_get_changes()
         if 'extra_info' in updates:
             updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
         if updates:
             db_pci = db.pci_device_update(self._context,
                                           self.compute_node_id,
                                           self.address, updates)
             self._from_db_object(self._context, self, db_pci)
Beispiel #14
0
 def save(self, context):
     if self.status == "removed":
         self.status = "deleted"
         db.pci_device_destroy(context, self.compute_node_id, self.address)
     elif self.status != "deleted":
         updates = {}
         for field in self.obj_what_changed():
             if field == "extra_info":
                 updates["extra_info"] = jsonutils.dumps(self.extra_info)
             else:
                 updates[field] = self[field]
         if updates:
             db_pci = db.pci_device_update(context, self.compute_node_id, self.address, updates)
             self._from_db_object(context, self, db_pci)
Beispiel #15
0
 def save(self):
     if self.status == fields.PciDeviceStatus.REMOVED:
         self.status = fields.PciDeviceStatus.DELETED
         db.pci_device_destroy(self._context, self.compute_node_id,
                               self.address)
     elif self.status != fields.PciDeviceStatus.DELETED:
         updates = self.obj_get_changes()
         if 'extra_info' in updates:
             updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
         if updates:
             db_pci = db.pci_device_update(self._context,
                                           self.compute_node_id,
                                           self.address, updates)
             self._from_db_object(self._context, self, db_pci)
Beispiel #16
0
 def save(self, context):
     if self.status == 'removed':
         self.status = 'deleted'
         db.pci_device_destroy(context, self.compute_node_id, self.address)
     elif self.status != 'deleted':
         updates = {}
         for field in self.obj_what_changed():
             if field == 'extra_info':
                 updates['extra_info'] = jsonutils.dumps(self.extra_info)
             else:
                 updates[field] = self[field]
         if updates:
             db_pci = db.pci_device_update(context, self.compute_node_id,
                                           self.address, updates)
             self._from_db_object(context, self, db_pci)
Beispiel #17
0
 def save(self):
     if self.status == 'removed':
         self.status = 'deleted'
         db.pci_device_destroy(self._context, self.compute_node_id,
                               self.address)
     elif self.status != 'deleted':
         updates = self.obj_get_changes()
         if 'extra_info' in updates:
             numa_node_extra = updates['extra_info'].pop('numa_node', None)
             # NOTE (ndipanov): Never overwrite an acual value with legacy
             #                  RHOS 6 data from 'extra_info'
             if (updates.get('numa_node') is None and self.numa_node is None
                     and numa_node_extra is not None):
                 updates['numa_node'] = int(numa_node_extra)
             updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
         if updates:
             db_pci = db.pci_device_update(self._context,
                                           self.compute_node_id,
                                           self.address, updates)
             self._from_db_object(self._context, self, db_pci)
Beispiel #18
0
    def save(self):
        if self.status == fields.PciDeviceStatus.REMOVED:
            self.status = fields.PciDeviceStatus.DELETED
            db.pci_device_destroy(self._context, self.compute_node_id,
                                  self.address)
        elif self.status != fields.PciDeviceStatus.DELETED:
            # TODO(jaypipes): Remove in 2.0 version of object. This does an
            # inline migration to populate the uuid field. A similar migration
            # is done in the _from_db_object() method to migrate objects as
            # they are read from the DB.
            if 'uuid' not in self:
                self.uuid = uuidutils.generate_uuid()
            updates = self.obj_get_changes()

            if 'extra_info' in updates:
                updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
            if updates:
                db_pci = db.pci_device_update(self._context,
                                              self.compute_node_id,
                                              self.address, updates)
                self._from_db_object(self._context, self, db_pci)
Beispiel #19
0
 def save(self):
     if self.status == 'removed':
         self.status = 'deleted'
         db.pci_device_destroy(self._context, self.compute_node_id,
                               self.address)
     elif self.status != 'deleted':
         updates = self.obj_get_changes()
         if 'extra_info' in updates:
             numa_node_extra = updates['extra_info'].pop('numa_node', None)
             # NOTE (ndipanov): Never overwrite an acual value with legacy
             #                  RHOS 6 data from 'extra_info'
             if (updates.get('numa_node') is None and
                     self.numa_node is None and
                     numa_node_extra is not None):
                 updates['numa_node'] = int(numa_node_extra)
             updates['extra_info'] = jsonutils.dumps(updates['extra_info'])
         if updates:
             db_pci = db.pci_device_update(self._context,
                                           self.compute_node_id,
                                           self.address, updates)
             self._from_db_object(self._context, self, db_pci)