Merge "Default deleted if the instance from BuildRequest is not having it"

This commit is contained in:
Jenkins
2016-11-29 11:51:25 +00:00
committed by Gerrit Code Review
2 changed files with 17 additions and 1 deletions
+5 -1
View File
@@ -80,9 +80,13 @@ class BuildRequest(base.NovaObject):
LOG.exception(_LE('Could not deserialize instance in '
'BuildRequest'))
raise exception.BuildRequestNotFound(uuid=self.instance_uuid)
# NOTE(sbauza): The instance primitive should already have the deleted
# field being set, so when hydrating it back here, we should get the
# right value but in case we don't have it, let's suppose that the
# instance is not deleted, which is the default value for that field.
self.instance.obj_set_defaults('deleted')
# NOTE(alaski): Set some fields on instance that are needed by the api,
# not lazy-loadable, and don't change.
self.instance.deleted = 0
self.instance.disable_terminate = False
self.instance.terminated_at = None
self.instance.host = None
@@ -12,6 +12,7 @@
import mock
from oslo_serialization import jsonutils
from oslo_versionedobjects import base as o_vo_base
from nova import exception
from nova import objects
@@ -147,6 +148,17 @@ class _TestBuildRequestObject(object):
self.assertEqual(getattr(build_request.instance, field),
getattr(instance, field))
def test_from_db_object_set_deleted(self):
# Assert that if we persisted an instance not yet having the deleted
# field being set, we still return a value for that field.
fake_req = fake_build_request.fake_db_req()
with mock.patch.object(o_vo_base.VersionedObject,
'obj_set_defaults') as mock_obj_set_defaults:
build_request = objects.BuildRequest._from_db_object(
self.context, objects.BuildRequest(), fake_req)
mock_obj_set_defaults.assert_called_once_with('deleted')
self.assertFalse(build_request.instance.deleted)
class TestBuildRequestObject(test_objects._LocalTest,
_TestBuildRequestObject):