Skip to content

Commit

Permalink
build: add integration testing for main roles (#34)
Browse files Browse the repository at this point in the history
* build: add integration testing

ci: add github workflow for integration tests

ci: use matrix for integration testing

chore: add tag to skip idempotence tests for clickhouse

build: add integration testing for mysql 8.4

test: fix verify command for mysql_8_4

test: fix mysql ansible variables

build: add integration testing for mysql 8.0

test: fix idempotence tests

test: setup vars in the all group

chore: run all jobs on parallel

build: add integration testing for caddy

build: add integration testing for caddy

build: add integration testing for elasticsearch_7_10

build: add integration testing for mongo_4_2

build: add integration testing

build: add integration testing

* fix: ensure gpg-agent is installed

fix: update docker images

fix: mark tasks are no idempotence

fix: run caddy tests on ubuntu

fix: add no idempotence tag for caddy and mongo

* fix: update elasticsearch log directory

* chore: remove mysql8.4 integration tests

* fix: setup bind IP for elastichsearch

* chore: remove outdated verify comment

* build: only run changed environments

* build: add integration testing for mysql 8.4

* build: only run changed environments

* build: only run changed environments

* build: only run changed environments

* docs: add molecule documentation

* docs: add molecule documentation

* fix: force a valid priv instead of using defaults

* test: add dependencies for mysql_8_4

* build: only run changed environments
  • Loading branch information
Ian2012 authored Jul 3, 2024
1 parent bd3bcdb commit 68c4dc1
Show file tree
Hide file tree
Showing 52 changed files with 687 additions and 15 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Integration Test

on:
pull_request:
push:
branches:
- main

jobs:

load-roles:
runs-on: ubuntu-latest
outputs:
roles: ${{ steps.changed_roles.outputs.roles }}
scenarios: ${{ steps.scenarios.outputs.scenarios}}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Find changed roles
id: changed_roles
run: |
ROLES=$(git diff --name-only origin/main origin/${GITHUB_HEAD_REF} -- roles/*/ | awk -F '/' '{print $2}' | uniq | jq -R -s -c 'split("\n")[:-1]')
echo "::set-output name=roles::$ROLES"
- name: Find available scenarios
id: scenarios
run: |
SCENARIOS=$(ls molecule | jq -R -s -c 'split("\n")[:-1]')
echo "::set-output name=scenarios::$SCENARIOS"
molecule:
needs: load-roles
strategy:
fail-fast: false
matrix:
environment: ${{ fromJson(needs.load-roles.outputs.roles) }}
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup python
uses: actions/setup-python@v3
with:
python-version: '3.8'

- name: Install test dependencies
run: pip3 install molecule[docker] yamllint ansible-lint

- name: Run molecule tests
if: ${{ contains(fromJson(needs.load-roles.outputs.scenarios), matrix.environment) }}
run: molecule test -s ${{ matrix.environment }}
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLORS: '1'
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ For now this repo supports the playbooks for:
- Caddy

---

## Extract and Restore databases:

The procedure involves extracting specific databases, creating backups of each, and subsequently restoring them into a new database. A list of databases to process will be compiled, and for each, a backup will be created followed by a restoration. The outcome will be a new database named after the original with an appended suffix. For example, if the original database is named `edxapp`, the new database will be called `edxapp_clone`, containing the data from the original database.
Expand Down Expand Up @@ -238,3 +237,54 @@ This process will be carried out using the `admin` user for MySQL and Mongo, whi
```

Upon completion of the execution, you should observe both the existing databases and the new databases suffixed with `_clone` in your database instance, as per the default configuration.

## Molecule tests

Integration testing is performed using [molecule](https://ansible.readthedocs.io/projects/molecule/).

Molecule tests consist of different scenarios which are implemented using ansible roles, those are run on Docker and
can be customized per role.

### Getting started

Install molecule via:

```shell
pip install molecule[docker] ansible-lint
```

### Run tests

A test consist of the following phases:

- **create**: Create a docker instance for the scenario to test. See `molecule/**/molecule.yml` for examples.
- **converge**: Create a docker instance for the scenario to test and runs the role specified on `molecule/**/converge.yml`
- **verify**: After the `converge` phase, you can run the `verify` command to check wheter your role was succesfully run.
See `molecule/**/verify.yml` for examples.
- **idempotence**: After the `converge` phase, you can run the `idempotence` command to check if your role is idempotent.
- **destroy**: Destroys the created docker instance for the scenario.

You can run a whole scenario by running:

```shell
molecule test -s scenario_name
```

You can also run the steps independently using the following commands:

```shell
molecule create -s scenario_name
molecule converge -s scenario_name
molecule verify -s scenario_name
molecule idempotence -s scenario_name
molecule destroy -s scenario_name
```

To debug molecule tests you can run the converge phase and login to the docker instance:

```shell
molecule converge -s scenario_name
molecule login -s scenario_name
```

See [molecule documentation](https://ansible.readthedocs.io/projects/molecule/) for more information.
8 changes: 8 additions & 0 deletions molecule/caddy/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include atlas-ansible-utils"
include_role:
name: "atlas-ansible-utils"
- import_playbook: ../../caddy.yml
27 changes: 27 additions & 0 deletions molecule/caddy/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: caddy-instance
image: geerlingguy/docker-ubuntu2204-ansible:latest
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- caddy_servers
provisioner:
name: ansible
inventory:
all: {}
verifier:
name: ansible
11 changes: 11 additions & 0 deletions molecule/caddy/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---


- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Verify Caddy installation
register: caddy
shell: |
caddy version
8 changes: 8 additions & 0 deletions molecule/clickhouse/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include atlas-ansible-utils"
include_role:
name: "atlas-ansible-utils"
- import_playbook: ../../clickhouse.yml
28 changes: 28 additions & 0 deletions molecule/clickhouse/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: clickhouse-instance
image: geerlingguy/docker-ubuntu2004-ansible:latest
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- clickhouse_servers
provisioner:
name: ansible
inventory:
all:
CLICKHOUSE_DEFAULT_USER_PASSWORD: password
verifier:
name: ansible
17 changes: 17 additions & 0 deletions molecule/clickhouse/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---


- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Verify ClickHouse HTTP
uri:
url: "http://localhost:8123/"
status_code: 200
timeout: 1
return_content: yes
- name: Verify ClickHouse installation
register: clickhouse_client
shell: |
clickhouse-client --user "default" --password="password" --query "SELECT 1"
8 changes: 8 additions & 0 deletions molecule/elasticsearch_7_10/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include atlas-ansible-utils"
include_role:
name: "atlas-ansible-utils"
- import_playbook: ../../elasticsearch_7_10.yml
27 changes: 27 additions & 0 deletions molecule/elasticsearch_7_10/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: elasticsearch-instance
image: geerlingguy/docker-ubuntu2004-ansible:latest
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- elasticsearch_servers
provisioner:
name: ansible
inventory:
all: {}
verifier:
name: ansible
13 changes: 13 additions & 0 deletions molecule/elasticsearch_7_10/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---


- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Verify ElasticSearch installation
uri:
url: http://localhost:9200/
status_code: 200
timeout: 1
return_content: yes
8 changes: 8 additions & 0 deletions molecule/mongo_4_2/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include atlas-ansible-utils"
include_role:
name: "atlas-ansible-utils"
- import_playbook: ../../mongo_4_2.yml
27 changes: 27 additions & 0 deletions molecule/mongo_4_2/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: mongo-instance
image: geerlingguy/docker-ubuntu2004-ansible:latest
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- mongo_servers
provisioner:
name: ansible
inventory:
all: {}
verifier:
name: ansible
13 changes: 13 additions & 0 deletions molecule/mongo_4_2/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---


- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Verify MongoDB installation
uri:
url: http://localhost:27017/
status_code: 200
timeout: 1
return_content: yes
8 changes: 8 additions & 0 deletions molecule/mongo_4_4/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include atlas-ansible-utils"
include_role:
name: "atlas-ansible-utils"
- import_playbook: ../../mongo_4_4.yml
27 changes: 27 additions & 0 deletions molecule/mongo_4_4/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: mongo-4-4-instance
image: geerlingguy/docker-ubuntu2204-ansible:latest
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
cgroupns_mode: host
privileged: true
pre_build_image: true
groups:
- mongo_servers
provisioner:
name: ansible
inventory:
all: {}
verifier:
name: ansible
13 changes: 13 additions & 0 deletions molecule/mongo_4_4/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---


- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Verify MongoDB installation
uri:
url: http://localhost:27017/
status_code: 200
timeout: 1
return_content: yes
8 changes: 8 additions & 0 deletions molecule/mongo_7_0/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include atlas-ansible-utils"
include_role:
name: "atlas-ansible-utils"
- import_playbook: ../../mongo_7_0.yml
Loading

0 comments on commit 68c4dc1

Please sign in to comment.