Add unit tests for osism/tasks/openstack.py#2459
Open
berendt wants to merge 1 commit into
Open
Conversation
Cover the cloud credential/environment helpers (get_cloud_password, setup_cloud_environment, cleanup_cloud_environment and the module-level get_openstack_connection), the baremetal/NetBox getters including the secret masking in get_baremetal_node_parameters, the thin Celery task wrappers around the OpenStack SDK, and the manager tasks (image_manager, flavor_manager, project_manager/project_manager_sync). All external effects are mocked: the SDK connection comes from a patched osism.utils.get_openstack_connection, the NetBox client replaces the lazy osism.utils.nb attribute, and the environment helpers never touch the real filesystem or working directory because the module-level os/shutil/yaml name bindings (plus builtins.open) are patched. keystoneauth1 and openstacksdk are pinned runtime dependencies, so their real exception classes are raised instead of stand-ins. Assisted-by: Claude:claude-fable-5 Signed-off-by: Christian Berendt <berendt@osism.tech>
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
test_openstack.pymodule is quite large (~1600 lines) and covers many distinct concerns (cloud env, connections, baremetal, NetBox, managers); consider splitting it into multiple test modules (e.g.test_openstack_env.py,test_openstack_baremetal.py,test_openstack_managers.py) to keep individual files easier to navigate and reason about. - The tests reach into
osism.tasks.conductor.utilsforget_vault,deep_decrypt, andmask_secretswhile primarily exercisingosism.tasks.openstack; if possible, isolating the masking behavior behind a smaller interface inopenstackand stubbing that instead would reduce coupling to the conductor implementation details and make the tests more robust to refactors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `test_openstack.py` module is quite large (~1600 lines) and covers many distinct concerns (cloud env, connections, baremetal, NetBox, managers); consider splitting it into multiple test modules (e.g. `test_openstack_env.py`, `test_openstack_baremetal.py`, `test_openstack_managers.py`) to keep individual files easier to navigate and reason about.
- The tests reach into `osism.tasks.conductor.utils` for `get_vault`, `deep_decrypt`, and `mask_secrets` while primarily exercising `osism.tasks.openstack`; if possible, isolating the masking behavior behind a smaller interface in `openstack` and stubbing that instead would reduce coupling to the conductor implementation details and make the tests more robust to refactors.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Summary
Adds
tests/unit/tasks/test_openstack.pywith unit tests for the OpenStack Celery worker module, covering the targets listed in #2356:get_cloud_password(hyphen normalization, key-format guard, whitespace stripping, non-string coercion, loader errors),setup_cloud_environment(password-injection branch incl.clouds.yml/missing-auth/missing-profile variants,secure.yml/secure.yamlfallback branch, error paths),cleanup_cloud_environmentandget_cloud_helpers.get_openstack_connection(cloud, password): allUnauthorized/MissingRequiredOptions/SDKExceptionexit paths for both the password and the secure.yml attempt, the secure.yml retry after a failed password, and thecurrent_projectconnection probe. The realkeystoneauth1/openstacksdkexception classes are raised.get_baremetal_nodes,get_baremetal_node_ports,get_baremetal_node_netbox_info/get_baremetal_nodes_netbox_info(incl.cf_inventory_hostnamefallback), and the secret masking inget_baremetal_node_parameters(value-based masking,ironic_osism_*name-based regex masking after dropped vault decryption,secret_valuesforwarding intomask_secrets).baremetal_node_createattribute injection,wait_for_nodes_provision_statefirst/empty result,set_power_statewait/no-wait, generator materialization,set_target_raid_configmicroversion PUT).image_manager(delegation without configs, temp-dir config rewriting of--imagesarguments, cleanup on error, documentedIndexErrorfor a trailing--images),flavor_manager,project_manager/project_manager_sync, and the task-lock check for all four.Notes
MissingRequiredOptionswithSimpleNamespace(name=...); keystoneauth1 5.15.0 builds the message fromo.dest, so the tests useSimpleNamespace(dest=...).os.path.exists/os.chdirglobally, the tests patch the module-levelos/shutil/yamlname bindings ofosism.tasks.openstack, so no test can touch the real filesystem or working directory.Closes #2356
🤖 Generated with Claude Code