Add PoC using custom ansible-test containers

This commit is contained in:
Laurent Indermuehle 2023-01-13 16:22:57 +01:00
parent 199b7a5b64
commit db995249cb
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09
6 changed files with 147 additions and 89 deletions

View file

@ -40,48 +40,60 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
db_engine_version: include:
- mysql:5.7.40 - ansible: stable-2.12
- mysql:8.0.31 db_engine_version: mysql:5.7.40
- mariadb:10.4.24 python: 3.8
- mariadb:10.5.18 connector: pymysql==0.7.11
- mariadb:10.6.11 docker_container: my57-py38-mysqlclient201-pymysql0711
- mariadb:10.7.7 - ansible: stable-2.12
- mariadb:10.8.3 db_engine_version: mysql:5.7.40
ansible: python: 3.8
- stable-2.12 connector: pymysql==0.9.3
- stable-2.13 docker_container: my57-py38-pymysql093
- stable-2.14
- devel # db_engine_version:
python: # - mysql:5.7.40
- "3.8" # - mysql:8.0.31
- "3.9" # - mariadb:10.4.24
- "3.10" # Without quotes, this become 3.1 in run_all_test.py! # - mariadb:10.5.18
connector: # - mariadb:10.6.11
- pymysql==0.7.10 # - mariadb:10.7.7
- pymysql==0.9.3 # - mariadb:10.8.3
- mysqlclient==2.0.1 # ansible:
exclude: # - stable-2.12
- db_engine_version: mysql:8.0.22 # - stable-2.13
connector: pymysql==0.7.10 # - stable-2.14
- db_engine_version: mariadb:10.4.24 # - devel
connector: pymysql==0.7.10 # python:
- db_engine_version: mariadb:10.5.18 # - "3.8"
connector: pymysql==0.7.10 # - "3.9"
- db_engine_version: mariadb:10.8.3 # - "3.10" # Without quotes, this become 3.1 in run_all_test.py!
connector: pymysql==0.7.10 # connector:
- python: 3.8 # - pymysql==0.7.10
ansible: stable-2.13 # - pymysql==0.9.3
- python: 3.8 # - mysqlclient==2.0.1
ansible: stable-2.14 # exclude:
- python: 3.8 # - db_engine_version: mysql:8.0.22
ansible: devel # connector: pymysql==0.7.10
- python: 3.9 # - db_engine_version: mariadb:10.4.24
ansible: stable-2.12 # connector: pymysql==0.7.10
- python: 3.9 # - db_engine_version: mariadb:10.5.18
connector: mysqlclient==2.0.1 # connector: pymysql==0.7.10
- python: 3.10 # - db_engine_version: mariadb:10.8.3
ansible: stable-2.12 # connector: pymysql==0.7.10
# - python: 3.8
# ansible: stable-2.13
# - python: 3.8
# ansible: stable-2.14
# - python: 3.8
# ansible: devel
# - python: 3.9
# ansible: stable-2.12
# - python: 3.9
# connector: mysqlclient==2.0.1
# - python: 3.10
# ansible: stable-2.12
services: services:
db_primary: db_primary:
@ -157,6 +169,7 @@ jobs:
echo -n "${{ matrix.db_engine_version }}" > tests/integration/db_engine_version; echo -n "${{ matrix.db_engine_version }}" > tests/integration/db_engine_version;
echo Setting Connector version to "${{ matrix.connector }}"...; echo Setting Connector version to "${{ matrix.connector }}"...;
echo -n "${{ matrix.connector }}" > tests/integration/connector echo -n "${{ matrix.connector }}" > tests/integration/connector
docker_container: ${{ matrix.docker_container }}
target-python-version: ${{ matrix.python }} target-python-version: ${{ matrix.python }}
testing-type: integration testing-type: integration

View file

@ -13,6 +13,29 @@ Actually, the makefile only support Podman. I don't have tested with docker yet.
The Makefile accept the following options: The Makefile accept the following options:
- ansible: Mandatory version of ansible to install in a venv to run ansible-test.
- container_image:
The container image to use to run our test. There images are created in github.com/community.mysql-test-containers and push the following images on quay.io:
- my57-py38-pymysql093
- my57-py38-mysqlclient201-pymysql0711
- my57-py39-pymysql093
- my57-py39-mysqlclient203-pymysql0711
- my57-py310-pymysql093
- my57-py310-mysqlclient211-pymysql0711
- my80-py38-pymysql093
- my80-py38-mysqlclient201-pymysql0711
- my80-py39-pymysql093
- my80-py39-mysqlclient203-pymysql0711
- my80-py310-pymysql093
- my80-py310-mysqlclient211-pymysql0711
- mariadb-py38-pymysql093
- mariadb-py38-mysqlclient201
- mariadb-py39-pymysql093
- mariadb-py39-mysqlclient203
- mariadb-py310-pymysql093
- mariadb-py310-mysqlclient211
Unfortunatly you must provide the right container_image yourself. And you still need to provides db_engine_version, python, etc...
To minimise the amount of images, pymysql 0.7.11 and mysqlclient are shipped together.
- db_engine_version: The name of the container to use. Either MYSQL or MariaDB. Use ':' as a separator. Do not use short version, like mysql:8 for instance. Our tests expect a full version to filter tests based on released version. For instance: when: db_version is version ('8.0.22', '>'). - db_engine_version: The name of the container to use. Either MYSQL or MariaDB. Use ':' as a separator. Do not use short version, like mysql:8 for instance. Our tests expect a full version to filter tests based on released version. For instance: when: db_version is version ('8.0.22', '>').
- connector: The name of the python package of the connector along with its version number. Use '==' as a separator. - connector: The name of the python package of the connector along with its version number. Use '==' as a separator.
- python: The python version to use in the controller. - python: The python version to use in the controller.
@ -22,10 +45,10 @@ Examples:
```sh ```sh
# Run all targets # Run all targets
make db_engine_version="mysql:5.7.40" connector="pymysql==0.7.10" python="3.8" make ansible="stable-2.14" db_engine_version="mysql:5.7.40" connector="pymysql==0.7.10" python="3.8" container_image="my57-py38-mysqlclient201-pymysql0711"
# A single target # A single target
make db_engine_version="mysql:5.7.40" connector="pymysql==0.7.10" python="3.8" target="test_mysql_db" make ansible="stable-2.14" db_engine_version="mysql:5.7.40" connector="pymysql==0.7.10" python="3.8" container_image="my57-py38-mysqlclient201-pymysql0711" target="test_mysql_db"
``` ```

