Merge "Make obj_set_defaults() more useful"
This commit is contained in:
commit
24bb0f981c
@ -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.
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user