diff --git a/.config/molecule/config.yml b/.config/molecule/config.yml index a5493859b..f0be1498e 100644 --- a/.config/molecule/config.yml +++ b/.config/molecule/config.yml @@ -44,4 +44,3 @@ scenario: verifier: name: ansible - enabled: false # TODO diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 000000000..850461090 --- /dev/null +++ b/molecule/default/verify.yml @@ -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 diff --git a/molecule/tests/etcd/etcd.yml b/molecule/tests/etcd/etcd.yml new file mode 100644 index 000000000..e95693cd7 --- /dev/null +++ b/molecule/tests/etcd/etcd.yml @@ -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'" diff --git a/molecule/tests/patroni/patroni.yml b/molecule/tests/patroni/patroni.yml new file mode 100644 index 000000000..833c7bff6 --- /dev/null +++ b/molecule/tests/patroni/patroni.yml @@ -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" diff --git a/molecule/tests/postgres/postgres.yml b/molecule/tests/postgres/postgres.yml new file mode 100644 index 000000000..b3020cf3b --- /dev/null +++ b/molecule/tests/postgres/postgres.yml @@ -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 diff --git a/molecule/tests/postgres/replication.yml b/molecule/tests/postgres/replication.yml new file mode 100644 index 000000000..ffe85b284 --- /dev/null +++ b/molecule/tests/postgres/replication.yml @@ -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"