Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions osism/commands/baremetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def take_action(self, parsed_args):
for b in baremetal:
row = [
b["name"],
b["id"],
b["power_state"] if b["power_state"] is not None else "n/a",
b["provision_state"],
b["maintenance"],
Expand All @@ -94,6 +95,7 @@ def take_action(self, parsed_args):

headers = [
"Name",
"UUID",
"Power State",
"Provision State",
"Maintenance",
Expand All @@ -104,8 +106,8 @@ def take_action(self, parsed_args):

for row in result:
info = get_baremetal_node_netbox_info(row[0])
row.insert(1, info.get("device_role") or "N/A")
headers.insert(1, "Device Role")
row.insert(2, info.get("device_role") or "N/A")
headers.insert(2, "Device Role")

print(
tabulate(
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/commands/test_baremetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ def test_node_not_found_returns_1(cls):
assert _run_not_found(cls) == 1


# --- BaremetalList output ---


def test_list_includes_uuid_column(capsys):
# The node UUID must be shown so it can be cross-referenced with Ironic logs.
cmd = baremetal.BaremetalList(MagicMock(), MagicMock())
parsed_args = cmd.get_parser("test").parse_args([])

node = {
"name": "node1",
"id": "11111111-2222-3333-4444-555555555555",
"power_state": "power on",
"provision_state": "active",
"maintenance": False,
}
conn = MagicMock()
conn.baremetal.nodes.return_value = [node]

setup = MagicMock(return_value=("pw", [], None, True))
getconn = MagicMock(return_value=conn)
cleanup = MagicMock()
with patch(
"osism.tasks.openstack.get_cloud_helpers",
return_value=(setup, getconn, cleanup),
):
cmd.take_action(parsed_args)

out = capsys.readouterr().out
assert "UUID" in out
assert node["id"] in out


# --- BaremetalDump failure paths ---


Expand Down