Skip to content

Commit

Permalink
Merge "Default deleted if the instance from BuildRequest is not havin…
Browse files Browse the repository at this point in the history
…g it"
  • Loading branch information
Jenkins authored and openstack-gerrit committed Nov 29, 2016
2 parents 8dafe05 + 37ec9b9 commit f47716c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nova/objects/build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ def _load_instance(self, db_instance):
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
Expand Down
12 changes: 12 additions & 0 deletions nova/tests/unit/objects/test_build_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -147,6 +148,17 @@ def test_get_new_instance_show_changed_fields(self):
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):
Expand Down

0 comments on commit f47716c

Please sign in to comment.