Skip to content

fix: fix modules validation and tests #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged

fix: fix modules validation and tests #62

merged 1 commit into from
May 19, 2025

Conversation

Gnoale
Copy link
Contributor

@Gnoale Gnoale commented May 5, 2025

Summary

Most of modules are broken for various reasons:

  • wrong arguments passed to the underlying SDK methods
  • overlapping arguments with scaleway client (project_id)
  • no tests
  • SDK versions bump that did not got catch here (the plugins are 2yo)

This is a first pass on the secret modules to define boilerplate code for unit testing and fix it

Goals

  • Write units test with monkey patching the different API calls to validate arguments and logic

  • Refactor the plugins/module_utils/scaleway.py => simplify and build the scaleway client directly from the Python SDK Client instantiation logic (get rid oif arguments overlapping issues)

Test, run

  • One can run the integration tests with

ansible-test integration --start-at scaleway_secret --requirements

  • Running a playbook with environment variables
---
- hosts: localhost
  tasks:
    - name: Create a secret
      scaleway.scaleway.scaleway_secret:
        #project_id: "6867048b-fe12-4e96-835e-41c79a39604b"
        name: "test-secret"
        protected: false
        state: present
      vars:
        ansible_python_interpreter: .venv/bin/python

SCW_PROFILE=owner SCW_DEFAULT_REGION=fr-par SCW_CONFIG_PATH="/Users/gnoale/git/scaleway/scaleway-cli/my_cfg.yml" ansible-playbook playbook.yaml

  • units

there are a few caveat

ansible-test units uses pytest and a special module pytest-xdist
For Macos user you need this environment variable export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
and pip install pytest-xdist

Using a local virtual env as always !

ansible-test units --python-interpreter .venv/bin/python

Next

  • fix all the remaining module by writing units and integration tests
  • argument validation could be improved, maybe consider using Pydantic at one point
    ...

Caveat

ansible-test sanity ignore completely the python path argument when it fires, so this explain in part all the

try 
  import scaleway
except ImportError
...

And the typing trick is to wrap "Client" type in quotes in func signatures

Otherwise, it try importing modules as relative and return these kind of validation errors "Exception attempting to import module for argument_spec introspection, 'name 'Client' is not defined'"

@Gnoale Gnoale force-pushed the fix-project-ids branch 6 times, most recently from a5c15ec to c82a9e1 Compare May 7, 2025 15:02
@Gnoale Gnoale force-pushed the fix-project-ids branch from 48f1c91 to 26003a0 Compare May 13, 2025 13:47
@Gnoale Gnoale marked this pull request as ready for review May 13, 2025 16:22
@Gnoale Gnoale requested a review from remyleone as a code owner May 13, 2025 16:22
@Gnoale Gnoale force-pushed the fix-project-ids branch 2 times, most recently from fcf1060 to 8bf004e Compare May 13, 2025 16:58
@Gnoale Gnoale force-pushed the fix-project-ids branch 2 times, most recently from f047939 to 6f83923 Compare May 13, 2025 23:26
@Gnoale Gnoale force-pushed the fix-project-ids branch 6 times, most recently from 08e6b27 to d99c100 Compare May 15, 2025 16:33
* use the scaleway client sdk to instantiate the client

* remove overlapping arguments from scaleway client inside plugins

* do not ansible-lint .github folder

* write scaleway_secret integration tests

* CI test secret
@Gnoale Gnoale force-pushed the fix-project-ids branch from 469d16c to 808ea32 Compare May 16, 2025 10:01
@remyleone remyleone changed the title Fix modules validation and tests fix: fix modules validation and tests May 19, 2025
@remyleone remyleone enabled auto-merge May 19, 2025 08:45
@remyleone remyleone added this pull request to the merge queue May 19, 2025
Merged via the queue into main with commit 57318fb May 19, 2025
10 checks passed
@remyleone remyleone deleted the fix-project-ids branch May 19, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants