vitabaks / postgresql_cluster

PostgreSQL High-Availability Cluster (based on Patroni). Automating with Ansible.
https://postgresql-cluster.org
MIT License
1.69k stars 411 forks source link

feat: add tests for Ansible Verifier #367

Closed ThomasSanson closed 1 year ago

ThomasSanson commented 1 year ago

🚀 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.

vitabaks commented 1 year ago

Thank you for your contribution

I think we should clarify the title of this PR In my understanding, there are already tests - https://github.com/vitabaks/postgresql_cluster/actions/workflows/molecule.yml

vitabaks commented 1 year ago

I believe we are talking about additional tests here

It is important to note that the necessary tests are performed in the main playbook

here is an example:

https://github.com/vitabaks/postgresql_cluster/blob/master/roles/patroni/tasks/main.yml#L836 https://github.com/vitabaks/postgresql_cluster/blob/master/roles/etcd/tasks/main.yml#L122

You can find a lot of detailed checks in the code.

vitabaks commented 1 year ago

maybe so "Add tests for Ansible Verifier"

ThomasSanson commented 1 year ago

@vitabaks

It's important to note that there are two scopes of testing in our process:

  1. The tests run during the installation, via the playbooks.
  2. The tests initiated by molecule's verify, designed to facilitate a test-driven development approach (TDD).

I believe that both types of tests are necessary. However, I could consider combining them and initiating them at the right time. This is what I anticipate with the collection format: I will have a 'healthcheck' playbook that can be launched at any time to check the health status of our infrastructure. This playbook will itself be triggered by molecule's verify.

In summary, I differentiate between the tests performed during installation, which are an integral part of the installation process, and the verification tests performed at the end.

To provide a bit more context, I plan to implement the 'side_effect' in the future. This process will aim to disrupt a part of the infrastructure (for example, by killing a master container) to then launch the verify and ensure everything is working correctly (i.e., the recovery is successful). This is just an example to highlight the importance of conducting tests after the convergence (installation) phase.

https://github.com/confluentinc/cp-ansible/tree/7.4.0-post/molecule

vitabaks commented 1 year ago

Thank you for sharing your detailed testing approach. I find the idea of integrating both installation testing and post-installation verification compelling. The planned 'healthcheck' playbook and future 'side_effect' implementation certainly add robustness to the process. Looking forward to seeing these enhancements in action.

vitabaks commented 1 year ago

@ThomasSanson Let me know when you're done working on this PR.

ThomasSanson commented 1 year ago

@vitabaks all done for me, this pull request is ready