diff --git a/10.1/root/usr/bin/run-mysqld b/10.1/root/usr/bin/run-mysqld index cd899a73..f52ab709 100755 --- a/10.1/root/usr/bin/run-mysqld +++ b/10.1/root/usr/bin/run-mysqld @@ -26,6 +26,10 @@ if [ -f ${CONTAINER_SCRIPTS_PATH}/post-init.sh ]; then log_info 'Sourcing post-init.sh ...' source ${CONTAINER_SCRIPTS_PATH}/post-init.sh fi +if [ -f ${CONTAINER_SCRIPTS_PATH}/check-upgrade.sh ]; then + log_info 'Sourcing check-upgrade.sh ...' + source ${CONTAINER_SCRIPTS_PATH}/check-upgrade.sh +fi # Restart the MySQL server with public IP bindings shutdown_local_mysql diff --git a/10.1/root/usr/bin/run-mysqld-master b/10.1/root/usr/bin/run-mysqld-master index 054889e4..73544fce 100755 --- a/10.1/root/usr/bin/run-mysqld-master +++ b/10.1/root/usr/bin/run-mysqld-master @@ -39,8 +39,14 @@ mysql $mysql_flags < "${upgrade_info_file}" + log_info "Storing version '${version}' information into the data dir '${upgrade_info_file}'" +} diff --git a/10.1/test/run b/10.1/test/run index df157156..5984ac74 100755 --- a/10.1/test/run +++ b/10.1/test/run @@ -62,7 +62,7 @@ function test_connection() { local ip ip=$(get_container_ip $name) echo " Testing MySQL connection to $ip..." - local max_attempts=20 + local max_attempts=8 local sleep_time=2 local i for i in $(seq $max_attempts); do @@ -412,6 +412,87 @@ run_doc_test() { echo } +function run_upgrade_test() { + local tmpdir=$(mktemp -d) + mkdir "${tmpdir}/data" && chmod -R a+rwx "${tmpdir}" + + # Create MySQL container with persistent volume and set the version from too old version + create_container "testupg1" -e MYSQL_USER=user -e MYSQL_PASSWORD=foo \ + -e MYSQL_DATABASE=db -v ${tmpdir}:/var/lib/mysql/data:Z + test_connection testupg1 user foo + docker stop $(get_cid testupg1) >/dev/null + + # Create version file that is too old + echo "5.0.12" >${tmpdir}/mysql_upgrade_info + + # Create another container with same data and upgrade set to 'auto' + create_container "testupg2" -e MYSQL_USER=user -e MYSQL_PASSWORD=foo \ + -e MYSQL_DATABASE=db -v ${tmpdir}:/var/lib/mysql/data:Z -e MYSQL_UPGRADE=auto + test_connection testupg2 user foo + docker stop $(get_cid testupg2) >/dev/null + + # Check whether some upgrade happened + if docker logs $(get_cid testupg2) | grep 'Checking and upgrading mysql database' &>/dev/null ; then + echo "Upgrade happened but it should not when upgrading from too old version" + return 1 + fi + + # Create version file that we can upgrade from + echo "10.0.12" >${tmpdir}/mysql_upgrade_info + + # Create another container with same data and upgrade set to 'auto' + create_container "testupg3" -e MYSQL_USER=user -e MYSQL_PASSWORD=foo \ + -e MYSQL_DATABASE=db -v ${tmpdir}:/var/lib/mysql/data:Z -e MYSQL_UPGRADE=auto + test_connection testupg3 user foo + docker stop $(get_cid testupg3) >/dev/null + + # Check whether some upgrade happened + if ! docker logs $(get_cid testupg3) | grep 'Checking and upgrading mysql database' &>/dev/null ; then + echo "Upgrade did not happen but it should when upgrading from previous version" + return 1 + fi + + # Create version file that we don't need to upgrade from + echo "10.1.12" >${tmpdir}/mysql_upgrade_info + + # Create another container with same data and upgrade set to 'auto' + create_container "testupg4" -e MYSQL_USER=user -e MYSQL_PASSWORD=foo \ + -e MYSQL_DATABASE=db -v ${tmpdir}:/var/lib/mysql/data:Z -e MYSQL_UPGRADE=auto + test_connection testupg4 user foo + docker stop $(get_cid testupg4) >/dev/null + + # Check whether some upgrade happened + if docker logs $(get_cid testupg4) | grep 'Checking and upgrading mysql database' &>/dev/null ; then + echo "Upgrade happened but it should not when upgrading from current version" + return 1 + fi + + # Create second container with same data and upgrade set to 'analyze' + create_container "testupg5" -e MYSQL_USER=user -e MYSQL_PASSWORD=foo \ + -e MYSQL_DATABASE=db -v ${tmpdir}:/var/lib/mysql/data:Z -e MYSQL_UPGRADE=analyze + test_connection testupg5 user foo + docker stop $(get_cid testupg5) >/dev/null + + # Check whether analyze happened + if ! docker logs $(get_cid testupg5) | grep -e '--analyze --all-databases' &>/dev/null ; then + echo "Analyze did not happen but it should" + return 1 + fi + + # Create another container with same data and upgrade set to 'optimize' + create_container "testupg6" -e MYSQL_USER=user -e MYSQL_PASSWORD=foo \ + -e MYSQL_DATABASE=db -v ${tmpdir}:/var/lib/mysql/data:Z -e MYSQL_UPGRADE=optimize + test_connection testupg6 user foo + docker stop $(get_cid testupg6) >/dev/null + + # Check whether optimize happened + if ! docker logs $(get_cid testupg6) | grep -e '--optimize --all-databases' &>/dev/null ; then + echo "Optimize did not happen but it should" + return 1 + fi + +} + # Tests. run_container_creation_tests @@ -434,4 +515,8 @@ run_change_password_test # Replication tests run_replication_test +# Documentation tests run_doc_test + +# Upgrade, optimaze and analyze tests +run_upgrade_test