1import ./../make-test-python.nix ({ pkgs, ...} :
2
3let
4 mysqlenv-common = pkgs.buildEnv { name = "mysql-path-env-common"; pathsToLink = [ "/bin" ]; paths = with pkgs; [ bash gawk gnutar inetutils which ]; };
5 mysqlenv-rsync = pkgs.buildEnv { name = "mysql-path-env-rsync"; pathsToLink = [ "/bin" ]; paths = with pkgs; [ lsof procps rsync stunnel ]; };
6
7in {
8 name = "mariadb-galera-rsync";
9 meta = with pkgs.lib.maintainers; {
10 maintainers = [ izorkin ];
11 };
12
13 # The test creates a Galera cluster with 3 nodes and is checking if rsync-based SST works. The cluster is tested by creating a DB and an empty table on one node,
14 # and checking the table's presence on the other node.
15
16 nodes = {
17 galera_04 =
18 { pkgs, ... }:
19 {
20 networking = {
21 interfaces.eth1 = {
22 ipv4.addresses = [
23 { address = "192.168.2.1"; prefixLength = 24; }
24 ];
25 };
26 extraHosts = ''
27 192.168.2.1 galera_04
28 192.168.2.2 galera_05
29 192.168.2.3 galera_06
30 '';
31 firewall.allowedTCPPorts = [ 3306 4444 4567 4568 ];
32 firewall.allowedUDPPorts = [ 4567 ];
33 };
34 users.users.testuser = { isSystemUser = true; };
35 systemd.services.mysql = with pkgs; {
36 path = [ mysqlenv-common mysqlenv-rsync ];
37 };
38 services.mysql = {
39 enable = true;
40 package = pkgs.mariadb;
41 ensureDatabases = [ "testdb" ];
42 ensureUsers = [{
43 name = "testuser";
44 ensurePermissions = {
45 "testdb.*" = "ALL PRIVILEGES";
46 };
47 }];
48 settings = {
49 mysqld = {
50 bind_address = "0.0.0.0";
51 };
52 galera = {
53 wsrep_on = "ON";
54 wsrep_debug = "NONE";
55 wsrep_retry_autocommit = "3";
56 wsrep_provider = "${pkgs.mariadb-galera}/lib/galera/libgalera_smm.so";
57 wsrep_cluster_address = "gcomm://";
58 wsrep_cluster_name = "galera-rsync";
59 wsrep_node_address = "192.168.2.1";
60 wsrep_node_name = "galera_04";
61 wsrep_sst_method = "rsync";
62 binlog_format = "ROW";
63 enforce_storage_engine = "InnoDB";
64 innodb_autoinc_lock_mode = "2";
65 };
66 };
67 };
68 };
69
70 galera_05 =
71 { pkgs, ... }:
72 {
73 networking = {
74 interfaces.eth1 = {
75 ipv4.addresses = [
76 { address = "192.168.2.2"; prefixLength = 24; }
77 ];
78 };
79 extraHosts = ''
80 192.168.2.1 galera_04
81 192.168.2.2 galera_05
82 192.168.2.3 galera_06
83 '';
84 firewall.allowedTCPPorts = [ 3306 4444 4567 4568 ];
85 firewall.allowedUDPPorts = [ 4567 ];
86 };
87 users.users.testuser = { isSystemUser = true; };
88 systemd.services.mysql = with pkgs; {
89 path = [ mysqlenv-common mysqlenv-rsync ];
90 };
91 services.mysql = {
92 enable = true;
93 package = pkgs.mariadb;
94 settings = {
95 mysqld = {
96 bind_address = "0.0.0.0";
97 };
98 galera = {
99 wsrep_on = "ON";
100 wsrep_debug = "NONE";
101 wsrep_retry_autocommit = "3";
102 wsrep_provider = "${pkgs.mariadb-galera}/lib/galera/libgalera_smm.so";
103 wsrep_cluster_address = "gcomm://galera_04,galera_05,galera_06";
104 wsrep_cluster_name = "galera-rsync";
105 wsrep_node_address = "192.168.2.2";
106 wsrep_node_name = "galera_05";
107 wsrep_sst_method = "rsync";
108 binlog_format = "ROW";
109 enforce_storage_engine = "InnoDB";
110 innodb_autoinc_lock_mode = "2";
111 };
112 };
113 };
114 };
115
116 galera_06 =
117 { pkgs, ... }:
118 {
119 networking = {
120 interfaces.eth1 = {
121 ipv4.addresses = [
122 { address = "192.168.2.3"; prefixLength = 24; }
123 ];
124 };
125 extraHosts = ''
126 192.168.2.1 galera_04
127 192.168.2.2 galera_05
128 192.168.2.3 galera_06
129 '';
130 firewall.allowedTCPPorts = [ 3306 4444 4567 4568 ];
131 firewall.allowedUDPPorts = [ 4567 ];
132 };
133 users.users.testuser = { isSystemUser = true; };
134 systemd.services.mysql = with pkgs; {
135 path = [ mysqlenv-common mysqlenv-rsync ];
136 };
137 services.mysql = {
138 enable = true;
139 package = pkgs.mariadb;
140 settings = {
141 mysqld = {
142 bind_address = "0.0.0.0";
143 };
144 galera = {
145 wsrep_on = "ON";
146 wsrep_debug = "NONE";
147 wsrep_retry_autocommit = "3";
148 wsrep_provider = "${pkgs.mariadb-galera}/lib/galera/libgalera_smm.so";
149 wsrep_cluster_address = "gcomm://galera_04,galera_05,galera_06";
150 wsrep_cluster_name = "galera-rsync";
151 wsrep_node_address = "192.168.2.3";
152 wsrep_node_name = "galera_06";
153 wsrep_sst_method = "rsync";
154 binlog_format = "ROW";
155 enforce_storage_engine = "InnoDB";
156 innodb_autoinc_lock_mode = "2";
157 };
158 };
159 };
160 };
161 };
162
163 testScript = ''
164 galera_04.start()
165 galera_04.wait_for_unit("mysql")
166 galera_04.wait_for_open_port(3306)
167 galera_04.succeed(
168 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db1 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
169 )
170 galera_04.succeed(
171 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db1 values (41);'"
172 )
173 galera_05.start()
174 galera_05.wait_for_unit("mysql")
175 galera_05.wait_for_open_port(3306)
176 galera_06.start()
177 galera_06.wait_for_unit("mysql")
178 galera_06.wait_for_open_port(3306)
179 galera_05.succeed(
180 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 41"
181 )
182 galera_05.succeed(
183 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db2 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
184 )
185 galera_05.succeed("systemctl stop mysql")
186 galera_04.succeed(
187 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db2 values (42);'"
188 )
189 galera_06.succeed(
190 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db3 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
191 )
192 galera_04.succeed(
193 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db3 values (43);'"
194 )
195 galera_05.succeed("systemctl start mysql")
196 galera_05.wait_for_open_port(3306)
197 galera_05.succeed(
198 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_cluster_size.*3'"
199 )
200 galera_06.succeed(
201 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_local_state_comment.*Synced'"
202 )
203 galera_04.succeed(
204 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db3;' -N | grep 43"
205 )
206 galera_05.succeed(
207 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db2;' -N | grep 42"
208 )
209 galera_06.succeed(
210 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 41"
211 )
212 galera_04.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db3;'")
213 galera_05.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db2;'")
214 galera_06.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db1;'")
215 '';
216})