Skip to content

Commit

Permalink
Add container test in dbserver for mariadb 10.1->10.2 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Oct 8, 2018
1 parent 5a9f1e3 commit 496c3ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Binary file not shown.
44 changes: 35 additions & 9 deletions containers/ddev-dbserver/test/testserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ function containercheck {
}


# Just to make sure we're starting with a clean environment.
cleanup

echo "Starting image with database image $IMAGE"
if ! docker run -u "$MOUNTUID:$MOUNTGID" -v $VOLUME:/var/lib/mysql --name=$CONTAINER_NAME -p $HOSTPORT:3306 -d $IMAGE; then
echo "MySQL server start failed with error code $?"
exit 2
exit 101
fi

# Now that we've got a container running, we need to make sure to clean up
Expand All @@ -63,18 +62,18 @@ trap cleanup EXIT

echo "Waiting for database server to become ready..."
if ! containercheck; then
exit 1
exit 102
fi
echo "DB Server container started up successfully"

# Try basic connection using root user/password.
if ! mysql --user=root --password=root --database=mysql --host=127.0.0.1 --port=$HOSTPORT -e "SELECT 1;"; then
exit 2;
exit 103
fi

# Test to make sure the db user and database are installed properly
if ! mysql -udb -pdb --database=db --host=127.0.0.1 --port=$HOSTPORT -e "SHOW TABLES;"; then
exit 3
exit 104
fi

# Make sure we have the right mysql version and can query it (and have root user setup)
Expand All @@ -89,7 +88,7 @@ then
echo "Version check ok - found '$MYSQL_VERSION'"
else
echo "Expected to see $versionregex. Actual output: $OUTPUT"
exit 4
exit 105
fi

# With the standard config, our collation should be utf8mb4_bin
Expand All @@ -101,11 +100,11 @@ cleanup
# mysqld will ignore world-writeable config file, so we make it ro for sure
if ! docker run -u "$MOUNTUID:$MOUNTGID" -v $VOLUME:/var/lib/mysql -v /$PWD/test/testdata:/mnt/ddev_config:ro --name=$CONTAINER_NAME -p $HOSTPORT:3306 -d $IMAGE; then
echo "MySQL server start failed with error code $?"
exit 3
exit 106
fi

if ! containercheck; then
exit 5
exit 107
fi

# Make sure the custom config is present in the container.
Expand All @@ -122,7 +121,7 @@ rm -rf $outdir/files/var/tmp/*
docker run -u "$MOUNTUID:$MOUNTGID" -t -v /$outdir://mysqlbase --rm --entrypoint=//create_base_db.sh $IMAGE
if [ ! -f "$outdir/ibdata1" ] ; then
echo "Failed to build test starter database for mariadb."
exit 4
exit 108
fi
command="rm -rf $outdir $MYTMPDIR"
if [ $(uname -s) = "Linux" ] ; then
Expand All @@ -131,5 +130,32 @@ else
$command
fi

cleanup


# Start up with a Mariadb 10.1 database and verify that it gets upgraded successfully to 10.2
docker volume rm $VOLUME && docker volume create $VOLUME
# Populate the volume with the contents of our 10.1 tarball. Here it doesn't matter that
# we're putting it in /var/lib/mysql, but it's put there just for clarity of purpose.
docker run -i --rm -v "$VOLUME:/var/lib/mysql" busybox tar -C /var/lib/mysql -zxf - <test/testdata/d6git_basic_mariadb_10_1.tgz
# Now start up the container with the populated volume
if ! docker run -u "$MOUNTUID:$MOUNTGID" -v "$VOLUME:/var/lib/mysql" --name=$CONTAINER_NAME -d $IMAGE; then
echo "MySQL server start failed with error code $?"
exit 109
fi
containercheck
# Here we should show an upgrade happening because this was a 10.1 database
(docker logs $CONTAINER_NAME 2>&1 | grep "Running mysql_upgrade because my_mariadb_version=10.2 is not the same as db_mariadb_version=10.1" >/dev/null 2>&1) || (echo "Failed to find mysql_upgrade clause in docker logs" && exit 4)

docker stop $CONTAINER_NAME && docker rm $CONTAINER_NAME
# Now run the container again with the same volume (now upgraded) and make sure we don't have the upgrade action
if ! docker run -u "$MOUNTUID:$MOUNTGID" -v "$VOLUME:/var/lib/mysql" --name=$CONTAINER_NAME -d $IMAGE; then
echo "MySQL server start failed with error code $?"
exit 110
fi
containercheck
(docker logs $CONTAINER_NAME 2>&1 | grep -v "Running mysql_upgrade" >/dev/null 2>&1) || (echo "Found mysql_upgrade clause in docker logs when upgrade should not have happened" && exit 6)


echo "Tests passed"
exit 0

0 comments on commit 496c3ab

Please sign in to comment.