Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tests for Ansible Verifier #367

Merged
merged 6 commits into from
Jun 9, 2023
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
4 changes: 4 additions & 0 deletions molecule/default/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
postgres_db_name: postgres
postgres_user: postgres
postgres_password: postgres
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Molecule | Verify | All
hosts: all

tasks:
- name: Molecule | Verify | Include all tests
ansible.builtin.include_tasks: "{{ item }}"
with_fileglob:
- ../tests/postgres/postgres.yml
- ../tests/patroni/*.yml
- ../tests/etcd/*.yml
ThomasSanson marked this conversation as resolved.
Show resolved Hide resolved

- name: Molecule | Verify | Replica
hosts: replica

tasks:
- name: Molecule | Verify | Include replica tests
ansible.builtin.include_tasks: "{{ item }}"
with_fileglob:
- ../tests/postgres/replication.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"
23 changes: 23 additions & 0 deletions molecule/tests/postgres/postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- 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: "{{ postgres_user }}"
login_password: "{{ postgres_password }}"
db: postgres
vitabaks marked this conversation as resolved.
Show resolved Hide resolved

- name: Check if the database exists
vitabaks marked this conversation as resolved.
Show resolved Hide resolved
postgresql_db:
name: "{{ postgres_db_name }}"
state: present
9 changes: 9 additions & 0 deletions molecule/tests/postgres/replication.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Check PostgreSQL replication status
postgresql_query:
db: "{{ postgres_db_name }}"
login_user: "{{ postgres_user }}"
login_password: "{{ postgres_password }}"
query: "SELECT * FROM pg_stat_wal_receiver;"
register: pg_replication_status
failed_when: "pg_replication_status.rowcount == 0"