2021-12-08 19:54:59 +03:00
|
|
|
{
|
|
|
|
system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../../.. { inherit system config; },
|
|
|
|
lib ? pkgs.lib
|
|
|
|
}:
|
2017-09-23 17:58:07 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
let
|
|
|
|
inherit (import ./common.nix { inherit pkgs lib; }) mkTestName mariadbPackages;
|
|
|
|
|
|
|
|
makeTest = import ./../make-test-python.nix;
|
|
|
|
|
|
|
|
makeBackupTest = {
|
|
|
|
package,
|
|
|
|
name ? mkTestName package
|
|
|
|
}: makeTest {
|
|
|
|
name = "${name}-backup";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ rvl ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
master = { pkgs, ... }: {
|
|
|
|
services.mysql = {
|
|
|
|
inherit package;
|
|
|
|
enable = true;
|
|
|
|
initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
|
|
|
|
};
|
2017-09-23 17:58:07 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
services.mysqlBackup = {
|
|
|
|
enable = true;
|
|
|
|
databases = [ "doesnotexist" "testdb" ];
|
|
|
|
};
|
2017-09-23 17:58:07 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
testScript = ''
|
|
|
|
start_all()
|
2017-09-23 17:58:07 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
# Delete backup file that may be left over from a previous test run.
|
|
|
|
# This is not needed on Hydra but useful for repeated local test runs.
|
|
|
|
master.execute("rm -f /var/backup/mysql/testdb.gz")
|
2018-05-12 12:37:35 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
# Need to have mysql started so that it can be populated with data.
|
|
|
|
master.wait_for_unit("mysql.service")
|
2017-09-23 17:58:07 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
# Wait for testdb to be fully populated (5 rows).
|
|
|
|
master.wait_until_succeeds(
|
|
|
|
"mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
|
|
|
|
)
|
2017-09-23 17:58:07 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
# Do a backup and wait for it to start
|
|
|
|
master.start_job("mysql-backup.service")
|
|
|
|
master.wait_for_unit("mysql-backup.service")
|
2017-09-23 17:58:07 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
# wait for backup to fail, because of database 'doesnotexist'
|
|
|
|
master.wait_until_fails("systemctl is-active -q mysql-backup.service")
|
2018-05-12 12:37:35 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
# wait for backup file and check that data appears in backup
|
|
|
|
master.wait_for_file("/var/backup/mysql/testdb.gz")
|
|
|
|
master.succeed(
|
|
|
|
"${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello"
|
|
|
|
)
|
2017-09-23 17:58:07 +03:00
|
|
|
|
2021-12-08 19:54:59 +03:00
|
|
|
# Check that a failed backup is logged
|
|
|
|
master.succeed(
|
|
|
|
"journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null"
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.mapAttrs (_: package: makeBackupTest { inherit package; }) mariadbPackages
|