~mysql/mysql-utilities/1.3.2

« back to all changes in this revision

Viewing changes to mysql-test/suite/replication/t/show_rpl.py

  • Committer: Paulo Jesus
  • Date: 2013-04-19 18:31:54 UTC
  • mfrom: (289.1.47 mysql-utilities-1.2.2)
  • Revision ID: paulo.jesus@oracle.com-20130419183154-g8rkvs2oezbdvrud
Release-1.3.1 Merge

This patch merges version 1.2.2 to 1.3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import mutlib
19
19
from mysql.utilities.exception import UtilError, MUTLibError
20
20
 
 
21
 
21
22
class test(mutlib.System_test):
22
23
    """show replication topology
23
24
    This test runs the mysqlrplshow utility on a known master-slave topology
24
 
    to print the topology. 
 
25
    to print the topology.
25
26
    """
26
27
 
27
28
    def check_prerequisites(self):
30
31
        return self.check_num_servers(1)
31
32
 
32
33
    def get_server(self, name):
33
 
        server = None
34
 
        server_id = None
35
 
        
36
34
        serverid = self.servers.get_next_id()
37
35
        new_port = self.servers.get_next_port()
38
 
        mysqld_params = ' --mysqld="--log-bin=mysql-bin ' + \
39
 
                        ' --report-host=%s --report-port=%s"' % \
40
 
                        ('localhost', new_port)
 
36
        mysqld_params = (' --mysqld="--log-bin=mysql-bin '
 
37
                         ' --report-host={0} '
 
38
                         '--report-port={1}"').format('localhost', new_port)
41
39
        self.servers.clear_last_port()
42
40
        res = self.servers.spawn_new_server(self.server_list[0], serverid,
43
 
                                           name, mysqld_params)
 
41
                                            name, mysqld_params)
44
42
        if not res:
45
43
            raise MUTLibError("Cannot spawn replication slave server.")
46
44
        server = res[0]
80
78
    def run(self):
81
79
        self.res_fname = "result.txt"
82
80
 
83
 
        master_str = "--master=%s" % \
84
 
                     self.build_connection_string(self.server_list[2])
85
 
        slave_str = " --slave=%s" % \
86
 
                    self.build_connection_string(self.server_list[1])
87
 
        relay_slave_slave = " --slave=%s" % \
88
 
                           self.build_connection_string(self.server_list[3])
89
 
        relay_slave_master = " --master=%s" % \
90
 
                             self.build_connection_string(self.server_list[3])
91
 
        slave_leaf = " --slave=%s" % \
92
 
                     self.build_connection_string(self.server_list[4])
93
 
 
94
 
        cmd_str = "mysqlrplshow.py --disco=root:root " + master_str
95
 
 
96
 
        comment = "Test case 1 - show topology of master with no slaves"
97
 
        cmd_opts = "  --show-list --recurse "
98
 
        res = mutlib.System_test.run_test_case(self, 0, cmd_str+cmd_opts,
99
 
                                                   comment)
100
 
        if not res:
101
 
            raise MUTLibError("%s: failed" % comment)
102
 
 
103
 
        conn_str = master_str + slave_str
104
 
        
105
 
        cmd = "mysqlreplicate.py --rpl-user=rpl:rpl " 
106
 
        try:
107
 
            res = self.exec_util(cmd+master_str+slave_str,
108
 
                                 self.res_fname)
109
 
            res = self.exec_util(cmd+master_str+relay_slave_slave,
110
 
                                 self.res_fname)
111
 
            res = self.exec_util(cmd+relay_slave_master+slave_leaf,
112
 
                                 self.res_fname)
113
 
            
114
 
        except UtilError, e:
115
 
            raise MUTLibError(e.errmsg)
116
 
 
117
 
        cmd_str = "mysqlrplshow.py --disco=root:root " + master_str
118
 
 
119
 
        comment = "Test case 2 - show topology"
120
 
        cmd_opts = "  --show-list --recurse "
121
 
        res = mutlib.System_test.run_test_case(self, 0, cmd_str+cmd_opts,
122
 
                                                   comment)
123
 
        if not res:
124
 
            raise MUTLibError("%s: failed" % comment)
125
 
   
126
 
        comment = "Test case 3 - show topology with --max-depth"
127
 
        cmd_opts = "  --show-list --recurse --max-depth=1"
128
 
        res = mutlib.System_test.run_test_case(self, 0, cmd_str+cmd_opts,
129
 
                                                   comment)
130
 
        if not res:
131
 
            raise MUTLibError("%s: failed" % comment)
132
 
 
133
 
        try:
134
 
            circle_master = " --master=%s" % \
135
 
                            self.build_connection_string(self.server_list[4])
136
 
            circle_slave = " --slave=%s" % \
137
 
                           self.build_connection_string(self.server_list[2])
138
 
            res = self.exec_util(cmd+circle_master+circle_slave,
139
 
                                 self.res_fname)
140
 
            
141
 
        except UtilError, e:
142
 
            raise MUTLibError(e.errmsg)
143
 
 
144
 
        comment = "Test case 4 - show topology with circular replication"
