Fix RequestSpec _from_db_object

The semantics of _from_db_update are that it should update the object
that is passed in since it it typically used within an object to update
itself.  RequestSpec._from_db_object was not updating the object that
was passed in and was essentially aliasing the parameter with a newly
created object.  This fixes it and updates the tests which worked
because they used _from_db_update in a different manner than it's used
in practice.

Change-Id: Ia516caceceddc1617b78871f699a7ad674fb044a
This commit is contained in:
Andrew Laski 2016-01-27 08:32:13 -05:00
parent df0fca62cf
commit 9e4b75058b
2 changed files with 10 additions and 4 deletions

View File

@ -366,7 +366,14 @@ class RequestSpec(base.NovaObject):
@staticmethod
def _from_db_object(context, spec, db_spec):
spec = spec.obj_from_primitive(jsonutils.loads(db_spec['spec']))
spec_obj = spec.obj_from_primitive(jsonutils.loads(db_spec['spec']))
for key in spec.fields:
# Load these from the db model not the serialized object within,
# though they should match.
if key in ['id', 'instance_uuid']:
setattr(spec, key, db_spec[key])
else:
setattr(spec, key, getattr(spec_obj, key))
spec._context = context
spec.obj_reset_changes()
return spec

View File

@ -31,10 +31,9 @@ class RequestSpecTestCase(test.NoDBTestCase):
args = fake_request_spec.fake_db_spec()
args.pop('id', None)
self.instance_uuid = args['instance_uuid']
spec = request_spec.RequestSpec._from_db_object(self.context,
self.spec_obj,
request_spec.RequestSpec._from_db_object(self.context, self.spec_obj,
self.spec_obj._create_in_db(self.context, args))
return spec
return self.spec_obj
def test_get_by_instance_uuid_not_found(self):
self.assertRaises(exception.RequestSpecNotFound,