2021-12-08 16:47:42 +01:00
|
|
|
{
|
|
|
|
system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../../.. { inherit system config; },
|
|
|
|
lib ? pkgs.lib
|
|
|
|
}:
|
2011-07-13 22:58:48 +02:00
|
|
|
|
|
|
|
let
|
2021-12-08 16:47:42 +01:00
|
|
|
inherit (import ./common.nix { inherit pkgs lib; }) mkTestName mariadbPackages;
|
|
|
|
|
2011-07-13 22:58:48 +02:00
|
|
|
replicateUser = "replicate";
|
|
|
|
replicatePassword = "secret";
|
2014-04-14 14:02:44 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
makeTest = import ./../make-test-python.nix;
|
2014-06-28 16:04:49 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
makeReplicationTest = {
|
|
|
|
package,
|
|
|
|
name ? mkTestName package,
|
|
|
|
}: makeTest {
|
|
|
|
name = "${name}-replication";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ ajs124 das_j ];
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
nodes = {
|
|
|
|
primary = {
|
|
|
|
services.mysql = {
|
|
|
|
inherit package;
|
|
|
|
enable = true;
|
|
|
|
replication.role = "master";
|
|
|
|
replication.slaveHost = "%";
|
|
|
|
replication.masterUser = replicateUser;
|
|
|
|
replication.masterPassword = replicatePassword;
|
|
|
|
initialDatabases = [ { name = "testdb"; schema = ./testdb.sql; } ];
|
|
|
|
};
|
2014-04-11 17:15:56 +02:00
|
|
|
networking.firewall.allowedTCPPorts = [ 3306 ];
|
2011-07-13 22:58:48 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
secondary1 = { nodes, ... }: {
|
|
|
|
services.mysql = {
|
|
|
|
inherit package;
|
|
|
|
enable = true;
|
|
|
|
replication.role = "slave";
|
|
|
|
replication.serverId = 2;
|
2023-05-10 18:13:38 +02:00
|
|
|
replication.masterHost = nodes.primary.networking.hostName;
|
2021-12-08 16:47:42 +01:00
|
|
|
replication.masterUser = replicateUser;
|
|
|
|
replication.masterPassword = replicatePassword;
|
|
|
|
};
|
2011-07-13 22:58:48 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
secondary2 = { nodes, ... }: {
|
|
|
|
services.mysql = {
|
|
|
|
inherit package;
|
|
|
|
enable = true;
|
|
|
|
replication.role = "slave";
|
|
|
|
replication.serverId = 3;
|
2023-05-10 18:13:38 +02:00
|
|
|
replication.masterHost = nodes.primary.networking.hostName;
|
2021-12-08 16:47:42 +01:00
|
|
|
replication.masterUser = replicateUser;
|
|
|
|
replication.masterPassword = replicatePassword;
|
|
|
|
};
|
2011-07-13 22:58:48 +02:00
|
|
|
};
|
2021-12-08 16:47:42 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
testScript = ''
|
|
|
|
primary.start()
|
|
|
|
primary.wait_for_unit("mysql")
|
|
|
|
primary.wait_for_open_port(3306)
|
|
|
|
# Wait for testdb to be fully populated (5 rows).
|
|
|
|
primary.wait_until_succeeds(
|
|
|
|
"sudo -u mysql mysql -u mysql -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
|
|
|
|
)
|
2018-05-22 01:22:12 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
secondary1.start()
|
|
|
|
secondary2.start()
|
|
|
|
secondary1.wait_for_unit("mysql")
|
|
|
|
secondary1.wait_for_open_port(3306)
|
|
|
|
secondary2.wait_for_unit("mysql")
|
|
|
|
secondary2.wait_for_open_port(3306)
|
2018-05-22 01:22:12 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
# wait for replications to finish
|
|
|
|
secondary1.wait_until_succeeds(
|
|
|
|
"sudo -u mysql mysql -u mysql -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
|
|
|
|
)
|
|
|
|
secondary2.wait_until_succeeds(
|
|
|
|
"sudo -u mysql mysql -u mysql -D testdb -N -B -e 'select count(id) from tests' | grep -q 5"
|
|
|
|
)
|
2018-05-22 01:22:12 +02:00
|
|
|
|
2021-12-08 16:47:42 +01:00
|
|
|
secondary2.succeed("systemctl stop mysql")
|
|
|
|
primary.succeed(
|
|
|
|
"echo 'insert into testdb.tests values (123, 456);' | sudo -u mysql mysql -u mysql -N"
|
|
|
|
)
|
|
|
|
secondary2.succeed("systemctl start mysql")
|
|
|
|
secondary2.wait_for_unit("mysql")
|
|
|
|
secondary2.wait_for_open_port(3306)
|
|
|
|
secondary2.wait_until_succeeds(
|
|
|
|
"echo 'select * from testdb.tests where Id = 123;' | sudo -u mysql mysql -u mysql -N | grep 456"
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
lib.mapAttrs (_: package: makeReplicationTest { inherit package; }) mariadbPackages
|