about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/mysql-backup.nix
blob: 81482dfef7e5625f624883fab17bf33275cb13a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Test whether mysqlBackup option works
import ./make-test.nix ({ pkgs, ... } : {
  name = "mysql-backup";
  meta = with pkgs.stdenv.lib.maintainers; {
    maintainers = [ rvl ];
  };

  nodes = {
    master = { pkgs, ... }: {
      services.mysql = {
        enable = true;
        initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
        package = pkgs.mysql;
      };

      services.mysqlBackup = {
        enable = true;
        databases = [ "doesnotexist" "testdb" ];
      };
    };
  };

  testScript =
    '' startAll;

       # 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");

       # Need to have mysql started so that it can be populated with data.
       $master->waitForUnit("mysql.service");

       # Wait for testdb to be fully populated (5 rows).
       $master->waitUntilSucceeds("mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5");

       # Do a backup and wait for it to start
       $master->startJob("mysql-backup.service");
       $master->waitForJob("mysql-backup.service");

       # wait for backup to fail, because of database 'doesnotexist'
       $master->waitUntilFails("systemctl is-active -q mysql-backup.service");

       # wait for backup file and check that data appears in backup
       $master->waitForFile("/var/backup/mysql/testdb.gz");
       $master->succeed("${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello");

       # Check that a failed backup is logged
       $master->succeed("journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null");
    '';
})