145
 
        cmd_opts = "  --show-list --recurse "
146
 
        res = mutlib.System_test.run_test_case(self, 0, cmd_str+cmd_opts,
147
 
                                                   comment)
148
 
        if not res:
149
 
            raise MUTLibError("%s: failed" % comment)
150
 
        
151
 
        # Create a master:master toplogy
152
 
        cmd = "mysqlreplicate.py --rpl-user=rpl:rpl " 
153
 
        try:
154
 
            cmd_str = cmd + "--master=%s --slave=%s" % \
155
 
                      (self.build_connection_string(self.server_list[5]),
156
 
                       self.build_connection_string(self.server_list[6]))                        
157
 
            res = self.exec_util(cmd_str, self.res_fname)
158
 
            cmd_str = cmd + "--master=%s --slave=%s" % \
159
 
                      (self.build_connection_string(self.server_list[6]),
160
 
                       self.build_connection_string(self.server_list[5]))                        
161
 
            res = self.exec_util(cmd_str, self.res_fname)
162
 
        except UtilError, e:
163
 
            raise MUTLibError(e.errmsg)
164
 
 
165
 
        comment = "Test case 5 - show topology with master:master replication"
166
 
        cmd_str = "mysqlrplshow.py --master=%s --disco=root:root " % \
167
 
                  self.build_connection_string(self.server_list[5])
168
 
        cmd_opts = "  --show-list --recurse "
169
 
        res = mutlib.System_test.run_test_case(self, 0, cmd_str+cmd_opts,
170
 
                                                   comment)
171
 
        if not res:
172
 
            raise MUTLibError("%s: failed" % comment)
173
 
            
 
81
        master_con = self.build_connection_string(self.server_list[2])
 
82
        master_str = "--master={0}".format(master_con)
 
83
 
 
84
        slave_con = self.build_connection_string(self.server_list[1])
 
85
        slave_str = "--slave={0}".format(slave_con)
 
86
 
 
87
        relay_slave_con = self.build_connection_string(self.server_list[3])
 
88
        relay_slave_slave = "--slave={0}".format(relay_slave_con)
 
89
        relay_slave_master = "--master={0}".format(relay_slave_con)
 
90
 
 
91
        slave_leaf_con = self.build_connection_string(self.server_list[4])
 
92
        slave_leaf = " --slave={0}".format(slave_leaf_con)
 
93
 
 
94
        test_num = 1
 
95
 
 
96
        comment = ("Test case {0} - show topology of master with no "
 
97
                   "slaves").format(test_num)
 
98
        cmd_str = ("mysqlrplshow.py --disco=root:root {0} "
 
99
                   "--show-list --recurse").format(master_str)
 
100
        res = self.run_test_case(0, cmd_str, comment)
 
101
        if not res:
 
102
            raise MUTLibError("%s: failed" % comment)
 
103
 
 
104
        cmd = "mysqlreplicate.py --rpl-user=rpl:rpl {0} {1}"
 
105
        try:
 
106
            res = self.exec_util(cmd.format(master_str, slave_str),
 
107
                                 self.res_fname)
 
108
            res = self.exec_util(cmd.format(master_str, relay_slave_slave),
 
109
                                 self.res_fname)
 
110
            res = self.exec_util(cmd.format(relay_slave_master, slave_leaf),
 
111
                                 self.res_fname)
 
112
        except UtilError, e:
 
113
            raise MUTLibError(e.errmsg)
 
114
 
 
115
        test_num += 1
 
116
 
 
117
        comment = "Test case {0} - show topology".format(test_num)
 
118
        cmd_str = ("mysqlrplshow.py --disco=root:root {0} "
 
119
                   "--show-list --recurse").format(master_str)
 
120
        res = self.run_test_case(0, cmd_str, comment)
 
121
        if not res:
 
122
            raise MUTLibError("%s: failed" % comment)
 
123
 
 
124
        test_num += 1
 
125
 
 
126
        comment = ("Test case {0} - show topology with "
 
127
                   "--max-depth").format(test_num)
 
128
        cmd_str = ("mysqlrplshow.py --disco=root:root {0} "
 
129
                   "--show-list --recurse --max-depth=1").format(master_str)
 
130
        res = self.run_test_case(0, cmd_str, comment)
 
131
        if not res:
 
132
            raise MUTLibError("%s: failed" % comment)
 
133
 
 
134
        try:
 
135
            circle_master = " --master={0}".format(slave_leaf_con)
 
136
            circle_slave = " --slave={0}".format(master_con)
 
137
            res = self.exec_util(cmd.format(circle_master, circle_slave),
 
138
                                 self.res_fname)
 
139
        except UtilError, e:
 
140
            raise MUTLibError(e.errmsg)
 
141
 
 
142
        test_num += 1
 
143
 
 
144
        comment = ("Test case {0} - show topology with circular "
 
145
                   "replication").format(test_num)
 
146
        cmd_str = ("mysqlrplshow.py --disco=root:root {0} "
 
147
                   "--show-list --recurse").format(master_str)
 
148
        res = self.run_test_case(0, cmd_str, comment)
 
