diff --git a/magnum/api/servicegroup.py b/magnum/api/servicegroup.py index 1077689eb6..f65ef6a34e 100644 --- a/magnum/api/servicegroup.py +++ b/magnum/api/servicegroup.py @@ -26,11 +26,11 @@ class ServiceGroup(object): def service_is_up(self, member): if not isinstance(member, magnum_service.MagnumService): raise TypeError - if member.get('forced_down'): + if member.forced_down: return False - last_heartbeat = (member.get( - 'last_seen_up') or member['updated_at'] or member['created_at']) + last_heartbeat = (member.last_seen_up or + member.updated_at or member.created_at) now = timeutils.utcnow(True) elapsed = timeutils.delta_seconds(last_heartbeat, now) is_up = abs(elapsed) <= self.service_down_time diff --git a/magnum/objects/magnum_service.py b/magnum/objects/magnum_service.py index bde0d634bd..ee0aeb8c22 100644 --- a/magnum/objects/magnum_service.py +++ b/magnum/objects/magnum_service.py @@ -17,8 +17,7 @@ from magnum.objects import base @base.MagnumObjectRegistry.register -class MagnumService(base.MagnumPersistentObject, base.MagnumObject, - base.MagnumObjectDictCompat): +class MagnumService(base.MagnumPersistentObject, base.MagnumObject): # Version 1.0: Initial version VERSION = '1.0' @@ -39,7 +38,7 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject, def _from_db_object(magnum_service, db_magnum_service): """Converts a database entity to a formal object.""" 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() return magnum_service diff --git a/magnum/tests/unit/objects/test_objects.py b/magnum/tests/unit/objects/test_objects.py index ca9ca961a1..2b3eb81ed2 100644 --- a/magnum/tests/unit/objects/test_objects.py +++ b/magnum/tests/unit/objects/test_objects.py @@ -28,8 +28,7 @@ gettext.install('magnum') @base.MagnumObjectRegistry.register -class MyObj(base.MagnumPersistentObject, base.MagnumObject, - base.MagnumObjectDictCompat): +class MyObj(base.MagnumPersistentObject, base.MagnumObject): VERSION = '1.0' fields = {'foo': fields.IntegerField(), @@ -152,8 +151,7 @@ class _TestObject(object): def test_load_in_base(self): @base.MagnumObjectRegistry.register_if(False) - class Foo(base.MagnumPersistentObject, base.MagnumObject, - base.MagnumObjectDictCompat): + class Foo(base.MagnumPersistentObject, base.MagnumObject): fields = {'foobar': fields.IntegerField()} obj = Foo(self.context) # NOTE(danms): Can't use assertRaisesRegexp() because of py26 @@ -292,19 +290,15 @@ class _TestObject(object): def test_get(self): obj = MyObj(self.context, foo=1) # 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 - self.assertEqual(1, obj.get('foo')) - # Bar is not loaded, so we should get the default - self.assertEqual('not-loaded', obj.get('bar', 'not-loaded')) + self.assertEqual(1, getattr(obj, 'foo')) # 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 - self.assertEqual('loaded!', obj.get('bar', 'not-loaded')) + self.assertEqual('loaded!', getattr(obj, 'bar', 'not-loaded')) # Invalid attribute should raise AttributeError - self.assertRaises(AttributeError, obj.get, 'nothing') - # ...even with a default - self.assertRaises(AttributeError, obj.get, 'nothing', 3) + self.assertFalse(hasattr(obj, 'nothing')) def test_object_inheritance(self): base_fields = list(base.MagnumPersistentObject.fields.keys()) @@ -330,8 +324,7 @@ class _TestObject(object): def test_obj_fields(self): @base.MagnumObjectRegistry.register_if(False) - class TestObj(base.MagnumPersistentObject, base.MagnumObject, - base.MagnumObjectDictCompat): + class TestObj(base.MagnumPersistentObject, base.MagnumObject): fields = {'foo': fields.IntegerField()} obj_extra_fields = ['bar']