Remove the objectify decorator
The objectify decorator was used to convert DB objects into RPC objects, but it's not being used anymore since out objects API already has correspondent methods to match the dbapi ones. Also, since dbapi methods didn't get a context the decorator was forming bad RPC objects without a context stored within it. Change-Id: I892ab6ee2236af040c7f8effcfdfecb293e13ab6 Partial-Bug: #1314732
This commit is contained in:
parent
f575ae7ea3
commit
38182e7222
@ -12,29 +12,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import functools
|
||||
|
||||
from ironic.objects import chassis
|
||||
from ironic.objects import conductor
|
||||
from ironic.objects import node
|
||||
from ironic.objects import port
|
||||
|
||||
|
||||
def objectify(klass):
|
||||
"""Decorator to convert database results into specified objects."""
|
||||
def the_decorator(fn):
|
||||
@functools.wraps(fn)
|
||||
def wrapper(*args, **kwargs):
|
||||
result = fn(*args, **kwargs)
|
||||
try:
|
||||
return klass._from_db_object(klass(), result)
|
||||
except TypeError:
|
||||
# TODO(deva): handle lists of objects better
|
||||
# once support for those lands and is imported.
|
||||
return [klass._from_db_object(klass(), obj) for obj in result]
|
||||
return wrapper
|
||||
return the_decorator
|
||||
|
||||
Chassis = chassis.Chassis
|
||||
Conductor = conductor.Conductor
|
||||
Node = node.Node
|
||||
@ -43,5 +26,4 @@ Port = port.Port
|
||||
__all__ = (Chassis,
|
||||
Conductor,
|
||||
Node,
|
||||
Port,
|
||||
objectify)
|
||||
Port)
|
||||
|
@ -19,7 +19,6 @@ from testtools.matchers import HasLength
|
||||
from ironic.common import exception
|
||||
from ironic.common import utils as ironic_utils
|
||||
from ironic.db import api as db_api
|
||||
from ironic.db.sqlalchemy import models
|
||||
from ironic import objects
|
||||
|
||||
from ironic.tests.db import base
|
||||
@ -88,37 +87,6 @@ class TestChassisObject(base.DbTestCase):
|
||||
self.assertEqual(new_uuid, c.uuid)
|
||||
self.assertEqual(expected, mock_get_chassis.call_args_list)
|
||||
|
||||
def test_objectify(self):
|
||||
def _get_db_chassis():
|
||||
c = models.Chassis()
|
||||
c.update(self.fake_chassis)
|
||||
return c
|
||||
|
||||
@objects.objectify(objects.Chassis)
|
||||
def _convert_db_chassis():
|
||||
return _get_db_chassis()
|
||||
|
||||
self.assertIsInstance(_get_db_chassis(), models.Chassis)
|
||||
self.assertIsInstance(_convert_db_chassis(), objects.Chassis)
|
||||
|
||||
def test_objectify_many(self):
|
||||
def _get_many_db_chassis():
|
||||
chassis = []
|
||||
for i in range(5):
|
||||
c = models.Chassis()
|
||||
c.update(self.fake_chassis)
|
||||
chassis.append(c)
|
||||
return chassis
|
||||
|
||||
@objects.objectify(objects.Chassis)
|
||||
def _convert_many_db_chassis():
|
||||
return _get_many_db_chassis()
|
||||
|
||||
for c in _get_many_db_chassis():
|
||||
self.assertIsInstance(c, models.Chassis)
|
||||
for c in _convert_many_db_chassis():
|
||||
self.assertIsInstance(c, objects.Chassis)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.dbapi, 'get_chassis_list',
|
||||
autospec=True) as mock_get_list:
|
||||
|
@ -20,7 +20,6 @@ import mock
|
||||
from oslo.utils import timeutils
|
||||
|
||||
from ironic.db import api as db_api
|
||||
from ironic.db.sqlalchemy import models
|
||||
from ironic import objects
|
||||
from ironic.objects import utils as obj_utils
|
||||
from ironic.tests.db import base
|
||||
@ -82,34 +81,3 @@ class TestConductorObject(base.DbTestCase):
|
||||
c.refresh()
|
||||
self.assertEqual(obj_utils.datetime_or_none(t1), c.updated_at)
|
||||
self.assertEqual(expected, mock_get_cdr.call_args_list)
|
||||
|
||||
def test_objectify(self):
|
||||
def _get_db_conductor():
|
||||
c = models.Conductor()
|
||||
c.update(self.fake_conductor)
|
||||
return c
|
||||
|
||||
@objects.objectify(objects.Conductor)
|
||||
def _convert_db_conductor():
|
||||
return _get_db_conductor()
|
||||
|
||||
self.assertIsInstance(_get_db_conductor(), models.Conductor)
|
||||
self.assertIsInstance(_convert_db_conductor(), objects.Conductor)
|
||||
|
||||
def test_objectify_many(self):
|
||||
def _get_db_conductors():
|
||||
conductors = []
|
||||
for i in range(5):
|
||||
c = models.Conductor()
|
||||
c.update(self.fake_conductor)
|
||||
conductors.append(c)
|
||||
return conductors
|
||||
|
||||
@objects.objectify(objects.Conductor)
|
||||
def _convert_db_conductors():
|
||||
return _get_db_conductors()
|
||||
|
||||
for c in _get_db_conductors():
|
||||
self.assertIsInstance(c, models.Conductor)
|
||||
for c in _convert_db_conductors():
|
||||
self.assertIsInstance(c, objects.Conductor)
|
||||
|
@ -13,15 +13,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
|
||||
import mock
|
||||
from oslo.utils import timeutils
|
||||
from testtools.matchers import HasLength
|
||||
|
||||
from ironic.common import exception
|
||||
from ironic.db import api as db_api
|
||||
from ironic.db.sqlalchemy import models
|
||||
from ironic import objects
|
||||
from ironic.tests.db import base
|
||||
from ironic.tests.db import utils
|
||||
@ -88,53 +84,6 @@ class TestNodeObject(base.DbTestCase):
|
||||
self.assertEqual({"fake": "second"}, n.properties)
|
||||
self.assertEqual(expected, mock_get_node.call_args_list)
|
||||
|
||||
def test_objectify(self):
|
||||
def _get_db_node():
|
||||
n = models.Node()
|
||||
n.update(self.fake_node)
|
||||
return n
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def _convert_db_node():
|
||||
return _get_db_node()
|
||||
|
||||
self.assertIsInstance(_get_db_node(), models.Node)
|
||||
self.assertIsInstance(_convert_db_node(), objects.Node)
|
||||
|
||||
def test_objectify_deserialize_provision_updated_at(self):
|
||||
dt = timeutils.isotime(datetime.datetime(2000, 1, 1, 0, 0))
|
||||
self.fake_node['provision_updated_at'] = dt
|
||||
|
||||
def _get_db_node():
|
||||
n = models.Node()
|
||||
n.update(self.fake_node)
|
||||
return n
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def _convert_db_node():
|
||||
return _get_db_node()
|
||||
|
||||
self.assertIsInstance(_get_db_node(), models.Node)
|
||||
self.assertIsInstance(_convert_db_node(), objects.Node)
|
||||
|
||||
def test_objectify_many(self):
|
||||
def _get_db_nodes():
|
||||
nodes = []
|
||||
for i in range(5):
|
||||
n = models.Node()
|
||||
n.update(self.fake_node)
|
||||
nodes.append(n)
|
||||
return nodes
|
||||
|
||||
@objects.objectify(objects.Node)
|
||||
def _convert_db_nodes():
|
||||
return _get_db_nodes()
|
||||
|
||||
for n in _get_db_nodes():
|
||||
self.assertIsInstance(n, models.Node)
|
||||
for n in _convert_db_nodes():
|
||||
self.assertIsInstance(n, objects.Node)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.dbapi, 'get_node_list',
|
||||
autospec=True) as mock_get_list:
|
||||
|
@ -18,7 +18,6 @@ from testtools.matchers import HasLength
|
||||
|
||||
from ironic.common import exception
|
||||
from ironic.db import api as db_api
|
||||
from ironic.db.sqlalchemy import models
|
||||
from ironic import objects
|
||||
from ironic.tests.db import base
|
||||
from ironic.tests.db import utils
|
||||
@ -95,37 +94,6 @@ class TestPortObject(base.DbTestCase):
|
||||
|
||||
self.assertEqual(expected, mock_get_port.call_args_list)
|
||||
|
||||
def test_objectify(self):
|
||||
def _get_db_port():
|
||||
p = models.Port()
|
||||
p.update(self.fake_port)
|
||||
return p
|
||||
|
||||
@objects.objectify(objects.Port)
|
||||
def _convert_db_port():
|
||||
return _get_db_port()
|
||||
|
||||
self.assertIsInstance(_get_db_port(), models.Port)
|
||||
self.assertIsInstance(_convert_db_port(), objects.Port)
|
||||
|
||||
def test_objectify_many(self):
|
||||
def _get_db_ports():
|
||||
nodes = []
|
||||
for i in range(5):
|
||||
n = models.Port()
|
||||
n.update(self.fake_port)
|
||||
nodes.append(n)
|
||||
return nodes
|
||||
|
||||
@objects.objectify(objects.Port)
|
||||
def _convert_db_nodes():
|
||||
return _get_db_ports()
|
||||
|
||||
for p in _get_db_ports():
|
||||
self.assertIsInstance(p, models.Port)
|
||||
for p in _convert_db_nodes():
|
||||
self.assertIsInstance(p, objects.Port)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.dbapi, 'get_port_list',
|
||||
autospec=True) as mock_get_list:
|
||||
|
Loading…
x
Reference in New Issue
Block a user