Skip to content

Commit

Permalink
add molecule integration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
antmelekhin committed Jun 16, 2024
1 parent 0066d69 commit b0a5d5e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
scenario: 'default'
- distro: 'ubuntu-22.04'
scenario: 'tls-and-basic-auth'
- distro: 'ubuntu-22.04'
scenario: 'integration-test'

steps:
- name: 'Checkout the codebase'
Expand Down
8 changes: 8 additions & 0 deletions molecule/integration-test/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: 'Converge'
hosts: all
roles:
- role: antmelekhin.postgres_exporter
postgres_exporter_data_source_uri: 'localhost:5432/molecule?sslmode=disable'
postgres_exporter_data_source_user: 'exporter'
postgres_exporter_data_source_pass: 'Passw0rd'
23 changes: 23 additions & 0 deletions molecule/integration-test/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
role_name_check: 2
dependency:
name: 'galaxy'
enabled: true
driver:
name: 'docker'
platforms:
- name: 'postgres_exporter-${IMAGE:-docker-systemd}-${TAG:-ubuntu-22.04}${TOX_ENVNAME}'
image: '${NAMESPACE:-antmelekhin}/${IMAGE:-docker-systemd}:${TAG:-ubuntu-22.04}'
published_ports:
- '0.0.0.0:9187:9187/udp'
- '0.0.0.0:9187:9187/tcp'
volumes:
- '/sys/fs/cgroup:/sys/fs/cgroup:rw'
- '/var/lib/containerd'
cgroupns_mode: 'host'
privileged: true
pre_build_image: true
provisioner:
name: 'ansible'
verifier:
name: 'ansible'
42 changes: 42 additions & 0 deletions molecule/integration-test/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: 'Prepare an Ansible host for GitHub Actions'
hosts: localhost
tasks:
- name: 'Install tar for tasks delegated to the localhost'
community.general.apk:
name: 'tar'
update_cache: true
when: ansible_os_family == 'Alpine'

- name: 'Prepare'
hosts: all
vars:
locale: 'en_US.UTF-8'

pre_tasks:
- name: 'Update APT cache'
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
when: ansible_os_family == 'Debian'

- name: 'Set database locale if using RedHat 8'
ansible.builtin.set_fact:
locale: 'C.UTF-8'
when:
- ansible_os_family == 'RedHat' and
ansible_distribution_major_version == '8'

roles:
- role: geerlingguy.postgresql
postgresql_users:
- name: 'exporter'
password: 'Passw0rd'
role_attr_flags: 'SUPERUSER'
postgresql_databases:
- name: 'molecule'
lc_collate: '{{ locale }}'
lc_ctype: '{{ locale }}'
encoding: 'UTF-8'
template: 'template0'
owner: 'exporter'
22 changes: 22 additions & 0 deletions molecule/integration-test/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: 'Verify'
hosts: all
gather_facts: false

tasks:
- name: 'Gathering Service Facts'
ansible.builtin.service_facts:

- name: 'Assert that Postgres Exporter service is enabled and running'
ansible.builtin.assert:
that:
- ansible_facts.services['postgres_exporter.service'].state == 'running'
- ansible_facts.services['postgres_exporter.service'].status == 'enabled'

- name: 'Verify the Postgres Exporter is responding to requests'
ansible.builtin.uri:
url: 'http://{{ ansible_host }}:9187/metrics'
register: __postgres_exporter_response
until: __postgres_exporter_response.status == 200
retries: 120
delay: 5

0 comments on commit b0a5d5e

Please sign in to comment.