Skip to content

Commit fbb77be

Browse files
committed
Fix wrong usage of the python ironic client
1 parent 200ddf8 commit fbb77be

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎python/understack-workflows/tests/test_enroll_server.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def make_ironic_client(
149149
)
150150
inspect_interface_iter = iter(inspect_interfaces)
151151
fake_client = MagicMock()
152-
fake_client.node.api.runbook.get.side_effect = lambda trait: SimpleNamespace(
152+
fake_client.runbook.get.side_effect = lambda trait: SimpleNamespace(
153153
uuid=runbook_ids[trait]
154154
)
155155
fake_client.node.create.return_value = created_node
@@ -465,7 +465,7 @@ def test_apply_firmware_updates_runs_traits_in_numeric_order(mocker):
465465

466466
enroll_server.ironic_node.apply_firmware_updates(node)
467467

468-
fake_ironic.node.api.runbook.get.assert_has_calls(
468+
fake_ironic.runbook.get.assert_has_calls(
469469
[
470470
call("CUSTOM_FIRMWARE_UPDATE_3_NIC"),
471471
call("CUSTOM_FIRMWARE_UPDATE_20_BIOS"),

‎python/understack-workflows/understack_workflows/ironic/client.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from ironicclient.v1.client import Client as IronicV1Client
66
from ironicclient.v1.node import Node
77
from ironicclient.v1.port import Port
8+
from ironicclient.v1.runbook import Runbook
89

910
from understack_workflows.openstack.client import get_ironic_client
1011

@@ -58,8 +59,17 @@ def set_node_target_raid_config(self, node_id: str, raid_config: dict) -> None:
5859
def get_node_traits(self, node_id: str) -> list[str]:
5960
return cast(list[str], self.client.node.get_traits(node_id))
6061

61-
def get_runbook(self, runbook_id: str):
62-
return self.client.node.api.runbook.get(runbook_id)
62+
def get_runbook(self, runbook_name_or_id: str) -> Runbook:
63+
"""Get runbook by name or by UUID.
64+
65+
raises ironicclient.common.apiclient.exceptions.NotFound
66+
"""
67+
runbook = self.client.runbook.get(runbook_name_or_id)
68+
# The above raises an error if there was no such runbook. The following
69+
# is just to make the type checker happy:
70+
if not runbook:
71+
raise ironic_exceptions.NotFound
72+
return runbook
6373

6474
def get_node_inventory(self, node_ident: str) -> dict:
6575
"""Fetch node inventory data from Ironic API.

0 commit comments

Comments
 (0)