2020-04-05 18:39:35 +00: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-mariabackup = pkgs . buildEnv { name = " m y s q l - p a t h - e n v - m a r i a b a c k u p " ; pathsToLink = [ " / b i n " ] ; paths = with pkgs ; [ gzip iproute netcat procps pv socat ] ; } ;
in {
name = " m a r i a d b - g a l e r a - m a r i a b a c k u p " ;
meta = with pkgs . stdenv . lib . maintainers ; {
maintainers = [ izorkin ] ;
} ;
# The test creates a Galera cluster with 3 nodes and is checking if mariabackup-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_01 =
{ pkgs , . . . }:
{
networking = {
interfaces . eth1 = {
ipv4 . addresses = [
{ address = " 1 9 2 . 1 6 8 . 1 . 1 " ; prefixLength = 24 ; }
] ;
} ;
extraHosts = ''
192 .168 .1 .1 galera_01
192 .168 .1 .2 galera_02
192 .168 .1 .3 galera_03
'' ;
firewall . allowedTCPPorts = [ 3306 4444 4567 4568 ] ;
firewall . allowedUDPPorts = [ 4567 ] ;
} ;
users . users . testuser = { } ;
systemd . services . mysql = with pkgs ; {
path = [ mysqlenv-common mysqlenv-mariabackup ] ;
} ;
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 " ;
} ;
} ] ;
initialScript = pkgs . writeText " m a r i a d b - i n i t . s q l " ''
GRANT ALL PRIVILEGES ON * . * TO ' check_repl' @ ' localhost' IDENTIFIED BY ' check_pass' WITH GRANT OPTION ;
FLUSH PRIVILEGES ;
'' ;
settings = {
mysqld = {
bind_address = " 0 . 0 . 0 . 0 " ;
} ;
galera = {
wsrep_on = " O N " ;
2020-05-07 18:27:02 +00:00
wsrep_debug = " N O N E " ;
2020-04-05 18:39:35 +00:00
wsrep_retry_autocommit = " 3 " ;
2020-05-05 06:30:54 +00: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 18:39:35 +00:00
wsrep_cluster_address = " g c o m m : / / " ;
wsrep_cluster_name = " g a l e r a " ;
wsrep_node_address = " 1 9 2 . 1 6 8 . 1 . 1 " ;
wsrep_node_name = " g a l e r a _ 0 1 " ;
wsrep_sst_method = " m a r i a b a c k u p " ;
wsrep_sst_auth = " c h e c k _ r e p l : c h e c k _ p a s s " ;
binlog_format = " R O W " ;
enforce_storage_engine = " I n n o D B " ;
innodb_autoinc_lock_mode = " 2 " ;
} ;
} ;
} ;
} ;
galera_02 =
{ pkgs , . . . }:
{
networking = {
interfaces . eth1 = {
ipv4 . addresses = [
{ address = " 1 9 2 . 1 6 8 . 1 . 2 " ; prefixLength = 24 ; }
] ;
} ;
extraHosts = ''
192 .168 .1 .1 galera_01
192 .168 .1 .2 galera_02
192 .168 .1 .3 galera_03
'' ;
firewall . allowedTCPPorts = [ 3306 4444 4567 4568 ] ;
firewall . allowedUDPPorts = [ 4567 ] ;
} ;
users . users . testuser = { } ;
systemd . services . mysql = with pkgs ; {
path = [ mysqlenv-common mysqlenv-mariabackup ] ;
} ;
services . mysql = {
enable = true ;
package = pkgs . mariadb ;
settings = {
mysqld = {
bind_address = " 0 . 0 . 0 . 0 " ;
} ;
galera = {
wsrep_on = " O N " ;
2020-05-07 18:27:02 +00:00
wsrep_debug = " N O N E " ;
2020-04-05 18:39:35 +00:00
wsrep_retry_autocommit = " 3 " ;
2020-05-05 06:30:54 +00: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 18:39:35 +00:00
wsrep_cluster_address = " g c o m m : / / g a l e r a _ 0 1 , g a l e r a _ 0 2 , g a l e r a _ 0 3 " ;
wsrep_cluster_name = " g a l e r a " ;
wsrep_node_address = " 1 9 2 . 1 6 8 . 1 . 2 " ;
wsrep_node_name = " g a l e r a _ 0 2 " ;
wsrep_sst_method = " m a r i a b a c k u p " ;
wsrep_sst_auth = " c h e c k _ r e p l : c h e c k _ p a s s " ;
binlog_format = " R O W " ;
enforce_storage_engine = " I n n o D B " ;
innodb_autoinc_lock_mode = " 2 " ;
} ;
} ;
} ;
} ;
galera_03 =
{ pkgs , . . . }:
{
networking = {
interfaces . eth1 = {
ipv4 . addresses = [
{ address = " 1 9 2 . 1 6 8 . 1 . 3 " ; prefixLength = 24 ; }
] ;
} ;
extraHosts = ''
192 .168 .1 .1 galera_01
192 .168 .1 .2 galera_02
192 .168 .1 .3 galera_03
'' ;
firewall . allowedTCPPorts = [ 3306 4444 4567 4568 ] ;
firewall . allowedUDPPorts = [ 4567 ] ;
} ;
users . users . testuser = { } ;
systemd . services . mysql = with pkgs ; {
path = [ mysqlenv-common mysqlenv-mariabackup ] ;
} ;
services . mysql = {
enable = true ;
package = pkgs . mariadb ;
settings = {
mysqld = {
bind_address = " 0 . 0 . 0 . 0 " ;
} ;
galera = {
wsrep_on = " O N " ;
2020-05-07 18:27:02 +00:00
wsrep_debug = " N O N E " ;
2020-04-05 18:39:35 +00:00
wsrep_retry_autocommit = " 3 " ;
2020-05-05 06:30:54 +00: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 18:39:35 +00:00
wsrep_cluster_address = " g c o m m : / / g a l e r a _ 0 1 , g a l e r a _ 0 2 , g a l e r a _ 0 3 " ;
wsrep_cluster_name = " g a l e r a " ;
wsrep_node_address = " 1 9 2 . 1 6 8 . 1 . 3 " ;
wsrep_node_name = " g a l e r a _ 0 3 " ;
wsrep_sst_method = " m a r i a b a c k u p " ;
wsrep_sst_auth = " c h e c k _ r e p l : c h e c k _ p a s s " ;
binlog_format = " R O W " ;
enforce_storage_engine = " I n n o D B " ;
innodb_autoinc_lock_mode = " 2 " ;
} ;
} ;
} ;
} ;
} ;
testScript = ''
galera_01 . start ( )
galera_01 . wait_for_unit ( " m y s q l " )
galera_01 . wait_for_open_port ( 3306 )
galera_01 . 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_01 . 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 ( 3 7 ) ; ' "
)
galera_02 . start ( )
galera_02 . wait_for_unit ( " m y s q l " )
galera_02 . wait_for_open_port ( 3306 )
galera_03 . start ( )
galera_03 . wait_for_unit ( " m y s q l " )
galera_03 . wait_for_open_port ( 3306 )
galera_02 . succeed (
2020-05-07 18:27:02 +00: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 3 7 "
2020-04-05 18:39:35 +00:00
)
galera_02 . succeed (
2020-05-07 18:27:02 +00: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 18:39:35 +00:00
)
galera_02 . succeed ( " s y s t e m c t l s t o p m y s q l " )
galera_01 . 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 ( 3 8 ) ; ' "
)
galera_03 . succeed (
2020-05-07 18:27:02 +00: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 18:39:35 +00:00
)
galera_01 . 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 ( 3 9 ) ; ' "
)
galera_02 . succeed ( " s y s t e m c t l s t a r t m y s q l " )
galera_02 . wait_for_open_port ( 3306 )
galera_02 . succeed (
2020-05-07 18:27:02 +00: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 18:39:35 +00:00
)
galera_03 . succeed (
2020-05-07 18:27:02 +00: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 18:39:35 +00:00
)
galera_01 . succeed (
2020-05-07 18:27:02 +00: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 3 9 "
2020-04-05 18:39:35 +00:00
)
galera_02 . succeed (
2020-05-07 18:27:02 +00: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 3 8 "
2020-04-05 18:39:35 +00:00
)
galera_03 . succeed (
2020-05-07 18:27:02 +00: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 3 7 "
2020-04-05 18:39:35 +00:00
)
galera_01 . 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 18:27:02 +00:00
galera_02 . 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_03 . 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 18:39:35 +00:00
'' ;
} )