Convert ironicclient node.get() call to Task
Changes the node.get() calls to Task calls. Also adds missing test case. Change-Id: I94b2c2bdb4c7c8bb7b96d3aa0e0117ec3585e620
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user