Debian Codegraph @

debian/tests/smoke

raw symbols SCIP
1 #!/bin/sh
2 # dep8 smoke test for mysql-server
3 # Author: Robie Basak <robie.basak at canonical.com>
4 #
5 # This test should be declared in debian/tests/control with a dependency
6 # on the package that provides a configured MariaDB server (eg.
7 # mariadb-server).
8 #
9 # This test should be declared in debian/tests/control with the
10 # following restrictions:
11 # - allow-stderr (set -x always outputs to stderr)
12 # - needs-root (to be able to log into the database)
13 # - isolation-container (to be able to start service)
14 #
15 # This test:
16 #
17 # 1) Creates a test database and test user as the root user.
18 #
19 # 2) Creates a test table and checks it appears to operate normally
20 # using the test user and test database.
21 #
22 # 3) Checks compression support for InnoDB & RocksDB engine.
23
24 echo "Running test 'smoke'"
25 set -ex
26
27 # Start the daemon if it was not running. For example in Docker testing
28 # environments there might not be any systemd et al and the service needs to
29 # be started manually.
30 if ! command -v systemctl
31 then
32 if ! /etc/init.d/mariadb status
33 then
34 echo "Did not find systemctl and daemon was not running, starting it.."
35 /etc/init.d/mariadb start
36 fi
37 else
38 echo "Found systemctl, continuing smoke test.."
39 # If systemd (and systemctl) is available, but the service did not start, then
40 # this smoke test is supposed to fail with extensive diagnostics output of
41 # that might explain why the service failed to start.
42 systemctl restart mariadb ||
43 {
44 echo "=== Systemd service status ==="
45 systemctl status mariadb.service || true
46 echo "=== Systemd journal ==="
47 journalctl -xeu mariadb.service || true
48 echo "=== MariaDB error log (if exists) ==="
49 cat /var/log/mysql/error.log 2>/dev/null || cat /var/lib/mysql/*.err 2>/dev/null || \
50 cat /var/log/mariadb/error.log 2>/dev/null || cat /var/lib/mariadb/*.err 2>/dev/null || echo "No error log found"
51 echo "=== MariaDB processes ==="
52 # shellcheck disable=SC2009
53 ps aux | grep -i mariadb || true
54 echo "=== data directory contents and permissions ==="
55 find /var/lib/mariadb/ -ls || true
56 find /var/lib/mysql/ -ls || true
57 echo "=== Socket existence ==="
58 find /run/mariadbd/ -ls || true
59 find /run/mysqld/ -ls || true
60 echo "=== AppArmor profile status ==="
61 aa-status 2>/dev/null | grep -A5 -B5 mariadb || true
62 echo "=== AppArmor denials ==="
63 dmesg | grep -i apparmor | grep -i mariadb || true
64 journalctl -k | grep -i apparmor | grep -i mariadb || true
65 echo "=== Start mariadbd directly to capture immediate error ==="
66 timeout 10 /usr/sbin/mariadbd --user=mysql --console 2>&1 || true
67 exit 1
68 }
69 fi
70
71 mariadb <<EOT
72 CREATE DATABASE testdatabase;
73 CREATE USER 'testuser'@'localhost' identified by 'testpassword';
74 GRANT ALL ON testdatabase.* TO 'testuser'@'localhost';
75 EOT
76
77 mariadb testdatabase <<EOT
78 CREATE TABLE foo (bar INTEGER);
79 INSERT INTO foo (bar) VALUES (41);
80 EOT
81
82 result=$(echo 'SELECT bar+1 FROM foo;' | mariadb --batch --skip-column-names --user=testuser --password=testpassword testdatabase)
83 if [ "$result" != "42" ]
84 then
85 echo "Unexpected result" >&2
86 exit 1
87 fi
88
89 mariadb --user=testuser --password=testpassword testdatabase <<EOT
90 DROP TABLE foo;
91 EOT
92
93 mariadb <<EOT
94 DROP DATABASE testdatabase;
95 DROP USER 'testuser'@'localhost';
96 EOT
97
98 # This will never fail but exists purely for debugging purposes in case a later
99 # step would fail
100 mariadb <<EOT
101 SHOW GLOBAL STATUS WHERE Variable_name LIKE 'Innodb_have_%';
102 EOT
103
104 mariadb <<EOT
105 SET GLOBAL innodb_compression_algorithm=lz4;
106 SET GLOBAL innodb_compression_algorithm=lzo;
107 SET GLOBAL innodb_compression_algorithm=lzma;
108 SET GLOBAL innodb_compression_algorithm=bzip2;
109 SET GLOBAL innodb_compression_algorithm=snappy;
110 SET GLOBAL innodb_compression_algorithm=zlib;
111 SET GLOBAL innodb_compression_algorithm=none;
112 EOT
113
114 # Check whether RocksDB should be installed or not
115 plugin=mariadb-plugin-rocksdb
116 if [ "$(dpkg-architecture -qDEB_HOST_ARCH_BITS)" != 32 ] &&
117 [ "$(dpkg-architecture -qDEB_HOST_ARCH_ENDIAN)" = little ]
118 then
119 dpkg-query -W $plugin
120
121 LOG=/var/lib/mariadb/#rocksdb/LOG
122 # XXX: The server may only be started during the install of
123 # mariadb-server, which happens before that of the plugin.
124 [ -e $LOG ] || mariadb -e "INSTALL PLUGIN RocksDB SONAME 'ha_rocksdb';"
125 # XXX: rocksdb_supported_compression_types variable does not report ZSTD.
126
127 # Print RocksDB supported items so test log is easier to debug
128 grep -F " supported:" $LOG
129
130 # Check that the expected compression methods are supported
131 for a in LZ4 Snappy Zlib ZSTD
132 do
133 if ! grep -qE "k$a(Compression)? supported: 1" $LOG
134 then
135 # Fail with explicit error message
136 echo "Error: Compression method $a not supported by RocksDB!" >&2
137 exit 1
138 fi
139 done
140 else
141 if dpkg-query -W $plugin
142 then
143 echo "Error: Plugin $plugin was found even though it should not exist on a 32-bit and little-endian system"
144 exit 1
145 fi
146 fi