-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reproducible setup for development and testing
Added: - venv setup with required dependencies - molecule setup with docker to simplify testing - makefile with commonly used tooling Signed-off-by: Zakhar Bessarab <[email protected]>
- Loading branch information
Showing
14 changed files
with
280 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
.vagrant | ||
.vscode | ||
.venv |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
init-venv: | ||
python3 -m venv .venv | ||
. .venv/bin/activate && pip install -r requirements.txt | ||
|
||
venv: | ||
. .venv/bin/activate | ||
|
||
lint: venv | ||
yamllint roles playbooks | ||
ansible-lint roles/ playbooks/ | ||
|
||
molecule-converge: venv | ||
cd roles/single && molecule converge -s docker | ||
cd roles/vmagent && molecule converge -s docker | ||
cd roles/vmalert && molecule converge -s docker | ||
|
||
molecule-destroy: venv | ||
cd roles/single && molecule destroy -s docker | ||
cd roles/vmagent && molecule destroy -s docker | ||
cd roles/vmalert && molecule destroy -s docker |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ansible-compat==4.1.11 | ||
ansible-core==2.16.3 | ||
ansible-lint==24.2.0 | ||
docker==7.0.0 | ||
molecule==24.2.0 | ||
molecule-plugins==23.5.3 | ||
yamllint==1.35.1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
become: yes | ||
vars: | ||
victoriametrics_data_dir: "/tmp/victoria-metrics/" | ||
victoriametrics_backup_enabled: false | ||
victoriametrics_service_envflag_enabled: true | ||
victoriametrics_service_envflag_data: | ||
- "graphiteListenAddr=127.0.0.1:12345" | ||
victoriametrics_service_args: | ||
storageDataPath: "{{ victoriametrics_data_dir }}" | ||
tasks: | ||
- name: "Include single" | ||
ansible.builtin.include_role: | ||
name: "single" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
lint: | | ||
yamllint . | ||
ansible-lint . | ||
dependency: | ||
name: galaxy | ||
|
||
driver: | ||
name: docker | ||
|
||
platforms: | ||
- name: vmsingle-debian11 | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
cgroupns_mode: host | ||
privileged: true | ||
pre_build_image: true | ||
|
||
provisioner: | ||
name: ansible | ||
|
||
verifier: | ||
name: ansible |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
# This is an example playbook to execute Ansible tests. | ||
|
||
- name: Verify | ||
hosts: all | ||
tasks: | ||
- name: Check if port 12345 is listening | ||
ansible.builtin.wait_for: | ||
port: 12345 | ||
delay: 5 | ||
timeout: 10 | ||
msg: "Timeout waiting for port to respond" | ||
register: port_check | ||
ignore_errors: yes | ||
|
||
- name: Validate victoria is listening | ||
ansible.builtin.assert: | ||
that: port_check is succeeded | ||
|
||
- name: Check if port 8428 is listening | ||
ansible.builtin.wait_for: | ||
port: 8428 | ||
delay: 5 | ||
timeout: 10 | ||
msg: "Timeout waiting for port to respond" | ||
register: port_check | ||
ignore_errors: yes | ||
|
||
- name: Validate victoria is listening | ||
ansible.builtin.assert: | ||
that: port_check is succeeded |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
become: yes | ||
tasks: | ||
- name: "Include vmagent" | ||
ansible.builtin.include_role: | ||
name: "vmagent" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
lint: | | ||
yamllint . | ||
ansible-lint . | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
|
||
platforms: | ||
- name: vmagent-debian11 | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
cgroupns_mode: host | ||
privileged: true | ||
pre_build_image: true | ||
|
||
provisioner: | ||
name: ansible | ||
verifier: | ||
name: ansible |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
service: | ||
"vic-vmagent": | ||
enabled: true | ||
running: true |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
# Molecule Goss Tests | ||
|
||
- name: Verify | ||
hosts: all | ||
become: true | ||
vars: | ||
goss_version: v0.3.10 | ||
goss_arch: amd64 | ||
goss_bin: /usr/local/bin/goss | ||
goss_sha256sum: 150f25495ca0d1d4fd2ef8d0e750dbd767a15e9a522505f99b61dd1dd40a76d4 | ||
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}" | ||
goss_test_directory: /tmp/molecule/goss | ||
goss_format: documentation | ||
tasks: | ||
- name: Download and install Goss | ||
ansible.builtin.get_url: | ||
url: "{{ goss_url }}" | ||
dest: "{{ goss_bin }}" | ||
sha256sum: "{{ goss_sha256sum }}" | ||
mode: "u=rwx,go=rx" | ||
register: download_goss | ||
until: download_goss is succeeded | ||
retries: 3 | ||
|
||
- name: Create Molecule directory for test files | ||
ansible.builtin.file: | ||
path: "{{ goss_test_directory }}" | ||
state: directory | ||
mode: "0755" | ||
|
||
- name: Find Goss tests on localhost | ||
ansible.builtin.find: | ||
paths: "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}" | ||
patterns: | ||
- "test[-.\\w]*.yml" | ||
- "test_host_{{ ansible_hostname }}[-.\\w]*.yml" | ||
excludes: | ||
- "test_host_(?!{{ ansible_hostname }})[-.\\w]*.yml" | ||
use_regex: true | ||
delegate_to: localhost | ||
register: test_files | ||
changed_when: false | ||
become: false | ||
|
||
- name: Debug | ||
ansible.builtin.debug: | ||
msg: "{{ test_files.files }}" | ||
verbosity: 3 | ||
|
||
- name: Copy Goss tests to remote | ||
ansible.builtin.copy: | ||
src: "{{ item.path }}" | ||
dest: "{{ goss_test_directory }}/{{ item.path | basename }}" | ||
mode: "0644" | ||
with_items: | ||
- "{{ test_files.files }}" | ||
loop_control: | ||
label: "{{ item.path | basename }}" | ||
|
||
- name: Register test files | ||
ansible.builtin.find: | ||
paths: | ||
- "{{ goss_test_directory }}" | ||
patterns: | ||
- "test_*.yml" | ||
register: test_files | ||
|
||
- name: Run verify | ||
when: test_files is succeeded | ||
block: | ||
- name: Execute Goss tests # noqa: no-changed-when | ||
ansible.builtin.command: "{{ goss_bin }} -g {{ item }} validate --format {{ goss_format }}" | ||
register: test_results | ||
with_items: "{{ test_files.files | map(attribute='path') | list }}" | ||
loop_control: | ||
label: "{{ item | basename }}" | ||
failed_when: false | ||
|
||
- name: Display details about the Goss results | ||
ansible.builtin.debug: | ||
msg: "{{ item.stdout_lines }}" | ||
with_items: "{{ test_results.results }}" | ||
loop_control: | ||
label: "{{ item[item.ansible_loop_var] | basename }}" | ||
|
||
- name: Fail when tests fail | ||
ansible.builtin.fail: | ||
msg: "Goss failed to validate" | ||
when: item.rc != 0 | ||
with_items: "{{ test_results.results }}" | ||
loop_control: | ||
label: "{{ item[item.ansible_loop_var] | basename }}" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
become: yes | ||
tasks: | ||
- name: "Include vmalert" | ||
ansible.builtin.include_role: | ||
name: "vmalert" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
lint: | | ||
yamllint . | ||
ansible-lint . | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
|
||
platforms: | ||
- name: vmalert-debian11 | ||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian11}-ansible:latest" | ||
command: ${MOLECULE_DOCKER_COMMAND:-""} | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
cgroupns_mode: host | ||
privileged: true | ||
pre_build_image: true | ||
|
||
provisioner: | ||
name: ansible | ||
verifier: | ||
name: ansible |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
# This is an example playbook to execute Ansible tests. | ||
|
||
- name: Verify | ||
hosts: all | ||
tasks: | ||
- name: Example assertion | ||
ansible.builtin.assert: | ||
that: true |