From 50cc656d60bbbf4968e4a766c9d102a38d0735a5 Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Wed, 18 Sep 2024 14:38:51 +0200 Subject: [PATCH] [CI] Add mariadb backup into mariadb scenario We are not testing mariadb backup, let's test it in mariadb scenario. Change-Id: I81d6ee944b3ed0e75129772bb993ce7a6147c3e8 --- tests/templates/globals-default.j2 | 1 + tests/test-mariadb.sh | 48 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/tests/templates/globals-default.j2 b/tests/templates/globals-default.j2 index 8c5cb8ab84..9d4fb6397d 100644 --- a/tests/templates/globals-default.j2 +++ b/tests/templates/globals-default.j2 @@ -133,6 +133,7 @@ enable_fluentd: "yes" enable_mariadb: "yes" enable_memcached: "no" enable_rabbitmq: "no" +enable_mariabackup: "yes" {% endif %} {% if scenario == "cephadm" %} diff --git a/tests/test-mariadb.sh b/tests/test-mariadb.sh index c5cf5b6a1f..a26b640c49 100755 --- a/tests/test-mariadb.sh +++ b/tests/test-mariadb.sh @@ -30,9 +30,57 @@ function test_recovery { mariadb_recovery } +function test_backup { + echo "Performing full backup" + kolla-ansible -i ${RAW_INVENTORY} -vvv mariadb_backup --full + # Sleep for 30 seconds, not because it's absolutely necessary. + # The full backup is already completed at this point, as the + # ansible job is waiting for the completion of the backup script + # in the container on the controller side. It’s more of an + # attempt at a "sort of" simulation of the usual elapsed time + # since the last full backup for the incremental job, as some + # data gets written within those 30 seconds. + echo "Sleeping for 30 seconds" + sleep 30 + kolla-ansible -i ${RAW_INVENTORY} -vvv mariadb_backup --incremental +} + +function test_backup_with_retries { + # Retry test_backup up to 3 times if it fails + local max_retries=3 + local attempt=1 + + while [[ $attempt -le $max_retries ]]; do + echo "Attempt $attempt of $max_retries for test_backup" + + set +o errexit # Temporarily disable errexit for retry logic + test_backup + result=$? + set -o errexit # Re-enable errexit after the attempt + + if [[ $result -eq 0 ]]; then + echo "test_backup succeeded on attempt $attempt" + return 0 # Exit the function if test_backup succeeds + else + echo "test_backup failed on attempt $attempt" + fi + + if [[ $attempt -lt $max_retries ]]; then + echo "Sleeping for 30 seconds before the next attempt" + sleep 30 # Wait for 30 seconds before retrying + fi + + attempt=$((attempt + 1)) + done + + echo "test_backup failed after $max_retries attempts" + return 1 # Return an error if all attempts fail +} + function test_mariadb_logged { RAW_INVENTORY=/etc/kolla/inventory source $KOLLA_ANSIBLE_VENV_PATH/bin/activate + test_backup_with_retries test_recovery }