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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"