Debian Codegraph @

mysql-test/suite/network_namespace/t/rpl_network_namespace.test

raw
1 #####################################################################
2 # #
3 # The aim of this test is to check support for usage of network #
4 # namespaces introduced by WL#12720 in a replication connection. #
5 # It includes verifying that replication works on using the #
6 # NETWORK_NAMESPACE clause added to the CHANGE REPLICATION SOURCE #
7 # command and that details about the network namespace used for the #
8 # replication is reflected through SHOW SLAVE STATUS and below #
9 # tables - #
10 # - performance_schema.replication_connection_configuration #
11 # - mysql.slave_master_info #
12 # #
13 # The test requires following conditions to be met in order for #
14 # it to run :- #
15 # 1. mysqld has been granted the capability to switch network #
16 # namespaces. #
17 # 2. Two network namespaces are created with specific IP addresses #
18 # and are accessible i.e., #
19 # - a namespace named 'red' containing the IP '10.0.2.1' #
20 # - a namespace named 'blue' containing the IP '10.0.2.1' #
21 # #
22 # Creation Date: 2019-02-20 #
23 # Author: Srikanth B R #
24 # #
25 #####################################################################
26
27 # Network namespaces is a feature of Linux.
28 # So, ignore this test on any platform except Linux.
29 --source include/linux.inc
30
31 --source ../include/have_network_namespaces.inc
32 --source include/not_group_replication_plugin.inc
33
34 --let $rpl_skip_start_slave= 1
35 --source include/master-slave.inc
36
37 call mtr.add_suppression("Hostname .* does not resolve to");
38 call mtr.add_suppression("IP address .* could not be resolved");
39
40 --echo # Add a bind address in the 'red' network namespace to master
41 --let $rpl_server_number=1
42 --let $rpl_server_parameters= --bind-address=127.0.0.1,10.0.2.1/red
43 --source include/rpl_restart_server.inc
44
45 --echo # Add a bind address in the 'blue' network namespace to the slave
46 --let $rpl_server_parameters= --bind-address=127.0.0.1,10.0.1.1/blue
47 --let $rpl_server_number=2
48 --source include/rpl_restart_server.inc
49
50 --connection slave
51 --source include/start_slave.inc
52
53 --connection master
54
55 --echo # Create tables and users.
56
57 CREATE TABLE t1(a int primary key, b varchar(10));
58 CREATE USER [email protected];
59 GRANT ALL ON *.* TO [email protected];
60 CREATE USER [email protected];
61 GRANT ALL ON *.* TO [email protected];
62
63 --echo #Insert via connection to the address 127.0.0.1 from the default network namespace
64 INSERT INTO t1 VALUES (1, 'abc');
65
66 --echo #Insert via connection to the address 10.0.2.1 from the 'red' network namespace
67 --replace_result $MASTER_MYPORT MASTER_PORT
68 --exec $EXE_MYSQL --no-defaults -u root --port $MASTER_MYPORT --host 10.0.2.1 --network-namespace=red test -e "INSERT INTO t1 VALUES (2, 'cdf');"
69
70 SHOW CREATE TABLE t1;
71
72 --echo [ connection slave ]
73 --source include/sync_slave_sql_with_master.inc
74
75 SHOW CREATE TABLE t1;
76
77 --echo # Check network namspace of currently connected master
78 SELECT network_namespace AS master_network_namespace FROM performance_schema.replication_connection_configuration;
79 SELECT Network_namespace FROM mysql.slave_master_info;
80 --let $slave_status_namespace= query_get_value(SHOW SLAVE STATUS,Network_Namespace, 1)
81 --echo Namespace from 'SHOW SLAVE STATUS' : $slave_status_namespace
82
83 --echo # Check slave connection on the 'blue' namespace
84 --replace_result $SLAVE_MYPORT SLAVE_PORT
85 --exec $EXE_MYSQL --no-defaults -u root --port $SLAVE_MYPORT --host 10.0.1.1 --network-namespace=blue test -e "SELECT * FROM t1"
86
87 --echo # Stop slave and run change master to listen to the master on socket
88 --echo # created in the 'red' namespace
89 --source include/stop_slave.inc
90
91 --echo [ connection master ]
92 --connection master
93 # Some more DML's on the master
94 --echo #Insert via connection to the address 127.0.0.1 from the default network namespace
95 --let $MASTER_LOG_POS= query_get_value(SHOW MASTER STATUS, Position, 1)
96
97 INSERT INTO t1 VALUES (3, 'ghi');
98
99 --echo #Insert via connection to the address 10.0.2.1 from the 'red' network namespace
100 --exec $EXE_MYSQL --no-defaults -u root --port $MASTER_MYPORT --host 10.0.2.1 --network-namespace=red test -e "INSERT INTO t1 VALUES (4, 'jkl');"
101
102 --echo [ connection slave ]
103 --connection slave
104 --echo # Change master to listen to the master on IP '10.0.2.1' in the 'red' namespace
105 --replace_result $MASTER_MYPORT MASTER_PORT $MASTER_LOG_POS MASTER_LOG_POS
106 --let $chm= CHANGE REPLICATION SOURCE TO SOURCE_HOST='10.0.2.1', SOURCE_USER='root', SOURCE_PORT=$MASTER_MYPORT, NETWORK_NAMESPACE='red'
107 if ( `SELECT @@GLOBAL.GTID_MODE = "OFF"` )
108 {
109 --let $chm= $chm, SOURCE_LOG_POS=$MASTER_LOG_POS
110 }
111 --exec $EXE_MYSQL --no-defaults -u root --port $SLAVE_MYPORT --host 10.0.1.1 --network-namespace=blue test -e "$chm"
112 --source include/start_slave.inc
113
114 # Now sync slave with master
115 --connection master
116 --source include/sync_slave_sql_with_master.inc
117
118 --echo # Check network namspace of currently connected master
119 SELECT network_namespace AS master_network_namespace FROM performance_schema.replication_connection_configuration;
120 SELECT Network_namespace FROM mysql.slave_master_info;
121 --let $slave_status_namespace= query_get_value(SHOW SLAVE STATUS,Network_Namespace, 1)
122 --echo Namespace from 'SHOW SLAVE STATUS' : $slave_status_namespace
123
124 --echo # Check slave connection on the 'blue' namespace
125 --exec $EXE_MYSQL --no-defaults -u root --port $SLAVE_MYPORT --host 10.0.1.1 --network-namespace=blue test -e "SELECT * FROM t1"
126
127 --echo # Check that the table is replicated properly
128 --let $diff_tables = master:t1, slave:t1
129 --source include/diff_tables.inc
130
131 --source include/stop_slave.inc
132
133 --echo [ connection master ]
134 --connection master
135 --let $MASTER_LOG_POS= query_get_value(SHOW MASTER STATUS, Position, 1)
136
137 --echo [ connection slave ]
138 --connection slave
139 --echo # Change master to original connection
140 --replace_result $MASTER_MYPORT MASTER_PORT $MASTER_LOG_POS MASTER_LOG_POS
141 --let $chm= CHANGE REPLICATION SOURCE TO SOURCE_HOST='127.0.0.1', SOURCE_USER='root', SOURCE_PORT=$MASTER_MYPORT, NETWORK_NAMESPACE=''
142 if ( `SELECT @@GLOBAL.GTID_MODE = "OFF"` )
143 {
144 --let $chm= $chm, SOURCE_LOG_POS=$MASTER_LOG_POS
145 }
146 --exec $EXE_MYSQL --no-defaults -u root --port $SLAVE_MYPORT --host 10.0.1.1 --network-namespace=blue test -e "$chm"
147
148 --source include/start_slave.inc
149
150 # Now sync slave with master
151 --connection master
152 INSERT INTO t1 VALUES (5, 'mno');
153 --source include/sync_slave_sql_with_master.inc
154
155 --echo # Check network namspace of currently connected master
156 SELECT network_namespace AS master_network_namespace FROM performance_schema.replication_connection_configuration;
157 SELECT Network_namespace FROM mysql.slave_master_info;
158 --let $slave_status_namespace= query_get_value(SHOW SLAVE STATUS,Network_Namespace, 1)
159 --echo Namespace from 'SHOW SLAVE STATUS' : $slave_status_namespace
160
161 --echo # Check that the table is replicated properly
162 --let $diff_tables = master:t1, slave:t1
163 --source include/diff_tables.inc
164
165 --echo # Cleanup
166
167 connection master;
168 DROP USER [email protected];
169 DROP USER [email protected];
170 DROP TABLE t1;
171
172 --source include/sync_slave_sql_with_master.inc
173 --source include/rpl_end.inc