Skip to content

Add unit tests for hardware CLI commands#2486

Open
berendt wants to merge 1 commit into
mainfrom
unit-tests-hardware-commands
Open

Add unit tests for hardware CLI commands#2486
berendt wants to merge 1 commit into
mainfrom
unit-tests-hardware-commands

Conversation

@berendt

@berendt berendt commented Jul 18, 2026

Copy link
Copy Markdown
Member

Closes #2364

Adds unit tests for the hardware-related CLI command modules, following the mocking patterns established in #2193 (no Celery broker, no real cloud/NetBox access):

New test modules

  • tests/unit/commands/test_redfish.py: column name normalization, per-resource-type column mappings, column filtering (case-insensitive selection, unknown-column warning), JSON data filtering, table rendering, and all take_action output paths (JSON full/filtered/empty, table dispatch per resource type, unknown resource type, no result). Verifies the task lock is consulted before the Celery task is dispatched.
  • tests/unit/commands/test_stress.py: default command construction of the openstack-simple-stress wrapper, boolean flag and custom value propagation, return code passthrough, FileNotFoundError/generic error handling, setup failure guard, and cleanup in all paths.

Extended test modules

  • tests/unit/commands/test_baremetal.py: _apply_metalbox_vars, a parametrized cloud-setup failure guard over all commands of the module, BaremetalList (sorting, n/a power state, query flags, NetBox device-role column, cleanup on error), BaremetalDeploy (provision-state decision matrix, instance_info refresh, validation failure, NetBox local_context_data incl. cf_inventory_hostname fallback, netplan/FRR parameters, Supermicro boot device, RAID deploy steps, config-drive failure, --all loop resilience — playbook content is asserted by parsing the actual playbook.yml handed to configdrive.pack), BaremetalDump (Ironic and NetBox sources), BaremetalUndeploy (state matrix, SSH known_hosts cleanup), BaremetalPing (_ping_host output parsing incl. macOS/Linux variants, device discovery/filtering, summary), BaremetalBurnIn (clean/service step construction, manage flow, active-node confirmation), BaremetalClean (RAID step prepending, manage flow), the provide/maintenance/power wrappers, and BaremetalDelete (port-before-node ordering, NetBox state clearing on primary and secondary instances, failure resilience).
  • tests/unit/commands/test_server.py: ServerMigrate (defaults, --target/--force, prompt handling, wait loop, --no-wait, PAUSED), ServerList (domain/project/user happy paths, domain-name fallback, age-based BUILD/ERROR reporting), and ServerClean (build timeout handling, prompt handling, ERROR servers, cleanup in finally).

No existing test cases were duplicated; flake8 and black pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MRk7qVcmoKuk74USmgY8Mm

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @berendt, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Cover the hardware-related command modules with focused unit tests:

- baremetal: provision-state decision matrix and config-drive assembly
  of BaremetalDeploy, playbook generation of BaremetalDump (Ironic and
  NetBox sources), undeploy state handling including SSH known_hosts
  cleanup, ping output parsing and device discovery, burn-in and clean
  step construction, the provide/maintenance/power wrappers, NetBox
  state clearing on delete, and the shared cloud-setup failure guard
- server: live-migration flow including prompt handling and wait loop,
  the domain/project/user listing paths, age-based reporting of stuck
  servers, and ServerClean deletion behavior
- redfish: new test module for the column mapping and filtering helpers
  and the table/JSON output paths of the list command
- stress: new test module for command construction, flag propagation
  and error handling of the openstack-simple-stress wrapper

Assisted-by: Claude:claude-fable-5
Signed-off-by: Christian Berendt <berendt@osism.tech>
@berendt
berendt force-pushed the unit-tests-hardware-commands branch from 3c17b73 to d1df374 Compare July 18, 2026 11:57
@berendt berendt moved this from New to In progress in Human Board Jul 18, 2026
@berendt berendt moved this from In progress to Ready for review in Human Board Jul 18, 2026
@berendt
berendt requested a review from ideaship July 18, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Unit tests for osism/commands/ — hardware (baremetal, redfish, server, stress)

2 participants