7.6 KiB
Contributing to the Podman Ansible Collection
First off, thank you for considering contributing to this collection! We welcome any help, from reporting a bug to submitting a new feature. Every contribution is valuable.
This document provides guidelines to help you get started. Please read it carefully to ensure a smooth and effective contribution process.
Code of Conduct
All contributors are expected to follow our Code of Conduct. Please make sure you are familiar with its contents.
How to Contribute
You can contribute in several ways:
- Reporting Bugs: If you find a bug, please open an issue and provide as much detail as possible, including your Podman version, Ansible version, the playbook you are using, and the full error output.
- Suggesting Enhancements: If you have an idea for a new feature or an improvement to an existing one, please open a feature request.
- Submitting Pull Requests: If you want to fix a bug or add a feature yourself, please follow the guidelines below.
Development Setup
-
Fork and Clone: Fork the repository on GitHub and clone your fork locally.
git clone https://github.com/YOUR-USERNAME/ansible-podman-collections.git cd ansible-podman-collections -
Set up a Virtual Environment: It's highly recommended to work in a Python virtual environment.
python3 -m venv venv source venv/bin/activate -
Install Dependencies: The collection's testing dependencies are listed in
test-requirements.txt.pip install -r test-requirements.txt
Guidelines for Pull Requests
General Workflow
- Create a new branch for your changes:
git checkout -b my-feature-or-fix. - Make your changes. Follow the coding and testing guidelines below.
- Commit your changes with a clear and descriptive message. See existing commit messages for style (
git log --oneline). - Push your branch to your fork:
git push origin my-feature-or-fix. - Open a pull request against the
mainbranch of the original repository.
Fixing a Bug
- If an issue for the bug doesn't already exist, please create one.
- Ideally, add an integration test case to
tests/integration/targets/that reproduces the bug and fails before your fix. - Implement the code change that fixes the bug.
- Run the tests to ensure your fix works and doesn't break anything else.
- In your PR description, use the "Fixes #123" syntax to link it to the issue.
Adding a New Module
We have a script to help you scaffold a new module.
- Define Module Variables: Copy
contrib/my_module_template_vars.yamland customize it with your new module's details (name, author, options, etc.). - Generate the Module: Run the
contrib/generate_module.shscript. This will create a new module file in thecontribdirectory. - Place the Module: Move the generated file into
plugins/modules/. - Add Logic: Implement the core logic for your module. If you need to share code with other modules, consider adding it to
plugins/module_utils/. - Document: Ensure the
DOCUMENTATION,EXAMPLES, andRETURNsections are thorough and accurate. This is critical for users. - Add Tests: Create a new integration test role and a new CI workflow for your module (see below).
Testing Strategy
This collection uses three types of tests. All tests must pass before a PR can be merged.
1. Sanity Tests
These tests check for code style, syntax errors, and other common issues. Sanity tests must pass in pull requests in opder to merge.
-
How to Run:
bash contrib/ansible-lint.sh -
Guidelines:
- This will install collection in
/tmpdirectory and runansible-testsanity in docker. - The maximum line length is 120 characters.
- This will install collection in
2. Unit Tests
Unit tests are for testing specific functions in isolation, often by mocking external dependencies. This is an area we are actively working to improve.
-
Location:
tests/unit/plugins/modules/ -
How to Run:
bash contrib/ansible-unit.sh -
Guidelines:
- This will install collection in
/tmpdirectory and runansible-testunit tests.
- This will install collection in
3. Integration Tests
These are the most important tests in the collection. They run Ansible playbooks to test modules against a live Podman instance.
-
Location:
tests/integration/targets/ -
Structure: Each subdirectory in
targetsis an Ansible role that tests a specific module or feature. The main logic is intasks/main.yml. -
Adding a New Integration Test:
-
Create a new directory (role) for your module:
tests/integration/targets/my_new_module/tasks. -
Create a
main.ymlfile inside that directory. -
Write Ansible tasks that execute your module and verify its behavior. Use the
assertorfailmodules to check for expected outcomes.- name: Run my_new_module my_new_module: name: test_container state: present register: result - name: Assert that the container was created assert: that: - result.changed - result.container.State.Status == "running"
-
-
Running Locally: You can run a specific test role using
ansible-playbook. This requires a working Podman installation. -
Create a testing playbook with your tests like:
- hosts: all gather_facts: false tasks: - include_tasks: tests/integration/targets/my_new_module/tasks/main.ymlInstall the collection version you develop with:
ansible-galaxy collection install -vvv --force .and then run the playbook it with:
ansible-playbook -vv -i localhost, my_playbook.yml
Continuous Integration (CI)
We use GitHub Actions to run all our tests automatically.
Adding a CI Job for a New Module
To ensure your new module is tested on every PR, you must add a new workflow file. We use a reusable workflow to make this easy.
-
Go to the
.github/workflows/directory. -
Create a new file named after your module, e.g.,
podman_my_new_module.yml. -
Copy the content from an existing module workflow, like
podman_export.yml, and adapt it. You only need to change a few lines:name: Podman my_new_module on: push: paths: - 'plugins/modules/podman_my_new_module.py' - 'tests/integration/targets/podman_my_new_module/**' pull_request: paths: - 'plugins/modules/podman_my_new_module.py' - 'tests/integration/targets/podman_my_new_module/**' jobs: test: uses: ./.github/workflows/reusable-module-test.yml with: module_name: podman_my_new_module # The name of your test role display_name: "Podman my_new_module" # A friendly name for the job -
Commit this new workflow file along with your module and test code.
Final Checklist for Pull Requests
Before you submit your PR, please make sure you have:
- Read this
CONTRIBUTING.mdguide. - Added or updated tests for your changes.
- Run
ansible-test sanityand fixed any issues. - Ensured all CI checks are passing on your PR.
- Updated the
DOCUMENTATIONblock in the module if you changed any parameters.
Thank you for your contribution!