2020-04-07 19:20:11 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# dep8 smoke test for mysql-server
|
|
|
|
# Author: Robie Basak <robie.basak at canonical.com>
|
|
|
|
#
|
|
|
|
# This test should be declared in debian/tests/control with a dependency
|
|
|
|
# on the package that provides a configured MariaDB server (eg.
|
|
|
|
# mariadb-server-10.5).
|
|
|
|
#
|
|
|
|
# This test should be declared in debian/tests/control with the
|
|
|
|
# following restrictions:
|
|
|
|
#
|
|
|
|
# needs-root (to be able to log into the database)
|
|
|
|
# allow-stderr
|
|
|
|
#
|
|
|
|
# This test:
|
|
|
|
#
|
|
|
|
# 1) Creates a test database and test user as the root user.
|
|
|
|
#
|
|
|
|
# 2) Creates a test table and checks it appears to operate normally
|
|
|
|
# using the test user and test database.
|
|
|
|
#
|
|
|
|
# 3) Checks compression support for InnoDB & RocksDB engine.
|
|
|
|
|
|
|
|
echo "Running test 'smoke'"
|
|
|
|
set -ex
|
|
|
|
|
2021-03-09 10:27:47 +01:00
|
|
|
# Start the daemon if it was not running. For example in Docker testing
|
2020-04-07 19:20:11 +02:00
|
|
|
# environments there might not be any systemd et al and the service needs to
|
|
|
|
# be started manually.
|
|
|
|
if ! which systemctl
|
|
|
|
then
|
2020-04-26 09:41:21 +02:00
|
|
|
if ! /etc/init.d/mariadb status
|
2020-04-07 19:20:11 +02:00
|
|
|
then
|
2021-05-06 21:08:38 +02:00
|
|
|
echo "Did not find systemctl and daemon was not running, starting it.."
|
2020-04-26 09:41:21 +02:00
|
|
|
/etc/init.d/mariadb start
|
2020-04-07 19:20:11 +02:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
# If systemd (and systemctl) is available, but the service did not start, then
|
|
|
|
# this smoke test is supposed to fail if next commands don't work.
|
|
|
|
echo "Found systemctl, continuing smoke test.."
|
|
|
|
fi
|
|
|
|
|
|
|
|
mysql <<EOT
|
|
|
|
CREATE DATABASE testdatabase;
|
|
|
|
CREATE USER 'testuser'@'localhost' identified by 'testpassword';
|
|
|
|
GRANT ALL ON testdatabase.* TO 'testuser'@'localhost';
|
|
|
|
EOT
|
|
|
|
|
|
|
|
mysql testdatabase <<EOT
|
|
|
|
CREATE TABLE foo (bar INTEGER);
|
|
|
|
INSERT INTO foo (bar) VALUES (41);
|
|
|
|
EOT
|
|
|
|
|
|
|
|
result=$(echo 'SELECT bar+1 FROM foo;'|mysql --batch --skip-column-names --user=testuser --password=testpassword testdatabase)
|
|
|
|
if [ "$result" != "42" ]; then
|
|
|
|
echo "Unexpected result" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mysql --user=testuser --password=testpassword testdatabase <<EOT
|
|
|
|
DROP TABLE foo;
|
|
|
|
EOT
|
|
|
|
|
|
|
|
mysql <<EOT
|
|
|
|
DROP DATABASE testdatabase;
|
|
|
|
DROP USER 'testuser'@'localhost';
|
|
|
|
EOT
|
|
|
|
|
2021-03-09 10:27:47 +01:00
|
|
|
# List based on what is advertised at
|
|
|
|
# https://mariadb.com/kb/en/innodb-page-compression/#configuring-the-innodb-page-compression-algorithm
|
|
|
|
# but disabled with '#' the options that are not available in this binary build
|
|
|
|
mariadb <<EOT
|
2020-04-07 19:20:11 +02:00
|
|
|
SET GLOBAL innodb_compression_algorithm=lz4;
|
2021-03-09 10:27:47 +01:00
|
|
|
#SET GLOBAL innodb_compression_algorithm=lzo;
|
|
|
|
#SET GLOBAL innodb_compression_algorithm=lzma;
|
|
|
|
#SET GLOBAL innodb_compression_algorithm=bzip2;
|
|
|
|
#SET GLOBAL innodb_compression_algorithm=snappy;
|
2020-04-07 19:20:11 +02:00
|
|
|
SET GLOBAL innodb_compression_algorithm=zlib;
|
|
|
|
SET GLOBAL innodb_compression_algorithm=none;
|
|
|
|
EOT
|
|
|
|
|
2021-03-09 10:27:47 +01:00
|
|
|
# Check whether RocksDB should be installed or not
|
2020-04-07 19:20:11 +02:00
|
|
|
plugin=mariadb-plugin-rocksdb
|
|
|
|
if [ "$(dpkg-architecture -qDEB_HOST_ARCH_BITS)" != 32 ] &&
|
2021-03-09 10:27:47 +01:00
|
|
|
[ "$(dpkg-architecture -qDEB_HOST_ARCH_ENDIAN)" = little ]
|
|
|
|
then
|
2020-04-07 19:20:11 +02:00
|
|
|
dpkg-query -W $plugin
|
|
|
|
|
|
|
|
LOG=/var/lib/mysql/#rocksdb/LOG
|
|
|
|
# XXX: The server may only be started during the install of
|
|
|
|
# mariadb-server-10.5, which happens before that of the plugin.
|
|
|
|
[ -e $LOG ] || mysql -e "INSTALL PLUGIN RocksDB SONAME 'ha_rocksdb';"
|
|
|
|
# XXX: rocksdb_supported_compression_types variable does not report ZSTD.
|
2021-03-09 10:27:47 +01:00
|
|
|
|
|
|
|
# Print RocksDB supported items so test log is easier to debug
|
|
|
|
grep -F " supported:" $LOG
|
|
|
|
|
|
|
|
# Check that the expected compression methods are supported
|
2020-04-07 19:20:11 +02:00
|
|
|
for a in LZ4 Snappy Zlib ZSTD; do
|
2021-03-09 10:27:47 +01:00
|
|
|
if ! grep -qE "k$a(Compression)? supported: 1" $LOG
|
|
|
|
then
|
|
|
|
# Fail with explicit error message
|
|
|
|
echo "Error: Compression method $a not supported by RocksDB!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-04-07 19:20:11 +02:00
|
|
|
done
|
|
|
|
else
|
|
|
|
! dpkg-query -W $plugin
|
|
|
|
fi
|