Add unit tests for conductor ironic sync orchestrators#2367
Open
berendt wants to merge 2 commits into
Open
Conversation
Cover the four sync entry points in osism/tasks/conductor/ironic.py in a new tests/unit/tasks/conductor/test_ironic_sync.py, focusing on state transitions and branch coverage rather than exact task-output strings: - _sync_ironic_device: node creation and update paths, driver password popping, target_raid_config handling, port reconciliation (case-insensitive MAC match, create and delete) and the full validation/provisioning state machine (enroll, clean failed, power off, boot-validation demotion, adoption from manageable/available, and the normal manage->provide->available transition). - _sync_ironic_device_dry_run: secret-value collection and masking, the create branch (adopt vs available messages) and the update branch (update vs no-update, port reconciliation, provision_state reporting). - sync_ironic: NetBox/Ironic reachability, node-name filtering, dry-run path, locking (acquire, release-on-error, lock contention), stale-node cleanup (delete, dry-run, clean-failed, ineligible) and kernel-parameter/ports propagation. - sync_netbox_from_ironic: filtered and unfiltered NetBox selection, primary/secondary reachability, node sync with reachable secondaries and failed-device reporting. Tests follow the existing mocker + SimpleNamespace conventions and patch the module-level imports (osism_utils, openstack, netbox, deep_compare, mask_secrets). Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Christian Berendt <berendt@osism.tech>
68bf6a7 to
809aad6
Compare
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new test module is quite large (~950 lines); consider splitting it into smaller files or grouping related tests into classes (e.g. per orchestrator) to keep each unit more focused and easier to navigate.
- There is some repeated setup logic for
openstack.baremetal_node_showandbaremetal_node_validatein multiple tests; extracting additional fixtures or helper functions for common scenarios (e.g. 'manageable node with valid validation', 'available node with boot failure') would reduce duplication and make the intent of each test clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new test module is quite large (~950 lines); consider splitting it into smaller files or grouping related tests into classes (e.g. per orchestrator) to keep each unit more focused and easier to navigate.
- There is some repeated setup logic for `openstack.baremetal_node_show` and `baremetal_node_validate` in multiple tests; extracting additional fixtures or helper functions for common scenarios (e.g. 'manageable node with valid validation', 'available node with boot failure') would reduce duplication and make the intent of each test clearer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
sync_ironic collects NetBox devices in a set, but the tests built device stand-ins as types.SimpleNamespace, which defines __eq__ without __hash__ and is therefore unhashable. Replace it with a plain class so instances use the default identity hash, matching real pynetbox objects. Assisted-by: Claude:claude-fable-5 Signed-off-by: Christian Berendt <berendt@osism.tech>
aa15de1 to
ecd456b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #2227.
Adds
tests/unit/tasks/conductor/test_ironic_sync.pycovering the foursync orchestrators in
osism/tasks/conductor/ironic.py. Tests focus onstate transitions and branch coverage, asserting on
push_task_outputsubstrings rather than exact strings, as the issue requests.
What the single commit adds
A new test module organised into four clearly-labelled sections, one per
target function. It patches the module-level imports
(
osism_utils,openstack,netbox,deep_compare,mask_secrets,_matches_netbox_filter,_prepare_node_attributes,_sync_ironic_device,_sync_ironic_device_dry_run) following theexisting
mocker+SimpleNamespaceconventions used in the siblingtest_netbox.py/test_config.py._sync_ironic_device(ironic.py:354)automated_clean=False;target_raid_configapplied viabaremetal_node_set_target_raid_config;a
(False, "error")result raises an exception mentioningtarget_raid_config.deep_comparepopulatesnode_updates→ update withfull
node_attributes; the driver password key (resolved viadriver_params[driver]["password"]) is popped, and a password-onlydelta drops
driver_infoso no update happens unlessforce=True.comparison is case-insensitive.
enroll/clean failedmove tomanageable; power is forced off;boot-validation failure on
availabledemotes tomanageable;adoption from
manageableand fromavailable; the normalmanage→provide→availablepath including theautomated_cleantoggles;
set_boot_devicefailure is caught;is_adoptionderivesfrom the
provision_state == "active"custom field._sync_ironic_device_dry_run(ironic.py:570)password/secret/ironic_osism_*string keys and passed to
mask_secrets(call args verified;non-strings and unrelated keys ignored).
activeimplying adopt) andupdate branch (update vs. no-update-needed, port create/delete,
current
provision_statereported).sync_ironic(ironic.py:681)finish_task_output(rc=1);node_namenot found; dry-run path; lock acquired (device synced and released in
finally, even on exception) and lock contention; stale-node cleanup(delete, dry-run "Would delete",
clean failed→manageablefirst,ineligible "Cannot remove");
skip/extra_kernel_paramspropagation;ports_attributesfiltering byenabled and not mgmt_only and mac_address.sync_netbox_from_ironic(ironic.py:877)unreachable) and unfiltered selection (primary unreachable, all/one
secondary reachable, no secondaries message); node-name not found;
set_*called withsecondary_nb_list=reachable_secondaries;failed-device reporting; Ironic unreachable.
Verification
black --checkandflake8pass on the new file.pytestwas not run in this local environment per my standingworkflow preference of letting CI run the suite; the Zuul
python-osism-unit-testsjob is the verification gate for this draft.Notes
is touched.
exceptbranches andmessage-only push paths is intentionally left lower.
Assisted-by: Claude:claude-opus-4-8