about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorRobin Gloster <mail@glob.in>2019-11-24 11:46:27 +0100
committerGitHub <noreply@github.com>2019-11-24 11:46:27 +0100
commit76ad040bb148fc70a54966d427087beb2a9706a7 (patch)
tree654b936273ce2cae80eca39ff8832ca74b1eaa20 /nixos
parentb1e98203069edff196e77ca6cd3da5f7d70343ef (diff)
parent132b7032712ae8e18f3d3d615aa01118c07d2913 (diff)
downloadnixlib-76ad040bb148fc70a54966d427087beb2a9706a7.tar
nixlib-76ad040bb148fc70a54966d427087beb2a9706a7.tar.gz
nixlib-76ad040bb148fc70a54966d427087beb2a9706a7.tar.bz2
nixlib-76ad040bb148fc70a54966d427087beb2a9706a7.tar.lz
nixlib-76ad040bb148fc70a54966d427087beb2a9706a7.tar.xz
nixlib-76ad040bb148fc70a54966d427087beb2a9706a7.tar.zst
nixlib-76ad040bb148fc70a54966d427087beb2a9706a7.zip
Merge pull request #73992 from flokli/nixos-test-port-mysql
nixosTests.mysql*: port to python
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/mysql-backup.nix48
-rw-r--r--nixos/tests/mysql-replication.nix46
-rw-r--r--nixos/tests/mysql.nix26
3 files changed, 70 insertions, 50 deletions
diff --git a/nixos/tests/mysql-backup.nix b/nixos/tests/mysql-backup.nix
index 81482dfef7e5..a0595e4d5539 100644
--- a/nixos/tests/mysql-backup.nix
+++ b/nixos/tests/mysql-backup.nix
@@ -1,5 +1,5 @@
 # Test whether mysqlBackup option works
-import ./make-test.nix ({ pkgs, ... } : {
+import ./make-test-python.nix ({ pkgs, ... } : {
   name = "mysql-backup";
   meta = with pkgs.stdenv.lib.maintainers; {
     maintainers = [ rvl ];
@@ -20,31 +20,37 @@ import ./make-test.nix ({ pkgs, ... } : {
     };
   };
 
-  testScript =
-    '' startAll;
+  testScript = ''
+    start_all()
 
-       # 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");
+    # 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");
+    # Need to have mysql started so that it can be populated with data.
+    master.wait_for_unit("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");
+    # 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"
+    )
 
-       # Do a backup and wait for it to start
-       $master->startJob("mysql-backup.service");
-       $master->waitForJob("mysql-backup.service");
+    # Do a backup and wait for it to start
+    master.start_job("mysql-backup.service")
+    master.wait_for_unit("mysql-backup.service")
 
-       # wait for backup to fail, because of database 'doesnotexist'
-       $master->waitUntilFails("systemctl is-active -q mysql-backup.service");
+    # wait for backup to fail, because of database 'doesnotexist'
+    master.wait_until_fails("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");
+    # 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"
+    )
 
-       # Check that a failed backup is logged
-       $master->succeed("journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null");
-    '';
+    # Check that a failed backup is logged
+    master.succeed(
+        "journalctl -u mysql-backup.service | grep 'fail.*doesnotexist' > /dev/null"
+    )
+  '';
 })
diff --git a/nixos/tests/mysql-replication.nix b/nixos/tests/mysql-replication.nix
index c75a862106f6..a2654f041add 100644
--- a/nixos/tests/mysql-replication.nix
+++ b/nixos/tests/mysql-replication.nix
@@ -1,4 +1,4 @@
-import ./make-test.nix ({ pkgs, ...} :
+import ./make-test-python.nix ({ pkgs, ...} :
 
 let
   replicateUser = "replicate";
@@ -54,28 +54,36 @@ in
   };
 
   testScript = ''
-    $master->start;
-    $master->waitForUnit("mysql");
-    $master->waitForOpenPort(3306);
+    master.start()
+    master.wait_for_unit("mysql")
+    master.wait_for_open_port(3306)
     # 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"
+    )
 
-    $slave1->start;
-    $slave2->start;
-    $slave1->waitForUnit("mysql");
-    $slave1->waitForOpenPort(3306);
-    $slave2->waitForUnit("mysql");
-    $slave2->waitForOpenPort(3306);
+    slave1.start()
+    slave2.start()
+    slave1.wait_for_unit("mysql")
+    slave1.wait_for_open_port(3306)
+    slave2.wait_for_unit("mysql")
+    slave2.wait_for_open_port(3306)
 
     # wait for replications to finish
-    $slave1->waitUntilSucceeds("mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5");
-    $slave2->waitUntilSucceeds("mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5");
+    slave1.wait_until_succeeds(
+        "mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
+    )
+    slave2.wait_until_succeeds(
+        "mysql -u root -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
+    )
 
-    $slave2->succeed("systemctl stop mysql");
-    $master->succeed("echo 'insert into testdb.tests values (123, 456);' | mysql -u root -N");
-    $slave2->succeed("systemctl start mysql");
-    $slave2->waitForUnit("mysql");
-    $slave2->waitForOpenPort(3306);
-    $slave2->waitUntilSucceeds("echo 'select * from testdb.tests where Id = 123;' | mysql -u root -N | grep 456");
+    slave2.succeed("systemctl stop mysql")
+    master.succeed("echo 'insert into testdb.tests values (123, 456);' | mysql -u root -N")
+    slave2.succeed("systemctl start mysql")
+    slave2.wait_for_unit("mysql")
+    slave2.wait_for_open_port(3306)
+    slave2.wait_until_succeeds(
+        "echo 'select * from testdb.tests where Id = 123;' | mysql -u root -N | grep 456"
+    )
   '';
 })
