2020-04-05 19:58:27 +01:00
import ./../make-test-python.nix ( { pkgs , . . . } :
let
mysqlenv-common = pkgs . buildEnv { name = " m y s q l - p a t h - e n v - c o m m o n " ; pathsToLink = [ " / b i n " ] ; paths = with pkgs ; [ bash gawk gnutar inetutils which ] ; } ;
mysqlenv-rsync = pkgs . buildEnv { name = " m y s q l - p a t h - e n v - r s y n c " ; pathsToLink = [ " / b i n " ] ; paths = with pkgs ; [ lsof procps rsync stunnel ] ; } ;
in {
name = " m a r i a d b - g a l e r a - r s y n c " ;
2021-01-10 19:08:30 +00:00
meta = with pkgs . lib . maintainers ; {
2020-04-05 19:58:27 +01:00
maintainers = [ izorkin ] ;
} ;
# 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,
# and checking the table's presence on the other node.
nodes = {
galera_04 =
{ pkgs , . . . }:
{
networking = {
interfaces . eth1 = {
ipv4 . addresses = [
{ address = " 1 9 2 . 1 6 8 . 2 . 1 " ; prefixLength = 24 ; }
] ;
} ;
extraHosts = ''
192 .168 .2 .1 galera_04
192 .168 .2 .2 galera_05
192 .168 .2 .3 galera_06
'' ;
firewall . allowedTCPPorts = [ 3306 4444 4567 4568 ] ;
firewall . allowedUDPPorts = [ 4567 ] ;
} ;
2021-03-07 13:54:00 +00:00
users . users . testuser = { isSystemUser = true ; } ;
2020-04-05 19:58:27 +01:00
systemd . services . mysql = with pkgs ; {
path = [ mysqlenv-common mysqlenv-rsync ] ;
} ;
services . mysql = {
enable = true ;
package = pkgs . mariadb ;
ensureDatabases = [ " t e s t d b " ] ;
ensureUsers = [ {
name = " t e s t u s e r " ;
ensurePermissions = {
" t e s t d b . * " = " A L L P R I V I L E G E S " ;
} ;
} ] ;
settings = {
mysqld = {
bind_address = " 0 . 0 . 0 . 0 " ;
} ;
galera = {
wsrep_on = " O N " ;
2020-05-07 19:30:25 +01:00
wsrep_debug = " N O N E " ;
2020-04-05 19:58:27 +01:00
wsrep_retry_autocommit = " 3 " ;
2020-05-05 07:30:54 +01:00
wsrep_provider = " ${ pkgs . mariadb-galera } / l i b / g a l e r a / l i b g a l e r a _ s m m . s o " ;
2020-04-05 19:58:27 +01:00
wsrep_cluster_address = " g c o m m : / / " ;
wsrep_cluster_name = " g a l e r a - r s y n c " ;
wsrep_node_address = " 1 9 2 . 1 6 8 . 2 . 1 " ;
wsrep_node_name = " g a l e r a _ 0 4 " ;
wsrep_sst_method = " r s y n c " ;
binlog_format = " R O W " ;
enforce_storage_engine = " I n n o D B " ;
innodb_autoinc_lock_mode = " 2 " ;
} ;
} ;
} ;
} ;
galera_05 =
{ pkgs , . . . }:
{
networking = {
interfaces . eth1 = {
ipv4 . addresses = [
{ address = " 1 9 2 . 1 6 8 . 2 . 2 " ; prefixLength = 24 ; }
] ;
} ;
extraHosts = ''
192 .168 .2 .1 galera_04
192 .168 .2 .2 galera_05
192 .168 .2 .3 galera_06
'' ;
firewall . allowedTCPPorts = [ 3306 4444 4567 4568 ] ;
firewall . allowedUDPPorts = [ 4567 ] ;
} ;
2021-03-07 13:54:00 +00:00
users . users . testuser = { isSystemUser = true ; } ;
2020-04-05 19:58:27 +01:00
systemd . services . mysql = with pkgs ; {
path = [ mysqlenv-common mysqlenv-rsync ] ;
} ;
services . mysql = {
enable = true ;
package = pkgs . mariadb ;
settings = {
mysqld = {
bind_address = " 0 . 0 . 0 . 0 " ;
} ;
galera = {
wsrep_on = " O N " ;
2020-05-07 19:30:25 +01:00
wsrep_debug = " N O N E " ;
2020-04-05 19:58:27 +01:00
wsrep_retry_autocommit = " 3 " ;
2020-05-05 07:30:54 +01:00
wsrep_provider = " ${ pkgs . mariadb-galera } / l i b / g a l e r a / l i b g a l e r a _ s m m . s o " ;
2020-04-05 19:58:27 +01:00
wsrep_cluster_address = " g c o m m : / / g a l e r a _ 0 4 , g a l e r a _ 0 5 , g a l e r a _ 0 6 " ;
wsrep_cluster_name = " g a l e r a - r s y n c " ;
wsrep_node_address = " 1 9 2 . 1 6 8 . 2 . 2 " ;
wsrep_node_name = " g a l e r a _ 0 5 " ;
wsrep_sst_method = " r s y n c " ;
binlog_format = " R O W " ;
enforce_storage_engine = " I n n o D B " ;
innodb_autoinc_lock_mode = " 2 " ;
} ;
} ;
} ;
} ;
galera_06 =
{ pkgs , . . . }:
{
networking = {
interfaces . eth1 = {
ipv4 . addresses = [
{ address = " 1 9 2 . 1 6 8 . 2 . 3 " ; prefixLength = 24 ; }
] ;
} ;
extraHosts = ''
192 .168 .2 .1 galera_04
192 .168 .2 .2 galera_05
192 .168 .2 .3 galera_06
'' ;
firewall . allowedTCPPorts = [ 3306 4444 4567 4568 ] ;
firewall . allowedUDPPorts = [ 4567 ] ;
} ;
2021-03-07 13:54:00 +00:00
users . users . testuser = { isSystemUser = true ; } ;
2020-04-05 19:58:27 +01:00
systemd . services . mysql = with pkgs ; {
path = [ mysqlenv-common mysqlenv-rsync ] ;
} ;
services . mysql = {
enable = true ;
package = pkgs . mariadb ;
settings = {
mysqld = {
bind_address = " 0 . 0 . 0 . 0 " ;
} ;
galera = {
wsrep_on = " O N " ;
2020-05-07 19:30:25 +01:00
wsrep_debug = " N O N E " ;
2020-04-05 19:58:27 +01:00
wsrep_retry_autocommit = " 3 " ;
2020-05-05 07:30:54 +01:00
wsrep_provider = " ${ pkgs . mariadb-galera } / l i b / g a l e r a / l i b g a l e r a _ s m m . s o " ;
2020-04-05 19:58:27 +01:00
wsrep_cluster_address = " g c o m m : / / g a l e r a _ 0 4 , g a l e r a _ 0 5 , g a l e r a _ 0 6 " ;
wsrep_cluster_name = " g a l e r a - r s y n c " ;
wsrep_node_address = " 1 9 2 . 1 6 8 . 2 . 3 " ;
wsrep_node_name = " g a l e r a _ 0 6 " ;
wsrep_sst_method = " r s y n c " ;
binlog_format = " R O W " ;
enforce_storage_engine = " I n n o D B " ;
innodb_autoinc_lock_mode = " 2 " ;
} ;
} ;
} ;
} ;
} ;
testScript = ''
galera_04 . start ( )
galera_04 . wait_for_unit ( " m y s q l " )
galera_04 . wait_for_open_port ( 3306 )
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 1 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
)
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 1 v a l u e s ( 4 1 ) ; ' "
)
galera_05 . start ( )
galera_05 . wait_for_unit ( " m y s q l " )
galera_05 . wait_for_open_port ( 3306 )
galera_06 . start ( )
galera_06 . wait_for_unit ( " m y s q l " )
galera_06 . wait_for_open_port ( 3306 )
galera_05 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 1 ; ' - N | g r e p 4 1 "
2020-04-05 19:58:27 +01:00
)
galera_05 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 2 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
2020-04-05 19:58:27 +01:00
)
galera_05 . succeed ( " s y s t e m c t l s t o p m y s q l " )
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 2 v a l u e s ( 4 2 ) ; ' "
)
galera_06 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 3 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
2020-04-05 19:58:27 +01:00
)
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 3 v a l u e s ( 4 3 ) ; ' "
)
galera_05 . succeed ( " s y s t e m c t l s t a r t m y s q l " )
galera_05 . wait_for_open_port ( 3306 )
galera_05 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' s h o w s t a t u s ' - N | g r e p ' w s r e p _ c l u s t e r _ s i z e . * 3 ' "
2020-04-05 19:58:27 +01:00
)
galera_06 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' s h o w s t a t u s ' - N | g r e p ' w s r e p _ l o c a l _ s t a t e _ c o m m e n t . * S y n c e d ' "
2020-04-05 19:58:27 +01:00
)
galera_04 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 3 ; ' - N | g r e p 4 3 "
2020-04-05 19:58:27 +01:00
)
galera_05 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 2 ; ' - N | g r e p 4 2 "
2020-04-05 19:58:27 +01:00
)
galera_06 . succeed (
2020-05-07 19:30:25 +01:00
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 1 ; ' - N | g r e p 4 1 "
2020-04-05 19:58:27 +01:00
)
galera_04 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 3 ; ' " )
2020-05-07 19:30:25 +01:00
galera_05 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 2 ; ' " )
galera_06 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 1 ; ' " )
2020-04-05 19:58:27 +01:00
'' ;
} )