nixosTests.mysqlBackup: port to python

This commit is contained in:
Florian Klink 2019-11-23 23:48:12 +01:00
parent ced69719cd
commit 132b703271

View File

@ -1,5 +1,5 @@
# Test whether mysqlBackup option works # Test whether mysqlBackup option works
import ./make-test.nix ({ pkgs, ... } : { import ./make-test-python.nix ({ pkgs, ... } : {
name = "mysql-backup"; name = "mysql-backup";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ rvl ]; maintainers = [ rvl ];
@ -20,31 +20,37 @@ import ./make-test.nix ({ pkgs, ... } : {
}; };
}; };
testScript = testScript = ''
'' startAll; start_all()
# Delete backup file that may be left over from a previous test run. # 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. # This is not needed on Hydra but useful for repeated local test runs.
$master->execute("rm -f /var/backup/mysql/testdb.gz"); master.execute("rm -f /var/backup/mysql/testdb.gz")
# Need to have mysql started so that it can be populated with data. # Need to have mysql started so that it can be populated with data.
$master->waitForUnit("mysql.service"); master.wait_for_unit("mysql.service")
# Wait for testdb to be fully populated (5 rows). # 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"); master.wait_until_succeeds(
"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 # Do a backup and wait for it to start
$master->startJob("mysql-backup.service"); master.start_job("mysql-backup.service")
$master->waitForJob("mysql-backup.service"); master.wait_for_unit("mysql-backup.service")
# wait for backup to fail, because of database 'doesnotexist' # wait for backup to fail, because of database 'doesnotexist'
$master->waitUntilFails("systemctl is-active -q mysql-backup.service"); master.wait_until_fails("systemctl is-active -q mysql-backup.service")
# wait for backup file and check that data appears in backup # wait for backup file and check that data appears in backup
$master->waitForFile("/var/backup/mysql/testdb.gz"); master.wait_for_file("/var/backup/mysql/testdb.gz")
$master->succeed("${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello"); master.succeed(
"${pkgs.gzip}/bin/zcat /var/backup/mysql/testdb.gz | grep hello"
)
# Check that a failed backup is logged # Check that a failed backup is logged
$master->succeed("journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null"); master.succeed(
''; "journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null"
)
'';
}) })