From 5369ffc3dce5cb5789fb654da2829f2de793e21a Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Fri, 19 Jun 2015 09:22:12 -0400 Subject: [PATCH] Convert ironicclient node.get() call to Task Changes the node.get() calls to Task calls. Also adds missing test case. Change-Id: I94b2c2bdb4c7c8bb7b96d3aa0e0117ec3585e620 --- shade/__init__.py | 9 +++++++-- shade/_tasks.py | 5 +++++ shade/tests/unit/test_shade_operator.py | 11 ++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/shade/__init__.py b/shade/__init__.py index 2e8acdb10..f1136ce95 100644 --- a/shade/__init__.py +++ b/shade/__init__.py @@ -2866,7 +2866,10 @@ class OperatorCloud(OpenStackCloud): are found. """ try: - return meta.obj_to_dict(self.ironic_client.node.get(name_or_id)) + return meta.obj_to_dict( + self.manager.submitTask( + _tasks.MachineNodeGet(node_id=name_or_id)) + ) except ironic_exceptions.ClientException: return None @@ -2882,7 +2885,9 @@ class OperatorCloud(OpenStackCloud): port = self.manager.submitTask( _tasks.MachinePortGetByAddress(address=mac)) return meta.obj_to_dict( - self.ironic_client.node.get(port.node_uuid)) + self.manager.submitTask( + _tasks.MachineNodeGet(node_id=port.node_uuid)) + ) except ironic_exceptions.ClientException: return None diff --git a/shade/_tasks.py b/shade/_tasks.py index ab5dff0b1..348a6d7c9 100644 --- a/shade/_tasks.py +++ b/shade/_tasks.py @@ -407,6 +407,11 @@ class MachinePortList(task_manager.Task): return client.ironic_client.port.list() +class MachineNodeGet(task_manager.Task): + def main(self, client): + return client.ironic_client.node.get(**self.args) + + class MachineNodeList(task_manager.Task): def main(self, client): return client.ironic_client.node.list(**self.args) diff --git a/shade/tests/unit/test_shade_operator.py b/shade/tests/unit/test_shade_operator.py index 32c04f3e2..c021229e8 100644 --- a/shade/tests/unit/test_shade_operator.py +++ b/shade/tests/unit/test_shade_operator.py @@ -33,6 +33,15 @@ class TestShadeOperator(base.TestCase): def test_operator_cloud(self): self.assertIsInstance(self.cloud, shade.OperatorCloud) + @mock.patch.object(shade.OperatorCloud, 'ironic_client') + def test_get_machine(self, mock_client): + node = fakes.FakeMachine(id='00000000-0000-0000-0000-000000000000', + name='bigOlFaker') + mock_client.node.get.return_value = node + machine = self.cloud.get_machine('bigOlFaker') + mock_client.node.get.assert_called_with(node_id='bigOlFaker') + self.assertEqual(meta.obj_to_dict(node), machine) + @mock.patch.object(shade.OperatorCloud, 'ironic_client') def test_get_machine_by_mac(self, mock_client): class port_value: @@ -51,7 +60,7 @@ class TestShadeOperator(base.TestCase): mock_client.port.get_by_address.assert_called_with( address='00:00:00:00:00:00') mock_client.node.get.assert_called_with( - '00000000-0000-0000-0000-000000000000') + node_id='00000000-0000-0000-0000-000000000000') self.assertEqual(machine, expected_value) @mock.patch.object(shade.OperatorCloud, 'ironic_client')