Add destroy method to the RequestSpec object
Now that the RequestSpec object is fully checked and persisted for all instances, we need to make sure that we can delete the record when an instance is destroyed. For the moment, only providing the classmethod until we modify the compute API. Change-Id: I86fbb841f6d5abae556e376a5d2772e63e6ce88c
This commit is contained in:
parent
93e689516d
commit
5aa6c87c2f
@ -38,7 +38,8 @@ class RequestSpec(base.NovaObject):
|
|||||||
# Version 1.4: ImageMeta version 1.7
|
# Version 1.4: ImageMeta version 1.7
|
||||||
# Version 1.5: Added get_by_instance_uuid(), create(), save()
|
# Version 1.5: Added get_by_instance_uuid(), create(), save()
|
||||||
# Version 1.6: Added requested_destination
|
# Version 1.6: Added requested_destination
|
||||||
VERSION = '1.6'
|
# Version 1.7: Added destroy()
|
||||||
|
VERSION = '1.7'
|
||||||
|
|
||||||
fields = {
|
fields = {
|
||||||
'id': fields.IntegerField(),
|
'id': fields.IntegerField(),
|
||||||
@ -485,6 +486,18 @@ class RequestSpec(base.NovaObject):
|
|||||||
self._from_db_object(self._context, self, db_spec)
|
self._from_db_object(self._context, self, db_spec)
|
||||||
self.obj_reset_changes()
|
self.obj_reset_changes()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@db.api_context_manager.writer
|
||||||
|
def _destroy_in_db(context, instance_uuid):
|
||||||
|
result = context.session.query(api_models.RequestSpec).filter_by(
|
||||||
|
instance_uuid=instance_uuid).delete()
|
||||||
|
if not result:
|
||||||
|
raise exception.RequestSpecNotFound(instance_uuid=instance_uuid)
|
||||||
|
|
||||||
|
@base.remotable
|
||||||
|
def destroy(self):
|
||||||
|
self._destroy_in_db(self._context, self.instance_uuid)
|
||||||
|
|
||||||
def reset_forced_destinations(self):
|
def reset_forced_destinations(self):
|
||||||
"""Clears the forced destination fields from the RequestSpec object.
|
"""Clears the forced destination fields from the RequestSpec object.
|
||||||
|
|
||||||
|
@ -72,6 +72,19 @@ class RequestSpecTestCase(test.NoDBTestCase):
|
|||||||
spec = self._create_spec()
|
spec = self._create_spec()
|
||||||
self.assertRaises(exception.ObjectActionError, spec.create)
|
self.assertRaises(exception.ObjectActionError, spec.create)
|
||||||
|
|
||||||
|
def test_destroy(self):
|
||||||
|
spec = self._create_spec()
|
||||||
|
spec.destroy()
|
||||||
|
self.assertRaises(
|
||||||
|
exception.RequestSpecNotFound,
|
||||||
|
self.spec_obj._get_by_instance_uuid_from_db, self.context,
|
||||||
|
self.instance_uuid)
|
||||||
|
|
||||||
|
def test_destroy_not_found(self):
|
||||||
|
spec = self._create_spec()
|
||||||
|
spec.destroy()
|
||||||
|
self.assertRaises(exception.RequestSpecNotFound, spec.destroy)
|
||||||
|
|
||||||
|
|
||||||
@db.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _delete_request_spec(context, instance_uuid):
|
def _delete_request_spec(context, instance_uuid):
|
||||||
|
@ -1179,7 +1179,7 @@ object_data = {
|
|||||||
'PciDevicePoolList': '1.1-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
'PciDevicePoolList': '1.1-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||||
'Quotas': '1.2-1fe4cd50593aaf5d36a6dc5ab3f98fb3',
|
'Quotas': '1.2-1fe4cd50593aaf5d36a6dc5ab3f98fb3',
|
||||||
'QuotasNoOp': '1.2-e041ddeb7dc8188ca71706f78aad41c1',
|
'QuotasNoOp': '1.2-e041ddeb7dc8188ca71706f78aad41c1',
|
||||||
'RequestSpec': '1.6-c1cb516acdf120d367a42d343ed695b5',
|
'RequestSpec': '1.7-5ff3e9df208bf25f8215f1b87624970d',
|
||||||
'ResourceProvider': '1.1-7bbcd5ea1c51782692f55489ab08dea6',
|
'ResourceProvider': '1.1-7bbcd5ea1c51782692f55489ab08dea6',
|
||||||
'ResourceProviderList': '1.0-82bd48d8d0f7913bbe7266f3835c81bf',
|
'ResourceProviderList': '1.0-82bd48d8d0f7913bbe7266f3835c81bf',
|
||||||
'S3ImageMapping': '1.0-7dd7366a890d82660ed121de9092276e',
|
'S3ImageMapping': '1.0-7dd7366a890d82660ed121de9092276e',
|
||||||
|
@ -535,6 +535,14 @@ class _TestRequestSpecObject(object):
|
|||||||
_test_save_args):
|
_test_save_args):
|
||||||
req_obj.save()
|
req_obj.save()
|
||||||
|
|
||||||
|
@mock.patch.object(request_spec.RequestSpec, '_destroy_in_db')
|
||||||
|
def test_destroy(self, destroy_in_db):
|
||||||
|
req_obj = fake_request_spec.fake_spec_obj()
|
||||||
|
req_obj.destroy()
|
||||||
|
|
||||||
|
destroy_in_db.assert_called_once_with(req_obj._context,
|
||||||
|
req_obj.instance_uuid)
|
||||||
|
|
||||||
def test_reset_forced_destinations(self):
|
def test_reset_forced_destinations(self):
|
||||||
req_obj = fake_request_spec.fake_spec_obj()
|
req_obj = fake_request_spec.fake_spec_obj()
|
||||||
# Making sure the fake object has forced hosts and nodes
|
# Making sure the fake object has forced hosts and nodes
|
||||||
|
Loading…
Reference in New Issue
Block a user