2021-12-08 15:47:42 +00:00
|
|
|
{
|
|
|
|
system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../../.. { inherit system config; },
|
|
|
|
lib ? pkgs.lib
|
|
|
|
}:
|
2011-07-13 20:58:48 +00:00
|
|
|
|
|
|
|
let
|
2021-12-08 15:47:42 +00:00
|
|
|
inherit (import ./common.nix { inherit pkgs lib; }) mkTestName mariadbPackages;
|
|
|
|
|
2011-07-13 20:58:48 +00:00
|
|
|
replicateUser = "replicate";
|
|
|
|
replicatePassword = "secret";
|
2014-04-14 12:02:44 +00:00
|
|
|
|
2021-12-08 15:47:42 +00:00
|
|
|
makeTest = import ./../make-test-python.nix;
|
2014-06-28 14:04:49 +00:00
|
|
|
|
2021-12-08 15:47:42 +00:00
|
|
|
makeReplicationTest = {
|
|
|
|
package,
|
|
|
|
name ? mkTestName package,
|
|
|
|
}: makeTest {
|
|
|
|
name = "${name}-replication";
|
2023-11-17 12:35:31 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.helsinki-systems.members;
|
2021-12-08 15:47:42 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2021-12-08 15:47:42 +00: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 15:15:56 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [ 3306 ];
|
2011-07-13 20:58:48 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2021-12-08 15:47:42 +00:00
|
|
|
secondary1 = { nodes, ... }: {
|
|
|
|
services.mysql = {
|
|
|
|
inherit package;
|
|
|
|
enable = true;
|
|
|
|
replication.role = "slave";
|
|
|
|
replication.serverId = 2;
|
2023-05-10 16:13:38 +00:00
|
|
|
replication.masterHost = nodes.primary.networking.hostName;
|
2021-12-08 15:47:42 +00:00
|
|
|
replication.masterUser = replicateUser;
|
|
|
|
replication.masterPassword = replicatePassword;
|
|
|
|
};
|
2011-07-13 20:58:48 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2021-12-08 15:47:42 +00:00
|
|
|
secondary2 = { nodes, ... }: {
|
|
|
|
services.mysql = {
|
|
|
|
inherit package;
|
|
|
|
enable = true;
|
|
|
|
replication.role = "slave";
|
|
|
|
replication.serverId = 3;
|
2023-05-10 16:13:38 +00:00
|
|
|
replication.masterHost = nodes.primary.networking.hostName;
|
2021-12-08 15:47:42 +00:00
|
|
|
replication.masterUser = replicateUser;
|
|
|
|
replication.masterPassword = replicatePassword;
|
|
|
|
};
|
2011-07-13 20:58:48 +00:00
|
|
|
};
|
2021-12-08 15:47:42 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2021-12-08 15:47:42 +00: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-21 23:22:12 +00:00
|
|
|
|
2021-12-08 15:47:42 +00: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-21 23:22:12 +00:00
|
|
|
|
2021-12-08 15:47:42 +00: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-21 23:22:12 +00:00
|
|
|
|
2021-12-08 15:47:42 +00: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
|