Skip to content

Commit

Permalink
feat: add tests for Ansible Verifier (#367)
Browse files Browse the repository at this point in the history
* πŸš€ feat(molecule): add Postgres and Patroni tests
✨ feat(molecule): add etcd health check test
πŸ› fix(molecule): enable verifier in molecule config
The molecule configuration file was updated to enable the verifier. A new group_vars file was added to set the default Postgres database name, user, and password. Tests were added to check if PostgreSQL is running, listening on the default port, and if the database exists. A test was added to check the replication status of PostgreSQL. Tests were added to check the status of Patroni and etcd. These tests will help ensure that the application is running correctly and that the infrastructure is properly configured.

* πŸ› fix(verify.yml): reorder fileglob

Co-authored-by: Vitaliy Kukharik <37010174+vitabaks@users.noreply.github.com>

* πŸ”₯ chore(all.yml): remove all.yml file
✨ feat(verify.yml): include all tests and remove replica tests
πŸ› fix(postgres.yml): use patroni_superuser_username and patroni_superuser_password instead of postgres_user and postgres_password
πŸ› fix(postgres.yml): fix typo in task name
The all.yml file was removed as it was no longer needed. The verify.yml file was updated to include all tests and remove replica tests. The postgres.yml file was updated to use patroni_superuser_username and patroni_superuser_password instead of postgres_user and postgres_password. A typo in the task name was also fixed.

* πŸ”₯ chore(postgres.yml): remove redundant test to check if databases exist
The test to check if the databases exist is redundant as it is already being checked in the `molecule/default/converge.yml` playbook. Removing this test will reduce the time taken to run the tests and improve the overall performance of the test suite.

* πŸ› fix(verify.yml): fix indentation of file path in include_vars task
The indentation of the file path in the include_vars task was fixed to be consistent with the rest of the file.

* πŸ› fix(postgres.yml): change database name from postgres to template1
The database name was changed from postgres to template1 to avoid issues with the postgres database being used as a template database.

---------

Co-authored-by: Vitaliy Kukharik <37010174+vitabaks@users.noreply.github.com>
  • Loading branch information
ThomasSanson and vitabaks authored Jun 9, 2023
1 parent e57b07f commit 16062c3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
1 change: 0 additions & 1 deletion .config/molecule/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ scenario:

verifier:
name: ansible
enabled: false # TODO
15 changes: 15 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Molecule | Verify | All
hosts: all

tasks:
- name: Include vars of vars/main.yml
ansible.builtin.include_vars:
file: ../../vars/main.yml

- name: Molecule | Verify | Include all tests
ansible.builtin.include_tasks: "{{ item }}"
with_fileglob:
- ../tests/etcd/*.yml
- ../tests/patroni/*.yml
- ../tests/postgres/*.yml
7 changes: 7 additions & 0 deletions molecule/tests/etcd/etcd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Check etcd health
uri:
url: "http://{{ inventory_hostname }}:2379/health"
return_content: true
register: etcd_health_status
failed_when: "(etcd_health_status.content | from_json).health != 'true'"
7 changes: 7 additions & 0 deletions molecule/tests/patroni/patroni.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Check Patroni status
uri:
url: "http://{{ inventory_hostname }}:8008/patroni"
return_content: true
register: patroni_status
failed_when: "'running' not in patroni_status.content"
18 changes: 18 additions & 0 deletions molecule/tests/postgres/postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Check if PostgreSQL process is running
command: pgrep -u postgres
register: result
failed_when: result.rc != 0

- name: Check if PostgreSQL is listening on the default port
wait_for:
port: 5432
timeout: 5
register: is_listening
failed_when: not is_listening

- name: Try to connect to PostgreSQL
postgresql_ping:
login_user: "{{ patroni_superuser_username }}"
login_password: "{{ patroni_superuser_password }}"
db: template1
10 changes: 10 additions & 0 deletions molecule/tests/postgres/replication.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Check PostgreSQL replication status
postgresql_query:
db: postgres
login_user: "{{ patroni_superuser_username }}"
login_password: "{{ patroni_superuser_password }}"
query: "SELECT * FROM pg_stat_wal_receiver;"
register: pg_replication_status
failed_when: "pg_replication_status.rowcount == 0"
when: "'replica' in group_names"

0 comments on commit 16062c3

Please sign in to comment.