Debian Codegraph @

ansible_collections/community/zabbix/CONTRIBUTING.md

raw
1 # Contribution guidelines
2
3 **Table of contents**
4
5 - [Contribution guidelines](#contribution-guidelines)
6 * [Contributing](#contributing)
7 * [Coding guidelines](#coding-guidelines)
8 + [Zabbix roles](#zabbix-roles)
9 + [Zabbix modules](#zabbix-modules)
10 * [Testing and Development](#testing-and-development)
11 + [Testing Zabbix roles](#testing-zabbix-roles)
12 + [Testing Zabbix modules](#testing-zabbix-modules)
13 - [Additional information](#additional-information)
14 * [Virtualenv](#virtualenv)
15 * [Links](#links)
16
17 Thank you very much for taking time to improve this Ansible collection. We appreciate your every contribution. Please make sure you are familiar with the content presented in this document to avoid any delays during reviews or merge.
18
19 Please note that this project is released with following codes of conduct and by participating in the project you agree to abide by them:
20 * [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md)
21 * [Community Code of Conduct](https://docs.ansible.com/projects/ansible/devel/community/code_of_conduct.html)
22
23 If you are interested in joining us as a maintainer, please open an issue.
24
25 ## Contributing
26
27 1. Fork this repository with community Zabbix collection.
28 2. Create a new branch and apply your changes to it. In addition to that:
29 1. Ensure that any changes you introduce to this collection are reflected in the documentation.
30 2. Ensure that your PR contains valid [changelog fragment](https://docs.ansible.com/projects/ansible/devel/community/development_process.html#changelogs).
31 3. Include tests with your contribution to ensure that future pull requests will not break your functionality.
32 4. Make sure that tests succeed.
33 3. Push the branch to your forked repository.
34 4. Submit a new pull request into this collection.
35
36 *Notes:*
37 * Pull requests that fail during the tests will not be merged. If you have trouble narrowing down cause of a failure and would like some help, do not hesitate to ask for it in comments.
38 * If you plan to propose an extensive feature or breaking change, please open an issue first. This allows collection maintainers to comment on such change in advance and avoid possible rejection of such contribution.
39
40 ## Coding guidelines
41
42 Style guides are important because they ensure consistency in the content, look, and feel of a book or a website. Any contributions to this collection must adhere to the following rules:
43
44 * [Ansible style guide](https://docs.ansible.com/projects/ansible/latest/dev_guide/style_guide/).
45 * Use "Ansible" when referring to the product and ``ansible`` when referring to the command line tool, package and so on.
46
47 ### Zabbix roles
48
49 * Playbooks should be written in multi-line YAML format using ``key: value``.
50 * The form ``key=value`` is suitable for ``ansible`` ad-hoc execution, not for ``ansible-playbook``.
51 * Every task should always have a ``name:`` keyword associated with it.
52
53 ### Zabbix modules
54
55 These rules are required for any contributions proposing a new Zabbix module or updating an existing one. Modules should:
56
57 * Be compatible with [currently supported Zabbix releases](https://www.zabbix.com/life_cycle_and_release_policy).
58 * Include the same set of general options as other Zabbix modules:
59 * In `DOCUMENTATION` block via `extends_documentation_fragment` keyword.
60 * In module `argument_spec` as a set of module parameters.
61 * Implement proper logout mechanism as other modules do.
62 * Comply with [Ansible module best practices](https://docs.ansible.com/projects/ansible/devel/dev_guide/developing_modules_best_practices.html).
63
64 ## Testing and Development
65
66 It is recommended to use Docker for the testing as this repository is utilizing it for its own CI. Read [Docker installation guide](https://docs.docker.com/install/) for more information.
67
68 Make sure you start your work on the current state of the repository with `main` branch up to date. The best way to both try new changes and run shipped tests is by cloning the repository to Ansible project:
69
70 ```bash
71 cd <ANSIBLE-PROJECT>/
72 mkdir -p collections/ansible_collections/community
73 git clone [email protected]:<USERNAME>/community.zabbix.git collections/ansible_collections/community/zabbix
74 ```
75
76 Functionality can be verified by looking at the documentation of a module:
77 ```bash
78 ansible-doc community.zabbix.zabbix_host
79 ```
80
81 Once this is done, you can reference modules and roles from testing playbook likes this:
82
83 ```yaml
84 - hosts: myserver
85 roles:
86 - role: community.zabbix.zabbix_agent
87 zabbix_agent_server: 10.0.0.1
88 ...
89
90 tasks:
91 - name: Configure Zabbix host
92 community.zabbix.zabbix_host:
93 server_url: http://10.0.0.1/
94 ...
95 delegate_to: localhost
96 ```
97
98 ### Testing Zabbix roles
99
100 *This section is subject to change as our CI regarding roles is being reworked and may not work for you right now!*
101
102 Roles make use of [Molecule](https://docs.ansible.com/projects/molecule/) to verify and test the execution of each role. In order to start testing with Molecule, you need to install the required dependencies. Requirements file can be found in the root of the [dj-wasabi/ansible-ci-base](https://github.com/dj-wasabi/ansible-ci-base) repository.
103
104 It is recommended to create a [new Python virtual environment](#virtualenv) for this to not clutter your global Python installation. First, install the dependencies:
105
106 ```bash
107 pip install -r requirements.txt
108 ```
109
110 Note that Docker is required when testing roles as Molecule is configured to use it. Once everything is installed, validate your role changes with:
111
112 ```bash
113 molecule test
114 ```
115
116 ### Testing Zabbix modules
117
118 Modules are tested via `ansible-test` command. Configurations for integration and sanity tests for the command are contained within `tests` directory. Refer to the [official documentation](https://docs.ansible.com/projects/ansible/latest/dev_guide/testing_integration.html) for introduction to module integration testing within Ansible. Please note that this may fail if you get your directory structure wrong. If this happens, please see the start of [Testing and Development](#testing-and-development) regarding the placement of the collection.
119
120 Running test suites locally requires a few dependencies to be installed. Same as for the roles, it is recommended to use [Python virtual environment](#virtualenv):
121
122 ```bash
123 pip install docker-compose
124 ```
125
126 Integration test suite for modules can be run with the commands below:
127
128 ```bash
129 export zabbix_version=X.Y
130 docker-compose up -d
131 ansible-test integration -v --color --continue-on-error --diff [test_zabbix_xyz]
132 docker-compose down
133 ```
134 *Notes*:
135 * `zabbix_version=X.Y` will be expanded to Docker image `ubuntu-X.Y-latest`
136 * Details for both variables and values that are in use can be read from [ansible-test.yml](.github/workflows/ansible-test.yml).
137
138 Sanity test suite for the modules can be run with the commands:
139
140 ```bash
141 ansible-test sanity -v --color --docker --python 3.6
142 ```
143
144 # Additional information
145
146 ## Virtualenv
147
148 It is recommended to use virtualenv for development and testing work to prevent any conflicting dependencies with other projects.
149
150 A few resources describing virtualenvs:
151
152 * http://thepythonguru.com/python-virtualenv-guide/
153 * https://realpython.com/python-virtual-environments-a-primer/
154 * https://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
155
156 ## Links
157
158 * [Ansible](https://www.ansible.com/)
159 * [Ansible style guide](https://docs.ansible.com/projects/ansible/latest/dev_guide/style_guide/)
160 * [Ansible module best practices](https://docs.ansible.com/projects/ansible/devel/dev_guide/developing_modules_best_practices.html)
161 * [Integration testing with `ansible-test`](https://docs.ansible.com/projects/ansible/latest/dev_guide/testing_integration.html)
162 * [Docker installation guide](https://docs.docker.com/install/)
163 * [Molecule](https://docs.ansible.com/projects/molecule/)
164 * [Molecule V2 with your own role](https://werner-dijkerman.nl/2017/09/05/using-molecule-v2-to-test-ansible-roles/)
165 * [dj-wasabi/ansible-ci-base](https://github.com/dj-wasabi/ansible-ci-base)
166 * [Current Zabbix releases](https://www.zabbix.com/life_cycle_and_release_policy)
167
168 **End note**: Have fun making changes. If a feature helps you, others may find it useful as well and we will be happy to merge it.