Merge "Make obj_set_defaults() more useful"

This commit is contained in:
Jenkins 2015-02-12 19:59:06 +00:00 committed by Gerrit Code Review
commit 24bb0f981c
2 changed files with 10 additions and 1 deletions

View File

@ -495,7 +495,8 @@ class NovaObject(object):
raise exception.ObjectActionError(
action='set_defaults',
reason='No default set for field %s' % attr)
setattr(self, attr, default)
if not self.obj_attr_is_set(attr):
setattr(self, attr, default)
def obj_load_attr(self, attrname):
"""Load an additional attribute from the real object.

View File

@ -884,6 +884,14 @@ class TestObject(_LocalTest, _TestObject):
self.assertEqual(set(['deleted', 'foo']), obj.obj_what_changed())
self.assertEqual(1, obj.foo)
def test_set_defaults_not_overwrite(self):
# NOTE(danms): deleted defaults to False, so verify that it does
# not get reset by obj_set_defaults()
obj = MyObj(deleted=True)
obj.obj_set_defaults()
self.assertEqual(1, obj.foo)
self.assertTrue(obj.deleted)
class TestRemoteObject(_RemoteTest, _TestObject):
def test_major_version_mismatch(self):