Beispiel #1
0
 def test_archive_deleted_rows_with_undeleted_residue(self):
     # Boots a server, deletes it, and then tries to archive it.
     server = self._create_server()
     server_id = server['id']
     # Assert that there are instance_actions. instance_actions are
     # interesting since we don't soft delete them but they have a foreign
     # key back to the instances table.
     actions = self.api.get_instance_actions(server_id)
     self.assertTrue(len(actions),
                     'No instance actions for server: %s' % server_id)
     self._delete_server(server)
     # Verify we have the soft deleted instance in the database.
     admin_context = context.get_admin_context(read_deleted='yes')
     # This will raise InstanceNotFound if it's not found.
     instance = db.instance_get_by_uuid(admin_context, server_id)
     # Make sure it's soft deleted.
     self.assertNotEqual(0, instance.deleted)
     # Undelete the instance_extra record to make sure we delete it anyway
     extra = db.instance_extra_get_by_instance_uuid(admin_context,
                                                    instance.uuid)
     self.assertNotEqual(0, extra.deleted)
     db.instance_extra_update_by_uuid(admin_context, instance.uuid,
                                      {'deleted': 0})
     extra = db.instance_extra_get_by_instance_uuid(admin_context,
                                                    instance.uuid)
     self.assertEqual(0, extra.deleted)
     # Verify we have some system_metadata since we'll check that later.
     self.assertTrue(len(instance.system_metadata),
                     'No system_metadata for instance: %s' % server_id)
     # Create a pci_devices record to simulate an instance that had a PCI
     # device allocated at the time it was deleted. There is a window of
     # time between deletion of the instance record and freeing of the PCI
     # device in nova-compute's _complete_deletion method during RT update.
     db.pci_device_update(
         admin_context, 1, 'fake-address', {
             'compute_node_id': 1,
             'address': 'fake-address',
             'vendor_id': 'fake',
             'product_id': 'fake',
             'dev_type': 'fake',
             'label': 'fake',
             'status': 'allocated',
             'instance_uuid': instance.uuid
         })
     # Now try and archive the soft deleted records.
     results, deleted_instance_uuids, archived = \
         db.archive_deleted_rows(max_rows=100)
     # verify system_metadata was dropped
     self.assertIn('instance_system_metadata', results)
     self.assertEqual(len(instance.system_metadata),
                      results['instance_system_metadata'])
     # Verify that instances rows are dropped
     self.assertIn('instances', results)
     # Verify that instance_actions and actions_event are dropped
     # by the archive
     self.assertIn('instance_actions', results)
     self.assertIn('instance_actions_events', results)
     self.assertEqual(sum(results.values()), archived)
     # Verify that the pci_devices record has not been dropped
     self.assertNotIn('pci_devices', results)
Beispiel #2
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)