Merge "Initial oslo.versionedobjects conversion"
This commit is contained in:
@@ -21,6 +21,7 @@ from oslo_context import context
|
||||
from oslo_log import log as logging
|
||||
import oslo_messaging as messaging
|
||||
from oslo_utils import versionutils
|
||||
from oslo_versionedobjects import base as ovo_base
|
||||
import six
|
||||
|
||||
from ironic.common import exception
|
||||
@@ -32,10 +33,6 @@ from ironic.objects import utils as obj_utils
|
||||
LOG = logging.getLogger('object')
|
||||
|
||||
|
||||
class NotSpecifiedSentinel(object):
|
||||
pass
|
||||
|
||||
|
||||
def get_attrname(name):
|
||||
"""Return the mangled name of the attribute's underlying storage."""
|
||||
return '_%s' % name
|
||||
@@ -169,7 +166,7 @@ def check_object_version(server, client):
|
||||
|
||||
|
||||
@six.add_metaclass(IronicObjectMetaclass)
|
||||
class IronicObject(object):
|
||||
class IronicObject(ovo_base.VersionedObjectDictCompat):
|
||||
"""Base class and object factory.
|
||||
|
||||
This forms the base of all objects that can be remoted or instantiated
|
||||
@@ -396,62 +393,6 @@ class IronicObject(object):
|
||||
def obj_fields(self):
|
||||
return list(self.fields) + self.obj_extra_fields
|
||||
|
||||
# dictish syntactic sugar
|
||||
def iteritems(self):
|
||||
"""For backwards-compatibility with dict-based objects.
|
||||
|
||||
NOTE(danms): May be removed in the future.
|
||||
"""
|
||||
for name in list(self.fields) + self.obj_extra_fields:
|
||||
if (hasattr(self, get_attrname(name)) or
|
||||
name in self.obj_extra_fields):
|
||||
yield name, getattr(self, name)
|
||||
|
||||
items = lambda self: list(self.iteritems())
|
||||
|
||||
def __getitem__(self, name):
|
||||
"""For backwards-compatibility with dict-based objects.
|
||||
|
||||
NOTE(danms): May be removed in the future.
|
||||
"""
|
||||
return getattr(self, name)
|
||||
|
||||
def __setitem__(self, name, value):
|
||||
"""For backwards-compatibility with dict-based objects.
|
||||
|
||||
NOTE(danms): May be removed in the future.
|
||||
"""
|
||||
setattr(self, name, value)
|
||||
|
||||
def __contains__(self, name):
|
||||
"""For backwards-compatibility with dict-based objects.
|
||||
|
||||
NOTE(danms): May be removed in the future.
|
||||
"""
|
||||
return hasattr(self, get_attrname(name))
|
||||
|
||||
def get(self, key, value=NotSpecifiedSentinel):
|
||||
"""For backwards-compatibility with dict-based objects.
|
||||
|
||||
NOTE(danms): May be removed in the future.
|
||||
"""
|
||||
if key not in self.obj_fields:
|
||||
raise AttributeError(
|
||||
_("'%(objclass)s' object has no attribute '%(attrname)s'") %
|
||||
{'objclass': self.__class__, 'attrname': key})
|
||||
if value != NotSpecifiedSentinel and not self.obj_attr_is_set(key):
|
||||
return value
|
||||
else:
|
||||
return self[key]
|
||||
|
||||
def update(self, updates):
|
||||
"""For backwards-compatibility with dict-base objects.
|
||||
|
||||
NOTE(danms): May be removed in the future.
|
||||
"""
|
||||
for key, value in updates.items():
|
||||
self[key] = value
|
||||
|
||||
def as_dict(self):
|
||||
return dict((k, getattr(self, k))
|
||||
for k in self.fields
|
||||
|
||||
@@ -292,16 +292,6 @@ class _TestObject(object):
|
||||
obj.foo = 'a'
|
||||
self.assertRaises(ValueError, fail)
|
||||
|
||||
def test_object_dict_syntax(self):
|
||||
obj = MyObj(self.context)
|
||||
obj.foo = 123
|
||||
obj.bar = 'bar'
|
||||
self.assertEqual(123, obj['foo'])
|
||||
self.assertEqual([('bar', 'bar'), ('foo', 123)],
|
||||
sorted(obj.items(), key=lambda x: x[0]))
|
||||
self.assertEqual([('bar', 'bar'), ('foo', 123)],
|
||||
sorted(list(obj.iteritems()), key=lambda x: x[0]))
|
||||
|
||||
def test_load(self):
|
||||
obj = MyObj(self.context)
|
||||
self.assertEqual('loaded!', obj.bar)
|
||||
|
||||
@@ -40,3 +40,4 @@ keystonemiddleware>=1.5.0
|
||||
oslo.messaging!=1.12.0,>=1.8.0 # Apache-2.0
|
||||
retrying!=1.3.0,>=1.2.3 # Apache-2.0
|
||||
posix-ipc
|
||||
oslo.versionedobjects>=0.3.0,!=0.5.0
|
||||
|
||||
Reference in New Issue
Block a user