diff --git a/testsuite/podman_runner/07_manager_setup.sh b/testsuite/podman_runner/07_manager_setup.sh index 74fe4ff88fac..43432e0820ce 100755 --- a/testsuite/podman_runner/07_manager_setup.sh +++ b/testsuite/podman_runner/07_manager_setup.sh @@ -8,12 +8,13 @@ sudo -i podman exec uyuni-server-all-in-one-test bash -c "/usr/bin/spacewalk-sch # Make sure latest sql migration scripts have been executed for both the main and the reporting database available_schemas=("spacewalk" "reportdb") -for schema in ${available_schemas[@]}; do - specfile=$(find ${src_dir}/schema/${schema}/ -name *.spec) - # Use Perl extended regexp and look-around assertions to extract only the values from the spec properties - schema_name=$(grep -oP "Name:\s+\K(.*)$" ${specfile}) - schema_version=$(grep -oP "Version:\s+\K(.*)$" ${specfile}) +for schema in "${available_schemas[@]}"; do + specfile=$(find "${src_dir}/schema/${schema}/" -name '*.spec') + # Get the package name from the spec using Perl extended regexp and look-around assertions to extract only its value + schema_name=$(grep -oP "Name:\s+\K(.*)$" "${specfile}") + # Check the version of the package installed in the podman container + schema_version=$(sudo -i podman exec uyuni-server-all-in-one-test rpm -q --queryformat '%{version}' "${schema_name}") + # Run the missing migrations and only those, to ensure no script is out of place sudo -i podman exec uyuni-server-all-in-one-test bash -c "/testsuite/podman_runner/run_db_migrations.sh ${schema_name} ${schema_version}" done - diff --git a/testsuite/podman_runner/run_db_migrations.sh b/testsuite/podman_runner/run_db_migrations.sh index 1b36fa2eef59..cac85f0f1641 100755 --- a/testsuite/podman_runner/run_db_migrations.sh +++ b/testsuite/podman_runner/run_db_migrations.sh @@ -22,7 +22,10 @@ else exit 1 fi -for i in $(find ${upgrade_dir} -name "$1-$2-to-*"); do +# Including all sub-folders of the upgrade dir that comes after the one called "${schema_name}-${schema_version}-to-..." +# This should make sure we apply all the scripts meant to be executed on top of the current schema version. +# It probably won't happen often that we have multiple pending directories, but it could happen in case of re-tagging +for i in $(find ${upgrade_dir} -name "$1-*-to-*" | sed -n "/$1-$2-to-.*$/,$ p"); do echo $(basename $i) for j in $(find $i -name *.sql); do echo -e "\t$(basename $j)"; spacewalk-sql ${additional_params} $j | sed 's/^/\t\t/';