149
        if not res:
 
150
            raise MUTLibError("%s: failed" % comment)
 
151
 
 
152
        test_num += 1
 
153
 
 
154
        comment = ("Test case {0} - show circular topology with verbose "
 
155
                   "option").format(test_num)
 
156
        cmd_str = ("mysqlrplshow.py --disco=root:root {0} "
 
157
                   "--show-list --recurse --verbose").format(master_str)
 
158
        res = self.run_test_case(0, cmd_str, comment)
 
159
        if not res:
 
160
            raise MUTLibError("%s: failed" % comment)
 
161
 
 
162
        # Create a master:master topology
 
163
        multi_master1_con = self.build_connection_string(self.server_list[5])
 
164
        multi_master2_con = self.build_connection_string(self.server_list[6])
 
165
        cmd = "mysqlreplicate.py --rpl-user=rpl:rpl --master={0} --slave={1}"
 
166
        try:
 
167
            res = self.exec_util(cmd.format(multi_master1_con,
 
168
                                            multi_master2_con),
 
169
                                 self.res_fname)
 
170
            res = self.exec_util(cmd.format(multi_master2_con,
 
171
                                            multi_master1_con),
 
172
                                 self.res_fname)
 
173
        except UtilError, e:
 
174
            raise MUTLibError(e.errmsg)
 
175
 
 
176
        test_num += 1
 
177
 
 
178
        comment = ("Test case {0} - show topology with master:master "
 
179
                   "replication").format(test_num)
 
180
        cmd_str = ("mysqlrplshow.py --disco=root:root --master={0} "
 
181
                   "--show-list --recurse").format(multi_master1_con)
 
182
        res = self.run_test_case(0, cmd_str, comment)
 
183
        if not res:
 
184
            raise MUTLibError("%s: failed" % comment)
 
185
 
174
186
        # Here we need to kill one of the servers to show that the
175
187
        # phantom server error from a stale SHOW SLAVE HOSTS is
176
188
        # fixed and the slave does *not* show on the graph.
179
191
        self.servers.remove_server(self.server_list[4])
180
192
        self.server_list[4] = None
181
193
 
 
194
        test_num += 1
 
195
 
182
196
        # This shows there is indeed stale data in the view
183
197
        res = self.server_list[3].exec_query("SHOW SLAVE HOSTS")
184
 
        self.results.append("Test case 6 : SHOW SLAVE HOSTS contains %d row.\n" %
185
 
                            len(res))
 
198
        self.results.append("Test case {0} : SHOW SLAVE HOSTS contains {1} "
 
199
                            "row.\n".format(test_num, len(res)))
186
200
 
187
 
        comment = "Test case 6 - show topology with phantom slave"
188
 
        cmd_str = "mysqlrplshow.py --disco=root:root " + relay_slave_master
189
 
        cmd_opts = "  --show-list "
190
 
        res = mutlib.System_test.run_test_case(self, 0, cmd_str+cmd_opts,
191
 
                                               comment)
 
201
        comment = ("Test case {0} - show topology with phantom "
 
202
                   "slave").format(test_num)
 
203
        cmd_str = ("mysqlrplshow.py --disco=root:root {0}"
 
204
                   "--show-list").format(relay_slave_master)
 
205
        res = self.run_test_case(0, cmd_str, comment)
192
206
 
193
207
        self.do_replacements()
194
 
            
 
208
 
195
209
        if not res:
196
210
            raise MUTLibError("%s: failed" % comment)
197
211
 
198
 
        for i in range(6,0,-1):
 
212
        for i in range(6, 0, -1):
199
213
            self.stop_replication(self.server_list[i])
200
 
        
 
214
 
201
215
        return True
202
 
    
 
216
 
203
217
    def do_replacements(self):
204
218
        self.replace_substring(" (28000)", "")
205
219
        self.replace_substring("127.0.0.1", "localhost")
210
224
        self.replace_result("Error connecting to a slave",
211
225
                            "Error connecting to a slave ...\n")
212
226
        self.replace_result("Error 2002: Can't connect to",
213
 
                            "Error ####: Can't connect to local MySQL server\n")
 
227
                            "Error ####: Can't connect to local MySQL server"
 
228
                            "\n")
214
229
        self.replace_result("Error 2003: Can't connect to",
215
 
                            "Error ####: Can't connect to local MySQL server\n")
 
230
                            "Error ####: Can't connect to local MySQL server"
 
231
                            "\n")
216
232
 
217
233
    def get_result(self):
218
234
        return self.compare(__name__, self.results)
219
 
    
 
235
 
220
236
    def record(self):
221
237
        return self.save_result_file(__name__, self.results)
222
 
    
 
238
 
223
239
    def stop_replication(self, server):
224
240
        if server is not None:
225
241
            res = server.exec_query("STOP SLAVE")
226
242
            res = server.exec_query("RESET SLAVE")
227
243
            res = server.exec_query("RESET MASTER")
228
 
    
 
244
 
229
245
    def cleanup(self):
230
246
        if self.res_fname:
231
247
            os.unlink(self.res_fname)
232
248
        return True
233
 
 
234