def run(self): self.res_fname = "result.txt" from_conn = "--server={0}".format( self.build_connection_string(self.server1) ) cmd_str = "mysqlbinlogrotate.py {0}".format(from_conn) test_num = 1 comment = ("Test case {0} - do the help" "".format(test_num)) cmd = "{0} --help".format(cmd_str) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - rotate and verbose option (-vv)" "".format(test_num)) cmd = "{0} -vv".format(cmd_str) res = self.run_test_case(0, cmd, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000002", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - rotate and min_size option (-vv)" "".format(test_num)) cmd = "{0} -vv --min-size={1}".format(cmd_str, 100) res = self.run_test_case(0, cmd, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000003", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Remove version information self.remove_result_and_lines_after("MySQL Utilities mysqlbinlogrotate" " version", 6) self.replace_result( "# Rotating Binary log on Server: ", "# Rotating Binary log on Server: XXXXXX:XXXX\n" ) self.replace_result( "# Active binlog file: ", "# Active binlog file: 'XXXXX-XXX:XXXXXX' (size: XXX bytes)\n" ) return True
def run(self): self.res_fname = "result.txt" from_conn = "--server={0}".format( self.build_connection_string(self.server1)) cmd_str = "mysqlbinlogpurge.py {0}".format(from_conn) test_num = 1 comment = ("Test case {0} - simple purge" "".format(test_num)) cmd = "{0}".format(cmd_str) res = self.run_test_case(0, cmd, comment) if not res or binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Flush master binary log to have some logs to purge self.server1.exec_query("FLUSH LOGS") test_num += 1 comment = ("Test case {0} - purge using verbose (-v)" "".format(test_num)) cmd = "{0} -v ".format(cmd_str) res = self.run_test_case(0, cmd, comment) if not res or binlog_file_exists(self.server1_datadir, "mysql-bin.000002", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask known source host name. self.replace_result("# Source on ", "# Source on XXXX-XXXX: ... connected.\n") # Mask version self.replace_result( "MySQL Utilities mysqlbinlogpurge version", "MySQL Utilities mysqlbinlogpurge version X.Y.Z " "(part of MySQL Workbench ... XXXXXX)\n" ) return True
def run(self): self.res_fname = "result.txt" from_conn = "--server={0}".format( self.build_connection_string(self.server1)) cmd_str = "mysqlbinlogpurge.py {0}".format(from_conn) test_num = 1 comment = ("Test case {0} - simple purge" "".format(test_num)) cmd = "{0}".format(cmd_str) res = self.run_test_case(0, cmd, comment) if not res or binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Flush master binary log to have some logs to purge self.server1.exec_query("FLUSH LOGS") test_num += 1 comment = ("Test case {0} - purge using verbose (-v)" "".format(test_num)) cmd = "{0} -v ".format(cmd_str) res = self.run_test_case(0, cmd, comment) if not res or binlog_file_exists(self.server1_datadir, "mysql-bin.000002", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask known source host name. self.replace_result("# Source on ", "# Source on XXXX-XXXX: ... connected.\n") # Mask version self.replace_result( "MySQL Utilities mysqlbinlogpurge version", "MySQL Utilities mysqlbinlogpurge version X.Y.Z " "(part of MySQL Workbench ... XXXXXX)\n") return True
def run(self): self.res_fname = "result.txt" server_conn = "--server={0}".format( self.build_connection_string(self.server2)) master_conn = "--master={0}".format( self.build_connection_string(self.server2)) self.res_fname = "result.txt" server_conn3 = "--server={0}".format( self.build_connection_string(self.server3)) master_conn3 = "--master={0}".format( self.build_connection_string(self.server3)) cmd_str = "mysqlbinlogpurge.py {0}" test_num = 1 comment = ("Test case {0} - No options" "".format(test_num)) cmd = "mysqlbinlogpurge.py" res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Master no Slave options" "".format(test_num)) cmd = cmd_str.format(master_conn) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Server with Slave option" "".format(test_num)) cmd = "{0} --slave={1}".format( cmd_str.format(server_conn), self.build_connection_string(self.server2) ) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Server without binlog" "".format(test_num)) cmd = "{0} {1}".format( cmd_str.format(server_conn3), self.build_connection_string(self.server2) ) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Master with wrong Slave" "".format(test_num)) cmd = "{0} --slave={1}".format( cmd_str.format(master_conn3), self.build_connection_string(self.server2) ) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Server with Discover option" "".format(test_num)) cmd = "{0} --discover={1}".format( cmd_str.format(server_conn), "root:rootpass" ) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Only discover option" "".format(test_num)) cmd = "mysqlbinlogpurge.py --discover={0}".format("root:rootpass") res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Only slaves option" "".format(test_num)) cmd = "mysqlbinlogpurge.py --slaves={0}".format(server_conn) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Only dry-run and verbose options" "".format(test_num)) cmd = "{0} -vv -d".format("mysqlbinlogpurge.py") res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - wrong binlog base name" "".format(test_num)) cmd = "{0} --binlog={1}".format(cmd_str.format(server_conn), "wrong_binlog_name.00002") res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - server and master options mixed" "".format(test_num)) cmd = "{0} {1}".format(cmd_str.format(server_conn), master_conn) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask results self.replace_substring("localhost", "XXXX-XXXX") p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(repr(port), "PORT{0}".format(p_n)) return True
def run(self): self.res_fname = "result.txt" from_conn = "--server={0}".format( self.build_connection_string(self.server1) ) server2_conn = "--server={0}".format( self.build_connection_string(self.server2) ) cmd_str = "mysqlbinlogrotate.py " test_num = 1 comment = ("Test case {0} - no options" "".format(test_num)) cmd = "{0}".format(cmd_str) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - server has no binlog" "".format(test_num)) cmd = "{0} {1}".format(cmd_str, server2_conn) res = self.run_test_case(1, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - rotate bad value min_size option" "".format(test_num)) cmd = "{0} {1} --min-size={2}".format(cmd_str, from_conn, "A100") res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - rotate high value min_size option" "".format(test_num)) cmd = "{0} {1} --min-size={2}".format(cmd_str, from_conn, "10000") res = self.run_test_case(0, cmd, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - rotate on server without binlog and " "option (-vv)".format(test_num)) cmd = "{0} -vv {1}".format(cmd_str, server2_conn) res = self.run_test_case(1, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Mask results self.replace_substring_portion( "because it's size", "is lower than the minimum", "because it's size XXX is lower than the minimum" ) self.replace_substring_portion( "ERROR:", " You are not using binary log", "ERROR: You are not using binary log" ) self.replace_substring("localhost", "XXXX-XXXX") p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(repr(port), "PORT{0}".format(p_n)) return True
def run(self): test_num = 1 master_conn = self.build_connection_string(self.server1).strip(' ') slave1_conn = self.build_connection_string(self.server2).strip(' ') slave2_conn = self.build_connection_string(self.server3).strip(' ') std_server_conn = self.build_connection_string(self.server4).strip(' ') nb_server_conn = self.build_connection_string(self.server5).strip(' ') comment = "mysqlrplshow.py" cmd_opts = ("-r --discover-slaves-login={0} ").format( master_conn.split('@')[0]) cmds = "mysqlrplshow.py --master={0} {1}".format(master_conn, cmd_opts) self.run_test_case(0, cmds, comment) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(master_conn) cmd_opts = "--discover-slaves={0} ".format("in:valid") comment = ("Test case {0} - mysqlbinlogpurge: with discover invalid " "login".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: with discover invalid " "login and verbose".format(test_num)) cmds = "{0} {1} -vvv".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --master={0} " cmd_opts = "--discover-slaves={0} ".format(master_conn.split('@')[0]) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: single server given as " "master and --discover option".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(std_server_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server4_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1}".format(slave1_conn, slave2_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: standalone server given " "as master and --slaves from other master".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(std_server_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server4_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: server without binlog " "as master and --slaves from other master".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(nb_server_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, slave2_conn) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(master_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: one slave from other " "master".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(slave2_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, std_server_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: with slaves including an" " standalone server".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, nb_server_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: with slave without " "binlog".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(nb_server_conn) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, slave2_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Master without binlog" " and --slaves from other master".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --server={0} ".format(master_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Master given as server" " on --server option".format(test_num)) cmds = "{0}".format(cmd_str) res = self.run_test_case(1, cmds, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Master given as server" " on --server option and -v".format(test_num)) cmds = "{0} -v".format(cmd_str) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) self.server2.exec_query("FLUSH BINARY LOGS") self.server3.exec_query("STOP SLAVE IO_THREAD") disc_opts = "--discover-slaves={0} -vv".format("root:root") cmd_str = "mysqlbinlogpurge.py --master={0} ".format(slave1_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Slave disconnected from " "master using --discover-slave option".format(test_num)) cmds = "{0} {1}".format(cmd_str, disc_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(slave1_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Slave disconnected from " "master --slaves option".format(test_num)) cmds = "{0} --slave={1} -vv".format(cmd_str, slave2_conn) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask out non-deterministic data rpl_admin.test.do_masks(self) p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(str(port), "PORT{0}".format(p_n)) self.replace_substring_portion( "Slave with id:", "is connected", "Slave with id:XXX at localhost:PORT2 is connected") # following line is not available in MySQL servers version < 5.6 self.remove_result("# Binary log basename path:") return True
def run_set(self, option_name, test_num, cmd_str, server, datadir, ad_opt=""): """Runs a set of test for the given option. option_name[in] Option to use along the server connection string test_num[in] Test cane number cmd_str[in] Utility module name to run server[in] Server instance used to run the test datadir[in] the datadir path to check ad_opt[in] Additional command option Returns latest test case number used. """ server_con = self.build_custom_connection_string( server, 'a_user', 'a_pwd') # Create user without any privileges. if self.debug: print("\nCreating user without any privileges on server...") change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=None, revoke_list=None, disable_binlog=True, create_user=True) # Purge binary logs using a user with no privileges. test_num += 1 comment = ("Test case {0} - Purge binlog using a user without " "privileges, {1} option (fail).".format( test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Grant all required privilege to user (except REPLICATION SLAVE). if self.debug: print("\nGrant all required privileges except REPLICATION SLAVE.") grants = ['SUPER'] change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=grants, revoke_list=None, disable_binlog=True, create_user=False) # Purge binary logs using a user without REPLICATION SLAVE. test_num += 1 comment = ("Test case {0} - Purge binlog using a user without " "REPLICATION SLAVE, {1} option (fail).".format( test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Grant all required privilege to user (except SUPER). if self.debug: print("\nGrant all required privileges except SUPER.") revokes = ['SUPER'] grants = ['REPLICATION SLAVE'] change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=grants, revoke_list=revokes, disable_binlog=True, create_user=False) # Purge binary logs using a user without REPLICATION SLAVE. test_num += 1 comment = ("Test case {0} - Purge binlog using a user without " "SUPER, {1} option (fail).".format(test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Grant all required privilege to user (except SUPER). if self.debug: print("\nGrant all required privileges (REPLICATION SLAVE and " "SUPER).") grants = ['SUPER'] change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=grants, revoke_list=None, disable_binlog=True, create_user=False) # Purge binary logs using a user with all required privileges # (REPLICATION SLAVE and SUPER). test_num += 1 comment = ("Test case {0} - Purge binlog using a user with required " "privileges (REPLICATION SLAVE and SUPER)" ", {1} option.".format(test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(0, cmd, comment) if not res or binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask results self.replace_substring("localhost", "XXXX-XXXX") p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(repr(port), "PORT{0}".format(p_n)) return test_num
def run(self): self.res_fname = "result.txt" server_conn = "--server={0}".format( self.build_connection_string(self.server2)) master_conn = "--master={0}".format( self.build_connection_string(self.server2)) self.res_fname = "result.txt" server_conn3 = "--server={0}".format( self.build_connection_string(self.server3)) master_conn3 = "--master={0}".format( self.build_connection_string(self.server3)) cmd_str = "mysqlbinlogpurge.py {0}" test_num = 1 comment = ("Test case {0} - No options" "".format(test_num)) cmd = "mysqlbinlogpurge.py" res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Master no Slave options" "".format(test_num)) cmd = cmd_str.format(master_conn) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Server with Slave option" "".format(test_num)) cmd = "{0} --slave={1}".format( cmd_str.format(server_conn), self.build_connection_string(self.server2) ) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Server without binlog" "".format(test_num)) cmd = "{0} ".format( cmd_str.format(server_conn3), self.build_connection_string(self.server2) ) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Master with wrong Slave" "".format(test_num)) cmd = "{0} --slave={1}".format( cmd_str.format(master_conn3), self.build_connection_string(self.server2) ) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Server with Discover option" "".format(test_num)) cmd = "{0} --discover={1}".format( cmd_str.format(server_conn), "root:rootpass" ) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Only discover option" "".format(test_num)) cmd = "mysqlbinlogpurge.py --discover={0}".format("root:rootpass") res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Only slaves option" "".format(test_num)) cmd = "mysqlbinlogpurge.py --slaves={0}".format(server_conn) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Only dry-run and verbose options" "".format(test_num)) cmd = "{0} -vv -d".format("mysqlbinlogpurge.py") res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - wrong binlog base name" "".format(test_num)) cmd = "{0} --binlog={1}".format(cmd_str.format(server_conn), "wrong_binlog_name.00002") res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - server and master options mixed" "".format(test_num)) cmd = "{0} {1}".format(cmd_str.format(server_conn), master_conn) res = self.run_test_case(2, cmd, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask results self.replace_substring("localhost", "XXXX-XXXX") p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(repr(port), "PORT{0}".format(p_n)) return True
def run_set(self, option_name, test_num, cmd_str, server, datadir, ad_opt=""): """Runs a set of test for the given option. option_name[in] Option to use along the server connection string test_num[in] Test cane number cmd_str[in] Utility module name to run server[in] Server instance used to run the test datadir[in] the datadir path to check ad_opt[in] Additional command option Returns latest test case number used. """ server_con = self.build_custom_connection_string(server, 'a_user', 'a_pwd') # Create user without any privileges. if self.debug: print("\nCreating user without any privileges on server...") change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=None, revoke_list=None, disable_binlog=True, create_user=True) # Purge binary logs using a user with no privileges. test_num += 1 comment = ("Test case {0} - Purge binlog using a user without " "privileges, {1} option (fail).".format(test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Grant all required privilege to user (except REPLICATION SLAVE). if self.debug: print("\nGrant all required privileges except REPLICATION SLAVE.") grants = ['SUPER'] change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=grants, revoke_list=None, disable_binlog=True, create_user=False) # Purge binary logs using a user without REPLICATION SLAVE. test_num += 1 comment = ("Test case {0} - Purge binlog using a user without " "REPLICATION SLAVE, {1} option (fail).".format(test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Grant all required privilege to user (except SUPER). if self.debug: print("\nGrant all required privileges except SUPER.") revokes = ['SUPER'] grants = ['REPLICATION SLAVE'] change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=grants, revoke_list=revokes, disable_binlog=True, create_user=False) # Purge binary logs using a user without REPLICATION SLAVE. test_num += 1 comment = ("Test case {0} - Purge binlog using a user without " "SUPER, {1} option (fail).".format(test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(1, cmd, comment) if not res or not binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Grant all required privilege to user (except SUPER). if self.debug: print("\nGrant all required privileges (REPLICATION SLAVE and " "SUPER).") grants = ['SUPER'] change_user_privileges(server, 'a_user', 'a_pwd', server.host, grant_list=grants, revoke_list=None, disable_binlog=True, create_user=False) # Purge binary logs using a user with all required privileges # (REPLICATION SLAVE and SUPER). test_num += 1 comment = ("Test case {0} - Purge binlog using a user with required " "privileges (REPLICATION SLAVE and SUPER)" ", {1} option.".format(test_num, option_name)) cmd = cmd_str.format("--{0}={1} {2}".format(option_name, server_con, ad_opt)) res = self.run_test_case(0, cmd, comment) if not res or binlog_file_exists(datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask results self.replace_substring("localhost", "XXXX-XXXX") p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(repr(port), "PORT{0}".format(p_n)) return test_num
def run(self): test_num = 1 master_conn = self.build_connection_string(self.server1).strip(' ') slave1_conn = self.build_connection_string(self.server2).strip(' ') slave2_conn = self.build_connection_string(self.server3).strip(' ') std_server_conn = self.build_connection_string(self.server4).strip(' ') nb_server_conn = self.build_connection_string(self.server5).strip(' ') comment = "mysqlrplshow.py" cmd_opts = ("-r --discover-slaves-login={0} " ).format(master_conn.split('@')[0]) cmds = "mysqlrplshow.py --master={0} {1}".format(master_conn, cmd_opts) self.run_test_case(0, cmds, comment) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(master_conn) cmd_opts = "--discover-slaves={0} ".format("in:valid") comment = ("Test case {0} - mysqlbinlogpurge: with discover invalid " "login".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: with discover invalid " "login and verbose".format(test_num)) cmds = "{0} {1} -vvv".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --master={0} " cmd_opts = "--discover-slaves={0} ".format(master_conn.split('@')[0]) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: single server given as " "master and --discover option".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(std_server_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server4_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1}".format(slave1_conn, slave2_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: standalone server given " "as master and --slaves from other master".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(std_server_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server4_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: server without binlog " "as master and --slaves from other master".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(nb_server_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, slave2_conn) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(master_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: one slave from other " "master".format(test_num)) cmds = "{0} {1}".format(cmd_str.format(slave2_conn), cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, std_server_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: with slaves including an" " standalone server".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, nb_server_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: with slave without " "binlog".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(nb_server_conn) cmd_opts = "--slaves={0},{1} ".format(slave1_conn, slave2_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Master without binlog" " and --slaves from other master".format(test_num)) cmds = "{0} {1}".format(cmd_str, cmd_opts) res = self.run_test_case(1, cmds, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --server={0} ".format(master_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Master given as server" " on --server option".format(test_num)) cmds = "{0}".format(cmd_str) res = self.run_test_case(1, cmds, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Master given as server" " on --server option and -v".format(test_num)) cmds = "{0} -v".format(cmd_str) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server1_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) self.server2.exec_query("FLUSH BINARY LOGS") self.server3.exec_query("STOP SLAVE IO_THREAD") disc_opts = "--discover-slaves={0} -vv".format("root:root") cmd_str = "mysqlbinlogpurge.py --master={0} ".format(slave1_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Slave disconnected from " "master using --discover-slave option".format(test_num)) cmds = "{0} {1}".format(cmd_str, disc_opts) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) cmd_str = "mysqlbinlogpurge.py --master={0} ".format(slave1_conn) test_num += 1 comment = ("Test case {0} - mysqlbinlogpurge: Slave disconnected from " "master --slaves option".format(test_num)) cmds = "{0} --slave={1} -vv".format(cmd_str, slave2_conn) res = self.run_test_case(1, cmds, comment) if not res or not binlog_file_exists(self.server2_datadir, "mysql-bin.000001", self.debug): raise MUTLibError("{0}: failed".format(comment)) # Mask out non-deterministic data rpl_admin.test.do_masks(self) p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(str(port), "PORT{0}".format(p_n)) self.replace_substring_portion( "Slave with id:", "is connected", "Slave with id:XXX at localhost:PORT2 is connected" ) # following line is not available in MySQL servers version < 5.6 self.remove_result("# Binary log basename path:") return True
def run(self): self.res_fname = "result.txt" cmd_str = "mysqlbinlogrotate.py " serv_conn = self.build_custom_connection_string(self.server2, 'a_user', 'a_pwd') test_num = 1 test_cases = ( {"comment": "with no privileges", "grant_list": None, "revoke_list": None, "exp_cmd_res": 1, "rotation_expected": False}, {"comment": "with RELOAD privilege only", "grant_list": ['RELOAD'], "revoke_list": None, "exp_cmd_res": 1, "rotation_expected": False}, {"comment": "with REPLICATION CLIENT privilege only", "grant_list": ['REPLICATION CLIENT'], "revoke_list": ['RELOAD'], "exp_cmd_res": 1, "rotation_expected": False}, {"comment": "with RELOAD and REPLICATION CLIENT privileges", "grant_list": ['RELOAD'], "revoke_list": None, "exp_cmd_res": 0, "rotation_expected": True} ) create_user = True for test_case in test_cases: # Create user if has not been created, also grant and revoke # privileges as required by the test case. if self.debug: print("\nChanging user privileges\n granting: {0}\n " "revoking: {1}".format(test_case["grant_list"], test_case["revoke_list"])) change_user_privileges(self.server2, 'a_user', 'a_pwd', self.server2.host, grant_list=test_case["grant_list"], revoke_list=test_case["revoke_list"], disable_binlog=True, create_user=create_user) create_user = False rot_exp = test_case["rotation_expected"] comment = ("Test case {0} - rotate on server {1} " "and -vv".format(test_num, test_case["comment"])) cmd = "{0} --server={1} -vv".format(cmd_str, serv_conn) res = self.run_test_case(test_case["exp_cmd_res"], cmd, comment) if not res or \ (rot_exp ^ binlog_file_exists(self.server2_datadir, "mysql-bin.000002", self.debug)): raise MUTLibError("{0}: failed".format(comment)) test_num += 1 self.replace_substring("localhost", "XXXX-XXXX") p_n = 0 for port in self.mask_ports: p_n += 1 self.replace_substring(repr(port), "PORT{0}".format(p_n)) self.replace_result( "# Active binlog file: ", "# Active binlog file: 'XXXXX-XXX:XXXXXX' (size: XXX bytes)\n" ) return True