From 1541b40456eade6cd976ab8491e98c943db8bd95 Mon Sep 17 00:00:00 2001 From: Roman Prykhodchenko Date: Mon, 24 Jun 2013 12:57:18 +0300 Subject: [PATCH] Re-define 'extra' as dict_or_none. Changed type of 'extra' fields from str_or_none to dict_or_none for Port and Chassis. DB model defines 'extra' as a JSONEncodedDict which is a type decorator that stores a value as a json string to the database and parses it to a dict when loading the object. That's why we need to change the type of the 'extra' field from str_or_none to dict_or_none. Test utils have been modified to simulate behavior of DB layer better. Fixes: bug #1194072 Change-Id: I2c73069f795754078ce8cba50ee669cce2f4b27d --- ironic/objects/chassis.py | 2 +- ironic/objects/port.py | 2 +- ironic/tests/db/utils.py | 6 +++--- ironic/tests/objects/test_chassis.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ironic/objects/chassis.py b/ironic/objects/chassis.py index 8b11bc2367..ab532bdb23 100644 --- a/ironic/objects/chassis.py +++ b/ironic/objects/chassis.py @@ -25,7 +25,7 @@ class Chassis(base.IronicObject): fields = { 'id': int, 'uuid': utils.str_or_none, - 'extra': utils.str_or_none, + 'extra': utils.dict_or_none, } @staticmethod diff --git a/ironic/objects/port.py b/ironic/objects/port.py index e172d6a5cf..e9f5eb87dd 100644 --- a/ironic/objects/port.py +++ b/ironic/objects/port.py @@ -27,7 +27,7 @@ class Port(base.IronicObject): 'uuid': utils.str_or_none, 'node_id': utils.int_or_none, 'address': utils.str_or_none, - 'extra': utils.str_or_none, + 'extra': utils.dict_or_none, } @staticmethod diff --git a/ironic/tests/db/utils.py b/ironic/tests/db/utils.py index dabc657521..6ba0217a48 100644 --- a/ironic/tests/db/utils.py +++ b/ironic/tests/db/utils.py @@ -79,7 +79,7 @@ def get_test_node(**kw): 'driver_info': kw.get('driver_info', fake_info), 'properties': kw.get('properties', properties), 'reservation': None, - 'extra': kw.get('extra', '{}'), + 'extra': kw.get('extra', {}), 'updated_at': None, 'created_at': None, } @@ -92,7 +92,7 @@ def get_test_port(**kw): 'uuid': kw.get('uuid', '1be26c0b-03f2-4d2e-ae87-c02d7f33c781'), 'node_id': kw.get('node_id', 123), 'address': kw.get('address', '52:54:00:cf:2d:31'), - 'extra': kw.get('extra', '{}'), + 'extra': kw.get('extra', {}), 'created_at': kw.get('created_at'), 'updated_at': kw.get('updated_at'), } @@ -104,7 +104,7 @@ def get_test_chassis(**kw): chassis = { 'id': kw.get('id', 42), 'uuid': kw.get('uuid', 'e74c40e0-d825-11e2-a28f-0800200c9a66'), - 'extra': kw.get('extra', '{}'), + 'extra': kw.get('extra', {}), 'created_at': kw.get('created_at'), 'updated_at': kw.get('updated_at'), } diff --git a/ironic/tests/objects/test_chassis.py b/ironic/tests/objects/test_chassis.py index 76575b9dce..725f428bb1 100644 --- a/ironic/tests/objects/test_chassis.py +++ b/ironic/tests/objects/test_chassis.py @@ -48,11 +48,11 @@ class TestChassisObject(base.DbTestCase): self.mox.StubOutWithMock(self.dbapi, 'update_chassis') self.dbapi.get_chassis(uuid).AndReturn(self.fake_chassis) - self.dbapi.update_chassis(uuid, {'extra': '{"test": 123}'}) + self.dbapi.update_chassis(uuid, {'extra': {"test": 123}}) self.mox.ReplayAll() c = objects.Chassis.get_by_uuid(self.ctxt, uuid) - c.extra = '{"test": 123}' + c.extra = {"test": 123} c.save() self.mox.VerifyAll()