Do not set the context twice when forming RPC objects
The context is already being set once the object is instantiated so there's no need to set it again. This patch fixes that and update tests to validate if the right context has been added to the object. Change-Id: I7eb3d734a990eb70e4fbfce6c539b268900b5241 Partial-Bug: #1314732
This commit is contained in:
parent
654ea01741
commit
4d7c3e828a
|
@ -74,9 +74,6 @@ class Chassis(base.IronicObject):
|
|||
"""
|
||||
db_chassis = cls.dbapi.get_chassis_by_id(chassis_id)
|
||||
chassis = Chassis._from_db_object(cls(context), db_chassis)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
chassis._context = context
|
||||
return chassis
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
@ -89,9 +86,6 @@ class Chassis(base.IronicObject):
|
|||
"""
|
||||
db_chassis = cls.dbapi.get_chassis_by_uuid(uuid)
|
||||
chassis = Chassis._from_db_object(cls(context), db_chassis)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
chassis._context = context
|
||||
return chassis
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
@ -107,18 +101,12 @@ class Chassis(base.IronicObject):
|
|||
:returns: a list of :class:`Chassis` object.
|
||||
|
||||
"""
|
||||
chassis_list = []
|
||||
db_chassis = cls.dbapi.get_chassis_list(limit=limit,
|
||||
marker=marker,
|
||||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
for obj in db_chassis:
|
||||
chassis = Chassis._from_db_object(cls(context), obj)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
chassis._context = context
|
||||
chassis_list.append(chassis)
|
||||
return chassis_list
|
||||
return [Chassis._from_db_object(cls(context), obj)
|
||||
for obj in db_chassis]
|
||||
|
||||
@base.remotable
|
||||
def create(self, context=None):
|
||||
|
|
|
@ -48,9 +48,6 @@ class Conductor(base.IronicObject):
|
|||
"""
|
||||
db_obj = cls.dbapi.get_conductor(hostname)
|
||||
conductor = Conductor._from_db_object(cls(context), db_obj)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
conductor._context = context
|
||||
return conductor
|
||||
|
||||
def save(self, context):
|
||||
|
|
|
@ -100,9 +100,6 @@ class Node(base.IronicObject):
|
|||
"""
|
||||
db_node = cls.dbapi.get_node_by_id(node_id)
|
||||
node = Node._from_db_object(cls(context), db_node)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
node._context = context
|
||||
return node
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
@ -114,9 +111,6 @@ class Node(base.IronicObject):
|
|||
"""
|
||||
db_node = cls.dbapi.get_node_by_uuid(uuid)
|
||||
node = Node._from_db_object(cls(context), db_node)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
node._context = context
|
||||
return node
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
@ -128,9 +122,6 @@ class Node(base.IronicObject):
|
|||
"""
|
||||
db_node = cls.dbapi.get_node_by_instance(instance_uuid)
|
||||
node = Node._from_db_object(cls(context), db_node)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
node._context = context
|
||||
return node
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
@ -147,17 +138,10 @@ class Node(base.IronicObject):
|
|||
:returns: a list of :class:`Node` object.
|
||||
|
||||
"""
|
||||
node_list = []
|
||||
db_nodes = cls.dbapi.get_node_list(filters=filters, limit=limit,
|
||||
marker=marker, sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
for obj in db_nodes:
|
||||
node = Node._from_db_object(cls(context), obj)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
node._context = context
|
||||
node_list.append(node)
|
||||
return node_list
|
||||
return [Node._from_db_object(cls(context), obj) for obj in db_nodes]
|
||||
|
||||
@base.remotable_classmethod
|
||||
def reserve(cls, context, tag, node_id):
|
||||
|
@ -175,9 +159,6 @@ class Node(base.IronicObject):
|
|||
"""
|
||||
db_node = cls.dbapi.reserve_node(tag, node_id)
|
||||
node = Node._from_db_object(cls(context), db_node)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
node._context = context
|
||||
return node
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
|
|
@ -51,14 +51,7 @@ class Port(base.IronicObject):
|
|||
@staticmethod
|
||||
def _from_db_object_list(db_objects, cls, context):
|
||||
"""Converts a list of database entities to a list of formal objects."""
|
||||
port_list = []
|
||||
for obj in db_objects:
|
||||
port = Port._from_db_object(cls(context), obj)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
port._context = context
|
||||
port_list.append(port)
|
||||
return port_list
|
||||
return [Port._from_db_object(cls(context), obj) for obj in db_objects]
|
||||
|
||||
@base.remotable_classmethod
|
||||
def get(cls, context, port_id):
|
||||
|
@ -85,9 +78,6 @@ class Port(base.IronicObject):
|
|||
"""
|
||||
db_port = cls.dbapi.get_port_by_id(port_id)
|
||||
port = Port._from_db_object(cls(context), db_port)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
port._context = context
|
||||
return port
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
@ -100,9 +90,6 @@ class Port(base.IronicObject):
|
|||
"""
|
||||
db_port = cls.dbapi.get_port_by_uuid(uuid)
|
||||
port = Port._from_db_object(cls(context), db_port)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
port._context = context
|
||||
return port
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
@ -115,9 +102,6 @@ class Port(base.IronicObject):
|
|||
"""
|
||||
db_port = cls.dbapi.get_port_by_address(address)
|
||||
port = Port._from_db_object(cls(context), db_port)
|
||||
# FIXME(comstud): Setting of the context should be moved to
|
||||
# _from_db_object().
|
||||
port._context = context
|
||||
return port
|
||||
|
||||
@base.remotable_classmethod
|
||||
|
|
|
@ -38,9 +38,10 @@ class TestChassisObject(base.DbTestCase):
|
|||
autospec=True) as mock_get_chassis:
|
||||
mock_get_chassis.return_value = self.fake_chassis
|
||||
|
||||
objects.Chassis.get(self.context, chassis_id)
|
||||
chassis = objects.Chassis.get(self.context, chassis_id)
|
||||
|
||||
mock_get_chassis.assert_called_once_with(chassis_id)
|
||||
self.assertEqual(self.context, chassis._context)
|
||||
|
||||
def test_get_by_uuid(self):
|
||||
uuid = self.fake_chassis['uuid']
|
||||
|
@ -48,9 +49,10 @@ class TestChassisObject(base.DbTestCase):
|
|||
autospec=True) as mock_get_chassis:
|
||||
mock_get_chassis.return_value = self.fake_chassis
|
||||
|
||||
objects.Chassis.get(self.context, uuid)
|
||||
chassis = objects.Chassis.get(self.context, uuid)
|
||||
|
||||
mock_get_chassis.assert_called_once_with(uuid)
|
||||
self.assertEqual(self.context, chassis._context)
|
||||
|
||||
def test_get_bad_id_and_uuid(self):
|
||||
self.assertRaises(exception.InvalidIdentity,
|
||||
|
@ -71,6 +73,7 @@ class TestChassisObject(base.DbTestCase):
|
|||
mock_get_chassis.assert_called_once_with(uuid)
|
||||
mock_update_chassis.assert_called_once_with(
|
||||
uuid, {'extra': {"test": 123}})
|
||||
self.assertEqual(self.context, c._context)
|
||||
|
||||
def test_refresh(self):
|
||||
uuid = self.fake_chassis['uuid']
|
||||
|
@ -86,6 +89,7 @@ class TestChassisObject(base.DbTestCase):
|
|||
c.refresh()
|
||||
self.assertEqual(new_uuid, c.uuid)
|
||||
self.assertEqual(expected, mock_get_chassis.call_args_list)
|
||||
self.assertEqual(self.context, c._context)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.dbapi, 'get_chassis_list',
|
||||
|
@ -94,3 +98,4 @@ class TestChassisObject(base.DbTestCase):
|
|||
chassis = objects.Chassis.list(self.context)
|
||||
self.assertThat(chassis, HasLength(1))
|
||||
self.assertIsInstance(chassis[0], objects.Chassis)
|
||||
self.assertEqual(self.context, chassis[0]._context)
|
||||
|
|
|
@ -81,3 +81,4 @@ 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)
|
||||
self.assertEqual(self.context, c._context)
|
||||
|
|
|
@ -36,9 +36,10 @@ class TestNodeObject(base.DbTestCase):
|
|||
autospec=True) as mock_get_node:
|
||||
mock_get_node.return_value = self.fake_node
|
||||
|
||||
objects.Node.get(self.context, node_id)
|
||||
node = objects.Node.get(self.context, node_id)
|
||||
|
||||
mock_get_node.assert_called_once_with(node_id)
|
||||
self.assertEqual(self.context, node._context)
|
||||
|
||||
def test_get_by_uuid(self):
|
||||
uuid = self.fake_node['uuid']
|
||||
|
@ -46,9 +47,10 @@ class TestNodeObject(base.DbTestCase):
|
|||
autospec=True) as mock_get_node:
|
||||
mock_get_node.return_value = self.fake_node
|
||||
|
||||
objects.Node.get(self.context, uuid)
|
||||
node = objects.Node.get(self.context, uuid)
|
||||
|
||||
mock_get_node.assert_called_once_with(uuid)
|
||||
self.assertEqual(self.context, node._context)
|
||||
|
||||
def test_get_bad_id_and_uuid(self):
|
||||
self.assertRaises(exception.InvalidIdentity,
|
||||
|
@ -69,6 +71,7 @@ class TestNodeObject(base.DbTestCase):
|
|||
mock_get_node.assert_called_once_with(uuid)
|
||||
mock_update_node.assert_called_once_with(
|
||||
uuid, {'properties': {"fake": "property"}})
|
||||
self.assertEqual(self.context, n._context)
|
||||
|
||||
def test_refresh(self):
|
||||
uuid = self.fake_node['uuid']
|
||||
|
@ -83,6 +86,7 @@ class TestNodeObject(base.DbTestCase):
|
|||
n.refresh()
|
||||
self.assertEqual({"fake": "second"}, n.properties)
|
||||
self.assertEqual(expected, mock_get_node.call_args_list)
|
||||
self.assertEqual(self.context, n._context)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.dbapi, 'get_node_list',
|
||||
|
@ -91,6 +95,7 @@ class TestNodeObject(base.DbTestCase):
|
|||
nodes = objects.Node.list(self.context)
|
||||
self.assertThat(nodes, HasLength(1))
|
||||
self.assertIsInstance(nodes[0], objects.Node)
|
||||
self.assertEqual(self.context, nodes[0]._context)
|
||||
|
||||
def test_reserve(self):
|
||||
with mock.patch.object(self.dbapi, 'reserve_node',
|
||||
|
@ -101,6 +106,7 @@ class TestNodeObject(base.DbTestCase):
|
|||
node = objects.Node.reserve(self.context, fake_tag, node_id)
|
||||
self.assertIsInstance(node, objects.Node)
|
||||
mock_reserve.assert_called_once_with(fake_tag, node_id)
|
||||
self.assertEqual(self.context, node._context)
|
||||
|
||||
def test_reserve_node_not_found(self):
|
||||
with mock.patch.object(self.dbapi, 'reserve_node',
|
||||
|
|
|
@ -36,9 +36,10 @@ class TestPortObject(base.DbTestCase):
|
|||
autospec=True) as mock_get_port:
|
||||
mock_get_port.return_value = self.fake_port
|
||||
|
||||
objects.Port.get(self.context, port_id)
|
||||
port = objects.Port.get(self.context, port_id)
|
||||
|
||||
mock_get_port.assert_called_once_with(port_id)
|
||||
self.assertEqual(self.context, port._context)
|
||||
|
||||
def test_get_by_uuid(self):
|
||||
uuid = self.fake_port['uuid']
|
||||
|
@ -46,9 +47,10 @@ class TestPortObject(base.DbTestCase):
|
|||
autospec=True) as mock_get_port:
|
||||
mock_get_port.return_value = self.fake_port
|
||||
|
||||
objects.Port.get(self.context, uuid)
|
||||
port = objects.Port.get(self.context, uuid)
|
||||
|
||||
mock_get_port.assert_called_once_with(uuid)
|
||||
self.assertEqual(self.context, port._context)
|
||||
|
||||
def test_get_by_address(self):
|
||||
address = self.fake_port['address']
|
||||
|
@ -56,9 +58,10 @@ class TestPortObject(base.DbTestCase):
|
|||
autospec=True) as mock_get_port:
|
||||
mock_get_port.return_value = self.fake_port
|
||||
|
||||
objects.Port.get(self.context, address)
|
||||
port = objects.Port.get(self.context, address)
|
||||
|
||||
mock_get_port.assert_called_once_with(address)
|
||||
self.assertEqual(self.context, port._context)
|
||||
|
||||
def test_get_bad_id_and_uuid_and_address(self):
|
||||
self.assertRaises(exception.InvalidIdentity,
|
||||
|
@ -78,6 +81,7 @@ class TestPortObject(base.DbTestCase):
|
|||
mock_get_port.assert_called_once_with(uuid)
|
||||
mock_update_port.assert_called_once_with(
|
||||
uuid, {'address': "b2:54:00:cf:2d:40"})
|
||||
self.assertEqual(self.context, p._context)
|
||||
|
||||
def test_refresh(self):
|
||||
uuid = self.fake_port['uuid']
|
||||
|
@ -93,6 +97,7 @@ class TestPortObject(base.DbTestCase):
|
|||
self.assertEqual("c3:54:00:cf:2d:40", p.address)
|
||||
|
||||
self.assertEqual(expected, mock_get_port.call_args_list)
|
||||
self.assertEqual(self.context, p._context)
|
||||
|
||||
def test_list(self):
|
||||
with mock.patch.object(self.dbapi, 'get_port_list',
|
||||
|
@ -101,3 +106,4 @@ class TestPortObject(base.DbTestCase):
|
|||
ports = objects.Port.list(self.context)
|
||||
self.assertThat(ports, HasLength(1))
|
||||
self.assertIsInstance(ports[0], objects.Port)
|
||||
self.assertEqual(self.context, ports[0]._context)
|
||||
|
|
Loading…
Reference in New Issue