Remove the usage of MagnumObjectDictCompat from magnum_service
Nova has removed the usage of NovaObjectDictCompat: https://blueprints.launchpad.net/nova/+spec/rm-object-dict-compat. magnum needs a similar cleanup. Change-Id: I07ce6db76aaca517aadff6fba7fb51ff0972ccca Partially-Implements: blueprint rm-object-dict-compat
This commit is contained in:
parent
edd6934577
commit
85b1babb00
@ -26,11 +26,11 @@ class ServiceGroup(object):
|
|||||||
def service_is_up(self, member):
|
def service_is_up(self, member):
|
||||||
if not isinstance(member, magnum_service.MagnumService):
|
if not isinstance(member, magnum_service.MagnumService):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
if member.get('forced_down'):
|
if member.forced_down:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
last_heartbeat = (member.get(
|
last_heartbeat = (member.last_seen_up or
|
||||||
'last_seen_up') or member['updated_at'] or member['created_at'])
|
member.updated_at or member.created_at)
|
||||||
now = timeutils.utcnow(True)
|
now = timeutils.utcnow(True)
|
||||||
elapsed = timeutils.delta_seconds(last_heartbeat, now)
|
elapsed = timeutils.delta_seconds(last_heartbeat, now)
|
||||||
is_up = abs(elapsed) <= self.service_down_time
|
is_up = abs(elapsed) <= self.service_down_time
|
||||||
|
@ -17,8 +17,7 @@ from magnum.objects import base
|
|||||||
|
|
||||||
|
|
||||||
@base.MagnumObjectRegistry.register
|
@base.MagnumObjectRegistry.register
|
||||||
class MagnumService(base.MagnumPersistentObject, base.MagnumObject,
|
class MagnumService(base.MagnumPersistentObject, base.MagnumObject):
|
||||||
base.MagnumObjectDictCompat):
|
|
||||||
# Version 1.0: Initial version
|
# Version 1.0: Initial version
|
||||||
VERSION = '1.0'
|
VERSION = '1.0'
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject,
|
|||||||
def _from_db_object(magnum_service, db_magnum_service):
|
def _from_db_object(magnum_service, db_magnum_service):
|
||||||
"""Converts a database entity to a formal object."""
|
"""Converts a database entity to a formal object."""
|
||||||
for field in magnum_service.fields:
|
for field in magnum_service.fields:
|
||||||
magnum_service[field] = db_magnum_service[field]
|
setattr(magnum_service, field, db_magnum_service[field])
|
||||||
|
|
||||||
magnum_service.obj_reset_changes()
|
magnum_service.obj_reset_changes()
|
||||||
return magnum_service
|
return magnum_service
|
||||||
|
@ -28,8 +28,7 @@ gettext.install('magnum')
|
|||||||
|
|
||||||
|
|
||||||
@base.MagnumObjectRegistry.register
|
@base.MagnumObjectRegistry.register
|
||||||
class MyObj(base.MagnumPersistentObject, base.MagnumObject,
|
class MyObj(base.MagnumPersistentObject, base.MagnumObject):
|
||||||
base.MagnumObjectDictCompat):
|
|
||||||
VERSION = '1.0'
|
VERSION = '1.0'
|
||||||
|
|
||||||
fields = {'foo': fields.IntegerField(),
|
fields = {'foo': fields.IntegerField(),
|
||||||
@ -152,8 +151,7 @@ class _TestObject(object):
|
|||||||
|
|
||||||
def test_load_in_base(self):
|
def test_load_in_base(self):
|
||||||
@base.MagnumObjectRegistry.register_if(False)
|
@base.MagnumObjectRegistry.register_if(False)
|
||||||
class Foo(base.MagnumPersistentObject, base.MagnumObject,
|
class Foo(base.MagnumPersistentObject, base.MagnumObject):
|
||||||
base.MagnumObjectDictCompat):
|
|
||||||
fields = {'foobar': fields.IntegerField()}
|
fields = {'foobar': fields.IntegerField()}
|
||||||
obj = Foo(self.context)
|
obj = Foo(self.context)
|
||||||
# NOTE(danms): Can't use assertRaisesRegexp() because of py26
|
# NOTE(danms): Can't use assertRaisesRegexp() because of py26
|
||||||
@ -292,19 +290,15 @@ class _TestObject(object):
|
|||||||
def test_get(self):
|
def test_get(self):
|
||||||
obj = MyObj(self.context, foo=1)
|
obj = MyObj(self.context, foo=1)
|
||||||
# Foo has value, should not get the default
|
# Foo has value, should not get the default
|
||||||
self.assertEqual(1, obj.get('foo', 2))
|
self.assertEqual(1, getattr(obj, 'foo', 2))
|
||||||
# Foo has value, should return the value without error
|
# Foo has value, should return the value without error
|
||||||
self.assertEqual(1, obj.get('foo'))
|
self.assertEqual(1, getattr(obj, 'foo'))
|
||||||
# Bar is not loaded, so we should get the default
|
|
||||||
self.assertEqual('not-loaded', obj.get('bar', 'not-loaded'))
|
|
||||||
# Bar without a default should lazy-load
|
# Bar without a default should lazy-load
|
||||||
self.assertEqual('loaded!', obj.get('bar'))
|
self.assertEqual('loaded!', getattr(obj, 'bar'))
|
||||||
# Bar now has a default, but loaded value should be returned
|
# Bar now has a default, but loaded value should be returned
|
||||||
self.assertEqual('loaded!', obj.get('bar', 'not-loaded'))
|
self.assertEqual('loaded!', getattr(obj, 'bar', 'not-loaded'))
|
||||||
# Invalid attribute should raise AttributeError
|
# Invalid attribute should raise AttributeError
|
||||||
self.assertRaises(AttributeError, obj.get, 'nothing')
|
self.assertFalse(hasattr(obj, 'nothing'))
|
||||||
# ...even with a default
|
|
||||||
self.assertRaises(AttributeError, obj.get, 'nothing', 3)
|
|
||||||
|
|
||||||
def test_object_inheritance(self):
|
def test_object_inheritance(self):
|
||||||
base_fields = list(base.MagnumPersistentObject.fields.keys())
|
base_fields = list(base.MagnumPersistentObject.fields.keys())
|
||||||
@ -330,8 +324,7 @@ class _TestObject(object):
|
|||||||
|
|
||||||
def test_obj_fields(self):
|
def test_obj_fields(self):
|
||||||
@base.MagnumObjectRegistry.register_if(False)
|
@base.MagnumObjectRegistry.register_if(False)
|
||||||
class TestObj(base.MagnumPersistentObject, base.MagnumObject,
|
class TestObj(base.MagnumPersistentObject, base.MagnumObject):
|
||||||
base.MagnumObjectDictCompat):
|
|
||||||
fields = {'foo': fields.IntegerField()}
|
fields = {'foo': fields.IntegerField()}
|
||||||
obj_extra_fields = ['bar']
|
obj_extra_fields = ['bar']
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user