From b9d0e96deb9a21680f9f01d4dfc709e94f358498 Mon Sep 17 00:00:00 2001 From: Laurent Indermuehle Date: Thu, 12 Jan 2023 13:49:34 +0100 Subject: [PATCH] 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. --- .github/workflows/ansible-test-plugins.yml | 13 ++++++++----- Makefile | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ansible-test-plugins.yml b/.github/workflows/ansible-test-plugins.yml index d6be987..4ee732d 100644 --- a/.github/workflows/ansible-test-plugins.yml +++ b/.github/workflows/ansible-test-plugins.yml @@ -130,18 +130,21 @@ jobs: steps: - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 + # No need to check for service health. GitHub Action took care of it. - name: Restart MySQL server with settings for replication run: | - docker exec ${{ job.services.db_primary.id }} sh -c 'echo -e [mysqld]\\nserver-id=1\\nlog-bin=/var/lib/mysql/primary-bin > /etc/mysql/conf.d/replication.cnf' - docker exec ${{ job.services.db_replica1.id }} sh -c 'echo -e [mysqld]\\nserver-id=2\\nlog-bin=/var/lib/mysql/replica1-bin > /etc/mysql/conf.d/replication.cnf' - docker exec ${{ job.services.db_replica2.id }} sh -c 'echo -e [mysqld]\\nserver-id=3\\nlog-bin=/var/lib/mysql/replica2-bin > /etc/mysql/conf.d/replication.cnf' + docker exec ${{ job.services.db_primary.id }} bash -c 'echo -e [mysqld]\\nserver-id=1\\nlog-bin=/var/lib/mysql/primary-bin > /etc/mysql/conf.d/replication.cnf' + docker exec ${{ job.services.db_replica1.id }} bash -c 'echo -e [mysqld]\\nserver-id=2\\nlog-bin=/var/lib/mysql/replica1-bin > /etc/mysql/conf.d/replication.cnf' + docker exec ${{ job.services.db_replica2.id }} bash -c 'echo -e [mysqld]\\nserver-id=3\\nlog-bin=/var/lib/mysql/replica2-bin > /etc/mysql/conf.d/replication.cnf' docker restart ${{ job.services.db_primary.id }} docker restart ${{ job.services.db_replica1.id }} docker restart ${{ job.services.db_replica2.id }} + - name: Wait for the primary to be healthy + run: | + while ! /usr/bin/docker inspect --format="{{if .Config.Healthcheck}}{{print .State.Health.Status}}{{end}}" ${{ job.services.db_primary.id }} && [[ "$SECONDS" -lt 120 ]]; do sleep 1; done + - name: >- Perform integration testing against Ansible version ${{ matrix.ansible }} diff --git a/Makefile b/Makefile index d320cfe..25a57ce 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ test-integration: --publish 3307:3306 \ --health-cmd 'mysqladmin ping -P 3306 -pmsandbox | grep alive || exit 1' \ $(db_engine_version) \ - mysqld --server-id 1 --log-bin=/var/lib/mysql/primary-bin + mysqld podman run \ --detach \ --name replica1 \ @@ -21,7 +21,7 @@ test-integration: --publish 3308:3306 \ --health-cmd 'mysqladmin ping -P 3306 -pmsandbox | grep alive || exit 1' \ $(db_engine_version) \ - mysqld --server-id 2 --log-bin=/var/lib/mysql/replica1-bin + mysqld podman run \ --detach \ --name replica2 \ @@ -31,7 +31,16 @@ test-integration: --publish 3309:3306 \ --health-cmd 'mysqladmin ping -P 3306 -pmsandbox | grep alive || exit 1' \ $(db_engine_version) \ - mysqld --server-id 3 --log-bin=/var/lib/mysql/replica2-bin + mysqld + # Setup replication and restart containers + podman exec primary bash -c 'echo -e [mysqld]\\nserver-id=1\\nlog-bin=/var/lib/mysql/primary-bin > /etc/mysql/conf.d/replication.cnf' + podman exec replica1 bash -c 'echo -e [mysqld]\\nserver-id=2\\nlog-bin=/var/lib/mysql/replica1-bin > /etc/mysql/conf.d/replication.cnf' + podman exec replica2 bash -c 'echo -e [mysqld]\\nserver-id=3\\nlog-bin=/var/lib/mysql/replica2-bin > /etc/mysql/conf.d/replication.cnf' + # Don't restart a container unless it is healthy + while ! podman healthcheck run primary && [[ "$$SECONDS" -lt 120 ]]; do sleep 1; done + podman restart primary + podman restart replica1 + podman restart replica2 while ! podman healthcheck run primary && [[ "$$SECONDS" -lt 120 ]]; do sleep 1; done -set -x; ansible-test integration $(target) -v --color --coverage --retry-on-error --continue-on-error --diff --docker --docker-network podman --python $(python); set +x rm tests/integration/db_engine_version