1# Test whether mysqlBackup option works
2import ./../make-test-python.nix ({ pkgs, ... } : {
3 name = "mysql-backup";
4 meta = with pkgs.lib.maintainers; {
5 maintainers = [ rvl ];
6 };
7
8 nodes = {
9 master = { pkgs, ... }: {
10 services.mysql = {
11 enable = true;
12 initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
13 package = pkgs.mariadb;
14 };
15
16 services.mysqlBackup = {
17 enable = true;
18 databases = [ "doesnotexist" "testdb" ];
19 };
20 };
21 };
22
23 testScript = ''
24 start_all()
25
26 # Delete backup file that may be left over from a previous test run.
27 # This is not needed on Hydra but useful for repeated local test runs.
28 master.execute("rm -f /var/backup/mysql/testdb.gz")
29
30 # Need to have mysql started so that it can be populated with data.
31 master.wait_for_unit("mysql.service")
32
33 # Wait for testdb to be fully populated (5 rows).
34 master.wait_until_succeeds(
35 "mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
36 )
37
38 # Do a backup and wait for it to start
39 master.start_job("mysql-backup.service")
40 master.wait_for_unit("mysql-backup.service")
41
42 # wait for backup to fail, because of database 'doesnotexist'
43 master.wait_until_fails("systemctl is-active -q mysql-backup.service")
44
45 # wait for backup file and check that data appears in backup
46 master.wait_for_file("/var/backup/mysql/testdb.gz")
47 master.succeed(
48 "${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello"
49 )
50
51 # Check that a failed backup is logged
52 master.succeed(
53 "journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null"
54 )
55 '';
56})