Debian Codegraph @

ansible_collections/community/proxmox/CONTRIBUTING.md

raw
1 <!--
2 Copyright (c) Ansible Project
3 GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 SPDX-License-Identifier: GPL-3.0-or-later
5 -->
6
7 # Contributing
8
9 We follow [Ansible Code of Conduct](https://docs.ansible.com/projects/ansible/latest/community/code_of_conduct.html)
10 in all our contributions and interactions within this repository. If you are stuck while developing a
11 module, refer to our [recommended reads](#helpful-documentation) from the Ansible docs.
12
13 ## AI Contributions
14 We are not opposed to merging AI-generated code, so if you're using an AI agent to help you write code or tests, please feel free to do so.
15
16 However, please keep the following things in mind:
17
18 * Mention that you've used AI, either by having the AI as a co-contributor on your PR or mentioning it directly in the text.
19 * Verify that whatever your AI does is sensible.
20 * Try to keep the changes organized, remember, we're all volunteers and we don't have time to review huge PRs full of hallucinated nonsense.
21 * Ensure, that you yourself understand the code and its logic. In the end, the contents of your PR are your responsibility.
22
23 ## Issue tracker
24
25 Whether you are looking for an opportunity to contribute or you found a bug and already know how to
26 solve it, please go to the [issue tracker](https://github.com/ansible-collections/community.proxmox/issues).
27 There you can find feature ideas to implement, reports about bugs to solve, or submit an issue to
28 discuss your idea before implementing it which can help choose a right direction at the beginning of
29 your work and potentially save a lot of time and effort.
30 Also somebody may already have started discussing or working on implementing the same or a similar idea,
31 so you can cooperate to create a better solution together.
32 <!-- We currently do not maintain these tags
33 * If you are interested in starting with an easy issue, look for [issues with an `easyfix` label](https://github.com/ansible-collections/community.proxmox/labels/easyfix).
34 * Often issues that are waiting for contributors to pick up have [the `waiting_on_contributor` label](https://github.com/ansible-collections/community.proxmox/labels/waiting_on_contributor).
35 -->
36
37 ## Review pull requests
38
39 Look through currently [open pull requests](https://github.com/ansible-collections/community.proxmox/pulls).
40
41 You can help by reviewing and testing them, since this collection currently lacks integration tests.
42 Reviews and tests help us estimate the maturity of a pull request and increase the likelihood to merge its contents.
43 Note that reviewing does not only mean code review, but also offering comments on new interfaces added to existing plugins/modules,
44 interfaces of new plugins/modules, improving language (not everyone is a native English speaker), or testing bugfixes and new features!
45
46 Also, consider taking up a valuable, reviewed, but abandoned pull request which you could politely ask the original authors to complete yourself.
47
48 If you want to test a PR locally, refer to [our testing guide](https://docs.ansible.com/projects/ansible/devel/community/collection_contributors/collection_test_pr_locally.html) for instructions on how do it quickly.
49
50 If you find any inconsistencies or places in this document which can be improved, feel free to raise an issue or pull request to fix it.
51
52 ## Opening pull requests
53 Wether you found a bug and want to fix it or you want to contribute a new module,
54 please refer to these conventions:
55 * Try committing your changes with an informative but short commit message.
56 * Make sure your PR includes a [changelog fragment](https://docs.ansible.com/projects/ansible/devel/community/collection_development_process.html#creating-a-changelog-fragment).
57 * You must not include a fragment for new modules or new plugins. Also you shouldn't include one for docs-only changes.
58 * Please always include a link to the pull request itself, and if the PR is about an issue, also a link to the issue. Also make sure the fragment ends with a period, and begins with a lower-case letter after `-`. (Again, if you don't do this, we'll add suggestions to fix it, so don't worry too much :) )
59 * Note that we lint and format the code with `ruff`.
60 If your change does not match the expectations, CI will fail and your PR will not get merged.
61 Continue reading this guide to find out how to lint and format your code.
62
63 You can also read the Ansible community's [Quick-start development guide](https://docs.ansible.com/projects/ansible/devel/community/create_pr_quick_start.html).
64
65 ### New modules or plugins
66
67 Creating new modules and plugins requires a bit more work than other Pull Requests.
68
69 1. Please make sure that your new module or plugin is not already part of this collection.
70 If it is already partly adressed, you might want to add the functionality there or discuss refactoring the functions in an issue.
71
72 2. Please do not add more than one plugin/module in one PR, unless they are closely releated.
73 That makes it easier for reviewers, and increases the chance that your PR will get merged. If you plan to contribute a group
74 of plugins/modules (say, more than a module and a corresponding `_info` module), please mention that in the first PR.
75
76 3. When creating a new module or plugin, please make sure that you follow various guidelines:
77
78 - Follow [development conventions](https://docs.ansible.com/projects/ansible/devel/dev_guide/developing_modules_best_practices.html);
79 - Follow [documentation standards](https://docs.ansible.com/projects/ansible/devel/dev_guide/developing_modules_documenting.html) and
80 the [Ansible style guide](https://docs.ansible.com/projects/ansible/devel/dev_guide/style_guide/index.html#style-guide);
81 - Make sure your modules and plugins are [GPL-3.0-or-later](https://www.gnu.org/licenses/gpl-3.0-standalone.html) licensed
82 (new module_utils can also be [BSD-2-clause](https://opensource.org/licenses/BSD-2-Clause) licensed);
83 - Make sure that new plugins and modules have unit tests.
84
85 ## Formatting, linting and tests
86 We use `ruff` to maintain a baseline of code readability and quality.
87 Please check out our [ruff configuration](./ruff.toml) to find out which formatting and rules are enforced.
88
89 To perform basic testing, you will most likely require the following packages:
90 - `antsibull-nox`
91 - `nox`
92 - `ruff`
93 - `ansible`
94 - `pre-commit` (optional)
95
96 and ideally a container runtime, for example `podman` or `docker`.
97
98 The repository includes a [pre-commit](https://pre-commit.com/) configuration ([`.pre-commit-config.yaml`](.pre-commit-config.yaml)) which runs basic Ruff checks before each commit. **Hooks are not active until you install them**. After installing the `pre-commit` package, run `pre-commit install`.
99 If you want to manually run the hooks before making a commit, you can use `pre-commit run`.
100
101 To immediately run all default tests (format, lint), install the dependencies
102 and run `nox`. To run all unit/sanity tests, use `nox -s ansible-test-units` or `nox -s ansible-test-sanity`.
103
104 ### Codequality
105
106 The following commands show how to lint and format your code with nox:
107
108 ```.bash
109 # Run all configured formatters:
110 nox -Re formatters
111
112 # Lint:
113 nox -Re codeqa
114
115 # If you notice discrepancies between your local formatter and CI, you might
116 # need to re-generate the virtual environment:
117 nox -e formatters
118 ```
119
120 While antsibull-nox and nox enable you to run the whole suite of tests, you may
121 use `ruff format` and `ruff check` immediately within your development environment to perform basic linting and formatting.
122 Note that while our CI is aware of changed files, your environment may not be. Thus, ruff errors,
123 which might stem for other files, will not fail the tests of your contribution and can be ignored.
124
125 ### Sanity tests
126
127 The following commands show how to run ansible-test sanity tests:
128
129 ```.bash
130 # Run basic sanity tests for all files in the collection:
131 nox -Re ansible-test-sanity-devel
132
133 # Run basic sanity tests for the given files and directories:
134 nox -Re ansible-test-sanity-devel -- plugins/modules/proxmox_pool.py tests/integration/targets/proxmox_pool/
135
136 # Run all other sanity tests for all files in the collection:
137 nox -R
138 ```
139
140 ### Unit tests
141
142 The following commands show how to run unit tests:
143
144 ```.bash
145 # Run all unit tests:
146 nox -Re ansible-test-units-devel
147
148 # Run all unit tests for one Python version (a lot faster):
149 nox -Re ansible-test-units-devel -- --python 3.13
150
151 # Run a specific unit test for one Python version:
152 nox -Re ansible-test-units-devel -- --python 3.13 tests/unit/plugins/modules/test_proxmox_kvm.py
153 ```
154
155 ### Integration tests
156
157 Most Proxmox module integration tests require access to a real Proxmox environment and are marked as `unsupported` in CI. This means they are skipped during automated testing and must be executed manually in a properly configured environment.
158
159 **Warning:** Integration tests may create, modify, or delete resources on your Proxmox environment. It is strongly recommended to use a dedicated test environment.
160
161 #### Setup
162
163 1. Create your local configuration file:
164
165 ```bash
166 cp tests/integration/integration_config.yml.template tests/integration/integration_config.yml
167 ```
168
169 2. Adjust the authentication variables to match your Proxmox environment. A minimal example configuration may look like:
170
171 ```yaml
172 proxmox_host: https://your-proxmox:8006
173 proxmox_user: root@pam
174 proxmox_password: your-password
175 validate_certs: false
176 ```
177
178 Some modules require the `root@pam` user due to permission constraints.
179
180 #### Running tests
181
182 You can run integration tests using `ansible-test`:
183
184 ```bash
185 # Run all integration tests
186 ansible-test integration -v --allow-unsupported
187
188 # Run all integration tests using Docker
189 ansible-test integration --docker -v --allow-unsupported
190
191 # Run a specific test target
192 ansible-test integration proxmox_pool -v --allow-unsupported
193
194 # Run a specific test target using Docker
195 ansible-test integration proxmox_pool --docker -v --allow-unsupported
196 ```
197
198 ### Manual test and review of changes
199 If you want to test your new module or bugfix within a playbook, you may do the following:
200 - Ensure your repository resides, for example, in `exampledir/community/proxmox`.
201 - Set up Ansible to find your collection `export ANSIBLE_COLLECTIONS_PATH="$HOME/exampledir"`.
202 Alternatively, you may edit your [ansible.cfg](https://docs.ansible.com/projects/ansible/latest/reference_appendices/config.html#collections-paths).
203 - Verify, that your modified collection is found: `ansible-galaxy collection list`
204
205 Now you can use your custom code in playbooks and roles.
206 And you can use `ansible-doc` to review your rendered documentation.
207
208
209
210 ## Helpful Documentation
211 Unless you already read it up above, you probably really shoudl check out these links:
212 - Development:
213 - [Module architecture](https://docs.ansible.com/projects/ansible/latest/dev_guide/developing_program_flow_modules.html) (also contains the module options).
214 - [Best practises](https://docs.ansible.com/projects/ansible/devel/dev_guide/developing_modules_best_practices.html).
215 - [Creating changelog fragments](https://docs.ansible.com/projects/ansible/devel/community/collection_development_process.html#creating-a-changelog-fragment).
216 - Documentation
217 - [Ansible Module parts and blocks](https://docs.ansible.com/projects/ansible/devel/dev_guide/developing_modules_documenting.html).
218 - [Style Guide](https://docs.ansible.com/projects/ansible/devel/dev_guide/style_guide/index.html#style-guide), and the subsequent
219 [voice style](https://docs.ansible.com/projects/ansible/devel/dev_guide/style_guide/voice_style.html), [grammar](https://docs.ansible.com/projects/ansible/devel/dev_guide/style_guide/grammar_punctuation.html)
220 and [spelling](https://docs.ansible.com/projects/ansible/devel/dev_guide/style_guide/spelling_word_choice.html).
221 - [Ansible Markup for documentation yaml](https://docs.ansible.com/projects/ansible/latest/dev_guide/ansible_markup.html).
222
223 <!-- todo
224 ## Devcontainer
225
226 Since community.general 12.2.0, the project repository supports [devcontainers](https://containers.dev/). In short, it is a standard mechanism to
227 create a container that is then used during the development cycle. Many tools are pre-installed in the container and will be already available
228 to you as a developer. A number of different IDEs support that configuration, the most prominent ones being VSCode and PyCharm.
229
230 See the files under [.devcontainer](.devcontainer) for details on what is deployed inside that container.
231
232 Beware of:
233
234 - By default, the devcontainer installs the latest version of `ansible-core`.
235 When testing your changes locally, keep in mind that the collection must support older versions of
236 `ansible-core` and, depending on what is being tested, results may vary.
237 - Integration tests executed directly inside the devcontainer without isolation (see above) may fail if
238 they expected to be run in full fledged VMs. On the other hand, the devcontainer setup allows running
239 containers inside the container (the `docker-in-docker` feature).
240 - The devcontainer is built with a directory structure such that
241 `.../ansible_collections/community/general` contains the project repository, so `ansible-test` and
242 other standard tools should work without any additional setup
243 - By default, the devcontainer installs `pre-commit` and configures it to perform `ruff check` and
244 `ruff format` on the Python files, prior to commiting. That configuration is going to be used by
245 `git` even outside the devcontainer. To prevent errors, you have to either install `pre-commit` in
246 your computer, outside the devcontainer, or run `pre-commit uninstall` from within the devcontainer
247 before quitting it.
248 -->