View file

@ -28,27 +28,31 @@ def extract_matrix(workflow_yaml):
return matrix return matrix
def is_exclude(exclude_list, test_suite): # def is_exclude(exclude_list, test_suite):
test_is_excluded = False # test_is_excluded = False
for excl in exclude_list: # for excl in exclude_list:
match = 0 # match = 0
if 'db_engine_version' in excl: # if 'ansible' in excl:
if excl.get('db_engine_version') == test_suite[0]: # if excl.get('ansible') == test_suite[0]:
match += 1 # match += 1
if 'python' in excl: # if 'db_engine_version' in excl:
if excl.get('python') == test_suite[1]: # if excl.get('db_engine_version') == test_suite[1]:
match += 1 # match += 1
if 'connector' in excl: # if 'python' in excl:
if excl.get('connector') == test_suite[2]: # if excl.get('python') == test_suite[2]:
match += 1 # match += 1
if match > 1: # if 'connector' in excl:
test_is_excluded = True # if excl.get('connector') == test_suite[3]:
# match += 1
return test_is_excluded # if match > 1:
# test_is_excluded = True
# return test_is_excluded
def main(): def main():
@ -56,17 +60,23 @@ def main():
tests_matrix_yaml = extract_matrix(workflow_yaml) tests_matrix_yaml = extract_matrix(workflow_yaml)
matrix = [] matrix = []
exclude_list = tests_matrix_yaml.get('exclude') # exclude_list = tests_matrix_yaml.get('exclude')
for db_engine in tests_matrix_yaml.get('db_engine_version'): # for ansible in tests_matrix_yaml.get('ansible'):
for python in tests_matrix_yaml.get('python'): # for db_engine in tests_matrix_yaml.get('db_engine_version'):
for connector in tests_matrix_yaml.get('connector'): # for python in tests_matrix_yaml.get('python'):
if not is_exclude(exclude_list, (db_engine, python, connector)): # for connector in tests_matrix_yaml.get('connector'):
matrix.append((db_engine, python, connector)) # if not is_exclude(exclude_list, (ansible, db_engine, python, connector)):
# matrix.append((ansible, db_engine, python, connector))
for tests in matrix: for tests in tests_matrix_yaml.get('include'):
make_cmd = f'make db_engine_version="{tests[0]}" python="{tests[1]}" connector="{tests[2]}" test-integration' a = tests.get('ansible')
print(f'Run tests for: {tests[0]}, Python: {tests[1]}, Connector: {tests[2]}') d = tests.get('db_engine_version')
os.system(make_cmd) p = tests.get('python')
c = tests.get('connector')
i = tests.get('docker_container')
make_cmd = f'make ansible="{a}" db_engine_version="{d}" python="{p}" connector="{c}" docker_container="{i}" test-integration'
print(f'Run tests for: Ansible: {a}, DB: {d}, Python: {p}, Connector: {c}, Image: {i}')
# os.system(make_cmd)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -1,6 +1,18 @@
--- ---
- name: "{{ role_name }} | Connector | Install python packages" # - name: "{{ role_name }} | Connector | Install requirements for mysqlclient"
ansible.builtin.pip: # ansible.builtin.apt:
name: "{{ connector_name }}" # name:
state: present # - python3-dev
# - default-libmysqlclient-dev
# - build-essential
# state: present
# environment:
# DEBIAN_FRONTEND: noninteractive
# when:
# - connector_name == 'mysqlclient'
# - name: "{{ role_name }} | Connector | Install python packages"
# ansible.builtin.pip:
# name: "{{ connector_name_version }}"
# state: present

View file

@ -1,14 +1,14 @@
--- ---
- name: "{{ role_name }} | install | Required package for testing" # - name: "{{ role_name }} | install | Required package for testing"
ansible.builtin.apt: # ansible.builtin.apt:
name: # name:
- iproute2 # - iproute2 # To grab docker network gateway address
- python3-cryptography # To authenticate with MySQL 8+ # - python3-cryptography # To authenticate with MySQL 8+
state: present # state: present
update_cache: true # update_cache: true
environment: # environment:
DEBIAN_FRONTEND: noninteractive # DEBIAN_FRONTEND: noninteractive
- name: "{{ role_name }} | install | Ensure fake root folder" - name: "{{ role_name }} | install | Ensure fake root folder"
ansible.builtin.file: ansible.builtin.file:

View file

@ -13,10 +13,10 @@
ansible.builtin.import_tasks: ansible.builtin.import_tasks:
file: setvars.yml file: setvars.yml
- name: Install MySQL local client # - name: Install MySQL local client
ansible.builtin.import_tasks: # ansible.builtin.import_tasks:
file: client.yml # file: client.yml
- name: Install MySQL Python connector # - name: Install MySQL Python connector
ansible.builtin.import_tasks: # ansible.builtin.import_tasks:
file: connector.yml # file: connector.yml