diff --git a/nixos/tests/mysql.nix b/nixos/tests/mysql.nix
index 05bd968de02d..2c0d212c2f1d 100644
--- a/nixos/tests/mysql.nix
+++ b/nixos/tests/mysql.nix
@@ -1,4 +1,4 @@
-import ./make-test.nix ({ pkgs, ...} : {
+import ./make-test-python.nix ({ pkgs, ...} : {
   name = "mysql";
   meta = with pkgs.stdenv.lib.maintainers; {
     maintainers = [ eelco shlevy ];
@@ -47,17 +47,23 @@ import ./make-test.nix ({ pkgs, ...} : {
   };
 
   testScript = ''
-    startAll;
+    start_all
 
-    $mysql->waitForUnit("mysql");
-    $mysql->succeed("echo 'use empty_testdb;' | mysql -u root");
-    $mysql->succeed("echo 'use testdb; select * from tests;' | mysql -u root -N | grep 4");
+    mysql.wait_for_unit("mysql")
+    mysql.succeed("echo 'use empty_testdb;' | mysql -u root")
+    mysql.succeed("echo 'use testdb; select * from tests;' | mysql -u root -N | grep 4")
     # ';' acts as no-op, just check whether login succeeds with the user created from the initialScript
-    $mysql->succeed("echo ';' | mysql -u passworduser --password=password123");
+    mysql.succeed("echo ';' | mysql -u passworduser --password=password123")
 
-    $mariadb->waitForUnit("mysql");
-    $mariadb->succeed("echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser");
-    $mariadb->succeed("echo 'use testdb; insert into tests values (42);' | sudo -u testuser mysql -u testuser");
-    $mariadb->succeed("echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42");
+    mariadb.wait_for_unit("mysql")
+    mariadb.succeed(
+        "echo 'use testdb; create table tests (test_id INT, PRIMARY KEY (test_id));' | sudo -u testuser mysql -u testuser"
+    )
+    mariadb.succeed(
+        "echo 'use testdb; insert into tests values (42);' | sudo -u testuser mysql -u testuser"
+    )
+    mariadb.succeed(
+        "echo 'use testdb; select test_id from tests;' | sudo -u testuser mysql -u testuser -N | grep 42"
+    )
   '';
 })