def run(self): """ Run the test cases. Return True if all tests pass, otherwise a MUTLibError is issued. """ cmd_base = "mysqlslavetrx.py" slave1_con = self.build_connection_string(self.server2).strip(' ') slave2_con = self.build_connection_string(self.server3).strip(' ') slaves_con = ",".join([slave1_con, slave2_con]) if self.debug: print("\nGet UUID of each server:") uuids = [] for srv in [self.server1, self.server2, self.server3]: uuids.append(srv.get_server_uuid()) if self.debug: for uuid in uuids: print("- {0}".format(uuid)) # Wait for slaves to catch up to ensure that the GTID_EXECUTED is the # same on all servers. if self.debug: print("\nWait for slaves to catch up with master.") self.wait_for_slaves() test_num = 1 comment = ("Test case {0} - Skip specified GTIDs on all slaves" ".").format(test_num) gtid_set = "{0}:7,{1}:7,{2}:7".format(*uuids) cmd = "{0} --slaves={1} --gtid-set={2}".format(cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for all slaves. master_gtid_executed = self.server1.get_gtid_executed() expected_gtids = gtid_set_union(master_gtid_executed, gtid_set) if self.debug: print("\nExpected GTID_EXECUTED set: {0}".format(expected_gtids)) # Check if GTID_EXECUTED match the expected value on all slaves. try: check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) # Mask non-deterministic output. self.replace_substring(str(self.server1.port), "PORT1") self.replace_substring(str(self.server2.port), "PORT2") self.replace_substring(str(self.server3.port), "PORT3") # Mask UUID values in GTIDs. self.replace_substring(uuids[0], "UUID_m") self.replace_substring(uuids[1], "UUID_s1") self.replace_substring(uuids[2], "UUID_s2") return True
def test_gtid_set_union(self): # Union of GTID sets with the same UUID. gtid_set_a = 'cfb4dd08-588e-11e4-89aa-606720440b68:1-3' gtid_set_b = 'cfb4dd08-588e-11e4-89aa-606720440b68:7' expected_result = 'cfb4dd08-588e-11e4-89aa-606720440b68:1-3:7' result = gtid_set_union(gtid_set_a, gtid_set_b) self.assertEqual(expected_result, result) # Union of GTID sets with different UUIDs. gtid_set_a = 'd4f8eb6e-588e-11e4-89aa-606720440b68:7' gtid_set_b = 'cfb4dd08-588e-11e4-89aa-606720440b68:1-3' expected_result = ('cfb4dd08-588e-11e4-89aa-606720440b68:1-3,' 'd4f8eb6e-588e-11e4-89aa-606720440b68:7') result = gtid_set_union(gtid_set_a, gtid_set_b) self.assertEqual(expected_result, result) # Union of GTID sets with different UUIDs and intersecting intervals. gtid_set_a = ('cfb4dd08-588e-11e4-89aa-606720440b68:2-4:6:8-9:12,' 'd4f8eb6e-588e-11e4-89aa-606720440b68:7') gtid_set_b = 'cfb4dd08-588e-11e4-89aa-606720440b68:1-3:9-11:13' expected_result = ('cfb4dd08-588e-11e4-89aa-606720440b68:1-4:6:8-13,' 'd4f8eb6e-588e-11e4-89aa-606720440b68:7') result = gtid_set_union(gtid_set_a, gtid_set_b) self.assertEqual(expected_result, result) # Union of GTID sets not in the normalized format (itemized) and with # repeated values. gtid_set_a = ('da1f90b1-588e-11e4-89aa-606720440b68:5,' 'cfb4dd08-588e-11e4-89aa-606720440b68:2-4:6:8-9:12,' 'd4f8eb6e-588e-11e4-89aa-606720440b68:7,' 'da1f90b1-588e-11e4-89aa-606720440b68:1,' 'd4f8eb6e-588e-11e4-89aa-606720440b68:7,' 'da1f90b1-588e-11e4-89aa-606720440b68:9,' 'da1f90b1-588e-11e4-89aa-606720440b68:4:1-2') gtid_set_b = ('cfb4dd08-588e-11e4-89aa-606720440b68:1-3:9-11:13,' 'da1f90b1-588e-11e4-89aa-606720440b68:9:1-2') expected_result = ('cfb4dd08-588e-11e4-89aa-606720440b68:1-4:6:8-13,' 'd4f8eb6e-588e-11e4-89aa-606720440b68:7,' 'da1f90b1-588e-11e4-89aa-606720440b68:1-2:4-5:9') result = gtid_set_union(gtid_set_a, gtid_set_b) self.assertEqual(expected_result, result)
def run(self): """ Run the test cases. Return True if all tests pass, otherwise a MUTLibError is issued. """ cmd_base = "mysqlslavetrx.py" slave1_con = self.build_connection_string(self.server2).strip(' ') slave2_con = self.build_connection_string(self.server3).strip(' ') slaves_con = ",".join([slave1_con, slave2_con]) if self.debug: print("\nGet UUID of each server:") uuids = [] for srv in [self.server1, self.server2, self.server3]: uuids.append(srv.get_server_uuid()) if self.debug: for uuid in uuids: print("- {0}".format(uuid)) # Wait for slaves to catch up to ensure that the GTID_EXECUTED is the # same on all servers. if self.debug: print("\nWait for slaves to catch up with master.") self.wait_for_slaves() test_num = 1 comment = "Test case {0} - Help.".format(test_num) cmd = "{0} --help".format(cmd_base) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Skip only one GTID on a single slave" ".").format(test_num) gtid_set = "{0}:10".format(uuids[0]) cmd = "{0} --slaves={1} --gtid-set={2}".format(cmd_base, slave1_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for target slave. master_gtid_executed = self.server1.get_gtid_executed() expected_gtids = gtid_set_union(master_gtid_executed, gtid_set) if self.debug: print("\nExpected GTID_EXECUTED set: {0}".format(expected_gtids)) # Check if GTID_EXECUTED match the expected value on all slaves. try: slave_trx_skip.check_gtid_executed([self.server2], expected_gtids) # No GTID skipped for server3. slave_trx_skip.check_gtid_executed([self.server3], master_gtid_executed) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) test_num += 1 comment = ("Test case {0}a - [DRYRUN] Skip GTID set on all slaves " "(previous skipped GTID is ignored).").format(test_num) gtid_set = "{0}:8-10:12,{1}:7-9,{2}:7:9".format(*uuids) cmd = "{0} --slaves={1} --gtid-set={2} --dryrun".format( cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2], expected_gtids) slave_trx_skip.check_gtid_executed([self.server3], master_gtid_executed) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) comment = ("Test case {0}b - Skip GTID set on all slaves " "(previous skipped GTID is ignored).").format(test_num) cmd = "{0} --slaves={1} --gtid-set={2}".format( cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for target slave. expected_gtids = gtid_set_union(master_gtid_executed, gtid_set) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) test_num += 1 comment = ("Test case {0} - Repeat previous command " "(No GTIDs will be skipped).").format(test_num) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same (no new GTID skipped). slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) test_num += 1 comment = ("Test case {0}a - [DRYRUN] Skip GTID set on all slaves " "(with verbose).").format(test_num) gtid_set = "{0}:10-13,{1}:8,{2}:8".format(*uuids) cmd = "{0} --slaves={1} --gtid-set={2} --dryrun -v".format( cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) comment = ("Test case {0}b - Skip GTID set on all slaves " "(with verbose).").format(test_num) cmd = "{0} --slaves={1} --gtid-set={2} -v".format( cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for target slave. expected_gtids = gtid_set_union(expected_gtids, gtid_set) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) # Mask non-deterministic output. self.replace_substring(str(self.server1.port), "PORT1") self.replace_substring(str(self.server2.port), "PORT2") self.replace_substring(str(self.server3.port), "PORT3") # Remove version information. self.remove_result_and_lines_after("MySQL Utilities mysqlslavetrx " "version", 1) # Mask UUID values in GTIDs. self.replace_substring(uuids[0], "UUID_m") self.replace_substring(uuids[1], "UUID_s1") self.replace_substring(uuids[2], "UUID_s2") return True
def run(self): """ Run the test cases. Return True if all tests pass, otherwise a MUTLibError is issued. """ cmd_base = "mysqlslavetrx.py" # Create user to test privileges on slaves. # No privileges granted to user on slave. if self.debug: print("\nCreating user without any privileges on slaves...") for srv in [self.server2, self.server3]: change_user_privileges(srv, 's_user', 's_pwd', srv.host, grant_list=None, revoke_list=None, disable_binlog=True, create_user=True) slave1_con = self.build_custom_connection_string(self.server2, 's_user', 's_pwd') slave2_con = self.build_custom_connection_string(self.server3, 's_user', 's_pwd') slaves_con = ",".join([slave1_con, slave2_con]) if self.debug: print("\nGet UUID of each server:") uuids = [] for srv in [self.server1, self.server2, self.server3]: uuids.append(srv.get_server_uuid()) if self.debug: for uuid in uuids: print("- {0}".format(uuid)) # Wait for slaves to catch up to ensure that the GTID_EXECUTED is the # same on all servers. if self.debug: print("\nWait for slaves to catch up with master.") self.wait_for_slaves() test_num = 1 comment = ("Test case {0} - Skip GTIDs (fail) using 's_user': no " "privileges on all slaves.").format(test_num) gtid_set = "{0}:7,{1}:7,{2}:7".format(*uuids) cmd = "{0} --slaves={1} --gtid-set={2}".format(cmd_base, slaves_con, gtid_set) res = self.run_test_case(1, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Grant all required privileges (SUPER) to user on Slave 1. if self.debug: print("\nGrant all required privileges (SUPER) on Slave 1.") slave_grants = ['SUPER'] change_user_privileges(self.server2, 's_user', 's_pwd', self.server2.host, grant_list=slave_grants, revoke_list=None, disable_binlog=True, create_user=False) test_num += 1 comment = ("Test case {0} - Skip GTIDs (fail) using 's_user': "******"SUPER for slave1 and no privileges for slave2." "").format(test_num) res = self.run_test_case(1, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Grant all required privileges (SUPER) to user on Slave 2. if self.debug: print("\nGrant all required privileges (SUPER) on Slave 2.") change_user_privileges(self.server3, 's_user', 's_pwd', self.server3.host, grant_list=slave_grants, revoke_list=None, disable_binlog=True, create_user=False) test_num += 1 comment = ("Test case {0} - Skip GTIDs (succeed) using 's_user': "******"SUPER for all slaves." "").format(test_num) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for all slaves. master_gtid_executed = self.server1.get_gtid_executed() expected_gtids = gtid_set_union(master_gtid_executed, gtid_set) if self.debug: print("\nExpected GTID_EXECUTED set: {0}".format(expected_gtids)) # Check if GTID_EXECUTED match the expected value on all slaves. try: slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) # Mask non-deterministic output. self.replace_substring(str(self.server1.port), "PORT1") self.replace_substring(str(self.server2.port), "PORT2") self.replace_substring(str(self.server3.port), "PORT3") # Mask UUID values in GTIDs. self.replace_substring(uuids[0], "UUID_m") self.replace_substring(uuids[1], "UUID_s1") self.replace_substring(uuids[2], "UUID_s2") return True
def run(self): """ Run the test cases. Return True if all tests pass, otherwise a MUTLibError is issued. """ cmd_base = "mysqlslavetrx.py" # Create user to test privileges on slaves. # No privileges granted to user on slave. if self.debug: print("\nCreating user without any privileges on slaves...") for srv in [self.server2, self.server3]: change_user_privileges(srv, 's_user', 's_pwd', srv.host, grant_list=None, revoke_list=None, disable_binlog=True, create_user=True) slave1_con = self.build_custom_connection_string( self.server2, 's_user', 's_pwd') slave2_con = self.build_custom_connection_string( self.server3, 's_user', 's_pwd') slaves_con = ",".join([slave1_con, slave2_con]) if self.debug: print("\nGet UUID of each server:") uuids = [] for srv in [self.server1, self.server2, self.server3]: uuids.append(srv.get_server_uuid()) if self.debug: for uuid in uuids: print("- {0}".format(uuid)) # Wait for slaves to catch up to ensure that the GTID_EXECUTED is the # same on all servers. if self.debug: print("\nWait for slaves to catch up with master.") self.wait_for_slaves() test_num = 1 comment = ("Test case {0} - Skip GTIDs (fail) using 's_user': no " "privileges on all slaves.").format(test_num) gtid_set = "{0}:7,{1}:7,{2}:7".format(*uuids) cmd = "{0} --slaves={1} --gtid-set={2}".format(cmd_base, slaves_con, gtid_set) res = self.run_test_case(1, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Grant all required privileges (SUPER) to user on Slave 1. if self.debug: print("\nGrant all required privileges (SUPER) on Slave 1.") slave_grants = ['SUPER'] change_user_privileges(self.server2, 's_user', 's_pwd', self.server2.host, grant_list=slave_grants, revoke_list=None, disable_binlog=True, create_user=False) test_num += 1 comment = ("Test case {0} - Skip GTIDs (fail) using 's_user': "******"SUPER for slave1 and no privileges for slave2." "").format(test_num) res = self.run_test_case(1, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Grant all required privileges (SUPER) to user on Slave 2. if self.debug: print("\nGrant all required privileges (SUPER) on Slave 2.") change_user_privileges(self.server3, 's_user', 's_pwd', self.server3.host, grant_list=slave_grants, revoke_list=None, disable_binlog=True, create_user=False) test_num += 1 comment = ("Test case {0} - Skip GTIDs (succeed) using 's_user': "******"SUPER for all slaves." "").format(test_num) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for all slaves. master_gtid_executed = self.server1.get_gtid_executed() expected_gtids = gtid_set_union(master_gtid_executed, gtid_set) if self.debug: print("\nExpected GTID_EXECUTED set: {0}".format(expected_gtids)) # Check if GTID_EXECUTED match the expected value on all slaves. try: slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) # Mask non-deterministic output. self.replace_substring(str(self.server1.port), "PORT1") self.replace_substring(str(self.server2.port), "PORT2") self.replace_substring(str(self.server3.port), "PORT3") # Mask UUID values in GTIDs. self.replace_substring(uuids[0], "UUID_m") self.replace_substring(uuids[1], "UUID_s1") self.replace_substring(uuids[2], "UUID_s2") return True
def run(self): """ Run the test cases. Return True if all tests pass, otherwise a MUTLibError is issued. """ cmd_base = "mysqlslavetrx.py" slave1_con = self.build_connection_string(self.server2).strip(' ') slave2_con = self.build_connection_string(self.server3).strip(' ') slaves_con = ",".join([slave1_con, slave2_con]) if self.debug: print("\nGet UUID of each server:") uuids = [] for srv in [self.server1, self.server2, self.server3]: uuids.append(srv.get_server_uuid()) if self.debug: for uuid in uuids: print("- {0}".format(uuid)) # Wait for slaves to catch up to ensure that the GTID_EXECUTED is the # same on all servers. if self.debug: print("\nWait for slaves to catch up with master.") self.wait_for_slaves() test_num = 1 comment = "Test case {0} - Help.".format(test_num) cmd = "{0} --help".format(cmd_base) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) test_num += 1 comment = ("Test case {0} - Skip only one GTID on a single slave" ".").format(test_num) gtid_set = "{0}:10".format(uuids[0]) cmd = "{0} --slaves={1} --gtid-set={2}".format(cmd_base, slave1_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for target slave. master_gtid_executed = self.server1.get_gtid_executed() expected_gtids = gtid_set_union(master_gtid_executed, gtid_set) if self.debug: print("\nExpected GTID_EXECUTED set: {0}".format(expected_gtids)) # Check if GTID_EXECUTED match the expected value on all slaves. try: slave_trx_skip.check_gtid_executed([self.server2], expected_gtids) # No GTID skipped for server3. slave_trx_skip.check_gtid_executed([self.server3], master_gtid_executed) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) test_num += 1 comment = ("Test case {0}a - [DRYRUN] Skip GTID set on all slaves " "(previous skipped GTID is ignored).").format(test_num) gtid_set = "{0}:8-10:12,{1}:7-9,{2}:7:9".format(*uuids) cmd = "{0} --slaves={1} --gtid-set={2} --dryrun".format( cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2], expected_gtids) slave_trx_skip.check_gtid_executed([self.server3], master_gtid_executed) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) comment = ("Test case {0}b - Skip GTID set on all slaves " "(previous skipped GTID is ignored).").format(test_num) cmd = "{0} --slaves={1} --gtid-set={2}".format(cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for target slave. expected_gtids = gtid_set_union(master_gtid_executed, gtid_set) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) test_num += 1 comment = ("Test case {0} - Repeat previous command " "(No GTIDs will be skipped).").format(test_num) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same (no new GTID skipped). slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) test_num += 1 comment = ("Test case {0}a - [DRYRUN] Skip GTID set on all slaves " "(with verbose).").format(test_num) gtid_set = "{0}:10-13,{1}:8,{2}:8".format(*uuids) cmd = "{0} --slaves={1} --gtid-set={2} --dryrun -v".format( cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) comment = ("Test case {0}b - Skip GTID set on all slaves " "(with verbose).").format(test_num) cmd = "{0} --slaves={1} --gtid-set={2} -v".format( cmd_base, slaves_con, gtid_set) res = self.run_test_case(0, cmd, comment) if not res: raise MUTLibError("{0}: failed".format(comment)) # Computed expected GTID_EXECUTED set for target slave. expected_gtids = gtid_set_union(expected_gtids, gtid_set) # Check if GTID_EXECUTED match the expected value on all slaves. try: # GTID_EXECUTED is expected to be the same using dryrun mode. slave_trx_skip.check_gtid_executed([self.server2, self.server3], expected_gtids) except UtilError as err: raise MUTLibError("{0}: failed\n{1}".format(comment, err.errmsg)) # Mask non-deterministic output. self.replace_substring(str(self.server1.port), "PORT1") self.replace_substring(str(self.server2.port), "PORT2") self.replace_substring(str(self.server3.port), "PORT3") # Remove version information. self.remove_result_and_lines_after( "MySQL Utilities mysqlslavetrx " "version", 1) # Mask UUID values in GTIDs. self.replace_substring(uuids[0], "UUID_m") self.replace_substring(uuids[1], "UUID_s1") self.replace_substring(uuids[2], "UUID_s2") return True