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