Skip to content

Commit

Permalink
[PR #490/6970aef backport][stable-2] Integrations tests : Use contain…
Browse files Browse the repository at this point in the history
…ers (#519)

* Integrations tests : Use containers for more control and verify that versions match expectation (#490)

* Add healthcheck to MariaDB before starting the tests
This prevent the first test to fail because the db isn't ready yet.

* Add % instead of the default 'localhost' since we use remote connection

Previously, everything was on localhost. Now ansible-test is in a
venv and the db is in a container. The db see the IP address from the
podman host (10.88.0.2)

* Add mysql_client to the controller

* Prepare controller with Podman/Docker Network

We use the Podman/Docker network gateway address to communicate between
container. I haven't tested Docker. I would have preferred to use a pod
but only Podman support it and ansible-test only support the
--docker-network option.

* Generalize mysql and mariadb version based on container name

This way we can split db_engine and db_version and simplify tests.
Also this is mandatory to use the matrix.db_engine_version as the
image name for our services containers.

* Fix replication due to usage of gateway_addr instead of localhost

* Refactor setup_mysql into setup_controller

* Fix server_id in GHA

GHA lack a way to pass option to docker's command. Also server_id is
not read as a environment variable. So I'm forced to use a config file.

* Refactor test_mysql_user to work with other host than localhost

* Refactor way tests info are passed from sed to file with lookup

The idea is to avoid modifying test targets from the workflow to prevent
ansible-test to think every tests needs to be run.

* Refactor test to use the db_version from setup_controller

* Add temporary files to .gitignore

* Add back docker healthcheck on services

I saw in the GHA logs that it perform an healtcheck ! So I hope this
will work.

* Refactor the way server_id is set for replicas

The simple way is to add '--server-id 2' after the name of the image of
the container. But GHA doesn't let us do that. The idea of mount a file
from our repo doesn't work because the repo is check out later in the
workflow and I failed to find a pre-job hook. Then I realized that this
MySQL option is dynamic! So we will set that in the test target!

* Add IF NOT EXISTS to prevent misleading error on retry

* Cut python 3.11 not supported by ansible-test yet

* Add option to run only a single target

* Disable replication with channel tests entirely for MySQL 5.7

* Activate Mysql 8 and Mariadb into GitHub Action Workflow

* Document run_all_tests.py

* Fix replication settings

sh don't know 'echo -e', so we use bash instead.
Also, we need to wait for the container to be healthy before trying to
restart it. Otherwise that could corrupt it.

* Add more descriptive tests names

* Use mysql_host var name instead of gateway_addr in tests

* Refactor user@<gateway ip addr> into user@%

* Workaround for plugin role that fails with any MariaDB versions

* Ensure replicas are healthy before rebooting them

* Add a virtualenv for ansible-test used locally

* Cut column-statistics disabling

Thanks to our test-container, we now use the correspond mysql-client.
So to test mysql 5.7 we use mysql-client-5.7 and to test mysql 8 we
use mysql-client-8.

* Fix test matrix

Python version should be quoted, otherwise 3.10 become 3.1
We can skip 2.14 and devel with Python3.8
We can skip devel with Python 3.9
We can skip MariaDB 10.4 with mysql-client-10.6
Add tests for MariaDB 10.6, 10.7 and 10.8

* Fix queries for roles

* Add filter for issues resolved in newer version of mysqlclient

* Add names to tests

* Cut tests for incompatible MySQL 8 and pymysql 0.7.11

* Fix assertion for older mysqlclient than 2.0.1 with mysql (mariadb ok)

* Change docker-image workflow to work on all images using matrix

* Add support for version of mysqlclient

* Fix verify database version

Sometimes, version_full contains trailing information (-log). To prevent
issues it's best to concatenate major and minor version.

* Cut filter for tests now that the right connector is used

* Add clean up in "always" phase of the block

Because our tests use --retry-on-error, and the first thing the test
does is to try to create the database. We must cleanup otherwise if
there is a retry, it will throw a misleading "database already exists"
error.

* Disable tests using pymysql 1.0.2

Many tests are failing but this must be fixed in the plugins in a future
PR.

* Cut test MySQL 8 with incompatible pymysql 0.7.11

It fails to connect with error about cryptography unsupported

* Fix missing cffi package to connect to MySQL 8 using Python 3.9

* Split Docker image workflow to rebuild only changed Dockerfile

My goal is not to save the planet but to make it work. Currently
docker/setup-buildx-action@v2 often fails. You have to rerun the
workflow multiple times until it succeed. When you do that with the
matrix with 15 containers, you never get to the point where they all
built successfully. Having separate workflows makes rerun the failing
build easier.

* Add option to let containers alive at end of testing

* Migrate tests documentations in their own file

* Document usage of continue_on_errors

* Add support for systems with unsupported python set as default

* Add create podman network for system missing it.

We saw that on a Fedora 33 with Podman 3.3.1, an old system. I didn't
find in which release the default network changed and maybe it's
defined in the Linux distribution. So in doubt I always attempt to
create the network.

* Add full path to image to prevent podman asking which registry to use

* Add options to enforce recreate containers even if already exists

* Add deletion of anonymous volumes associated with the container

* Change shebang from python to python3 to avoid confusion with python2

This script is a python3 script.

* Add disk and RAM requirements

* Cut the 3 from python command to follow shebang recommendations

https://docs.ansible.com/ansible-core/devel/dev_guide/testing/sanity/shebang.html

* Reformat file path

Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <[email protected]>

* Move utility task files in their own folder

* Add called workflow file in the GHA hooks

Without this, the containers are not rebuilt when you modify the file
built-docker-image.yml.

* Rollback to github.repository in container image name

This time I think I understood. We publish in the
github.repository_owner's namespace. In my case it's laurent-indermuehle
and in case of upstream it's ansible-collections. A proof of that:
https://github.com/orgs/ansible-collections/packages <- here there is
one attempt I did in february to push my branch to the upstream.
So, our tests containers will be visible to the whole community, not
just community.mysql.

---------

Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <[email protected]>
(cherry picked from commit 6970aef)

* Add changelog fragment

* Disable tests that doesn't work on stable-1

It's shameful to disable tests, but they didn't makes much sense
anyway.

* Fix error message being different on stable-1 than v3

* Disable tests against MariaDB 10.5 and 10.6

Does version have never been tested on stable-1 and many tests fails.
  • Loading branch information
laurent-indermuehle committed Mar 29, 2023
1 parent b02c5b4 commit 530e6c3
Show file tree
Hide file tree
Showing 122 changed files with 3,433 additions and 2,286 deletions.
375 changes: 318 additions & 57 deletions .github/workflows/ansible-test-plugins.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .github/workflows/ansible-test-roles.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Roles CI
on:
push:
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: Build Docker Image for ansible-test

on:
workflow_call:
inputs:
registry:
required: true
type: string
image_name:
required: true
type: string
context:
required: true
type: string

jobs:

build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
# Requirement to use 'context' in docker/build-push-action@v3
- name: Checkout repository
uses: actions/checkout@v3

# https://github.com/docker/login-action
- name: Log into registry ${{ inputs.registry }}
uses: docker/login-action@v2
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# https://github.com/docker/metadata-action
- name: Extract Docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v4
with:
images:
"${{ inputs.registry }}\
/${{ github.repository }}\
/${{ inputs.image_name }}"
tags: latest

# Setting up Docker Buildx with docker-container driver is required
# at the moment to be able to use a subdirectory with Git context
#
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# https://github.com/docker/build-push-action
- name: Build and push Docker image with Buildx
id: build-and-push
uses: docker/build-push-action@v3
with:
context: ${{ inputs.context }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-mariadb103-py38-mysqlclient201.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI mariadb103-py38-mysqlclient201

on:
push:
paths:
- 'test-containers/mariadb103-py38-mysqlclient201/**'
- '.github/workflows/docker-image-mariadb103-py38-mysqlclient201.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-mariadb103-py38-mysqlclient201
context: test-containers/mariadb103-py38-mysqlclient201
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-mariadb103-py38-pymysql093.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI mariadb103-py38-pymysql093

on:
push:
paths:
- 'test-containers/mariadb103-py38-pymysql093/**'
- '.github/workflows/docker-image-mariadb103-py38-pymysql093.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-mariadb103-py38-pymysql093
context: test-containers/mariadb103-py38-pymysql093
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-mariadb103-py39-mysqlclient203.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI mariadb103-py39-mysqlclient203

on:
push:
paths:
- 'test-containers/mariadb103-py39-mysqlclient203/**'
- '.github/workflows/docker-image-mariadb103-py39-mysqlclient203.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-mariadb103-py39-mysqlclient203
context: test-containers/mariadb103-py39-mysqlclient203
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-mariadb103-py39-pymysql093.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI mariadb103-py39-pymysql093

on:
push:
paths:
- 'test-containers/mariadb103-py39-pymysql093/**'
- '.github/workflows/docker-image-mariadb103-py39-pymysql093.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-mariadb103-py39-pymysql093
context: test-containers/mariadb103-py39-pymysql093
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-mariadb106-py310-mysqlclient211.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI mariadb106-py310-mysqlclient211

on:
push:
paths:
- 'test-containers/mariadb106-py310-mysqlclient211/**'
- '.github/workflows/docker-image-mariadb106-py310-mysqlclient211.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-mariadb106-py310-mysqlclient211
context: test-containers/mariadb106-py310-mysqlclient211
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-mariadb106-py310-pymysql102.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI mariadb106-py310-pymysql102

on:
push:
paths:
- 'test-containers/mariadb106-py310-pymysql102/**'
- '.github/workflows/docker-image-mariadb106-py310-pymysql102.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-mariadb106-py310-pymysql102
context: test-containers/mariadb106-py310-pymysql102
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my57-py38-mysqlclient201.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my57-py38-mysqlclient201

on:
push:
paths:
- 'test-containers/my57-py38-mysqlclient201/**'
- '.github/workflows/docker-image-my57-py38-mysqlclient201.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my57-py38-mysqlclient201
context: test-containers/my57-py38-mysqlclient201
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my57-py38-pymysql0711.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my57-py38-pymysql0711

on:
push:
paths:
- 'test-containers/my57-py38-pymysql0711/**'
- '.github/workflows/docker-image-my57-py38-pymysql0711.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my57-py38-pymysql0711
context: test-containers/my57-py38-pymysql0711
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my57-py38-pymysql093.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my57-py38-pymysql093

on:
push:
paths:
- 'test-containers/my57-py38-pymysql093/**'
- '.github/workflows/docker-image-my57-py38-pymysql093.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my57-py38-pymysql093
context: test-containers/my57-py38-pymysql093
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my80-py310-mysqlclient211.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my80-py310-mysqlclient211

on:
push:
paths:
- 'test-containers/my80-py310-mysqlclient211/**'
- '.github/workflows/docker-image-my80-py310-mysqlclient211.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my80-py310-mysqlclient211
context: test-containers/my80-py310-mysqlclient211
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my80-py310-pymysql102.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my80-py310-pymysql102

on:
push:
paths:
- 'test-containers/my80-py310-pymysql102/**'
- '.github/workflows/docker-image-my80-py310-pymysql102.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my80-py310-pymysql102
context: test-containers/my80-py310-pymysql102
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my80-py38-mysqlclient201.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my80-py38-mysqlclient201

on:
push:
paths:
- 'test-containers/my80-py38-mysqlclient201/**'
- '.github/workflows/docker-image-my80-py38-mysqlclient201.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my80-py38-mysqlclient201
context: test-containers/my80-py38-mysqlclient201
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my80-py38-pymysql093.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my80-py38-pymysql093

on:
push:
paths:
- 'test-containers/my80-py38-pymysql093/**'
- '.github/workflows/docker-image-my80-py38-pymysql093.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my80-py38-pymysql093
context: test-containers/my80-py38-pymysql093
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my80-py39-mysqlclient203.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my80-py39-mysqlclient203

on:
push:
paths:
- 'test-containers/my80-py39-mysqlclient203/**'
- '.github/workflows/docker-image-my80-py39-mysqlclient203.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my80-py39-mysqlclient203
context: test-containers/my80-py39-mysqlclient203
19 changes: 19 additions & 0 deletions .github/workflows/docker-image-my80-py39-pymysql093.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Docker Image CI my80-py39-pymysql093

on:
push:
paths:
- 'test-containers/my80-py39-pymysql093/*'
- '.github/workflows/docker-image-my80-py39-pymysql093.yml'
- '.github/workflows/build-docker-image.yml'

jobs:

call-workflow-passing-data:
uses: ./.github/workflows/build-docker-image.yml
secrets: inherit
with:
registry: ghcr.io
image_name: test-container-my80-py39-pymysql093
context: test-containers/my80-py39-pymysql093
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/tests/output/
/tests/integration/inventory
/changelogs/.plugin-cache.yaml
*.swp

Expand Down
Loading

0 comments on commit 530e6c3

Please sign in to comment.