def run(self):
        cmd_base = "mysqlrplsync.py"
        master_con = self.build_connection_string(self.server1).strip(" ")
        slave1_con = self.build_connection_string(self.server2).strip(" ")
        slave2_con = self.build_connection_string(self.server3).strip(" ")
        slaves_con = "{0},{1}".format(slave1_con, slave2_con)

        # Check the data consistency of empty servers.
        test_num = 1
        comment = ("Test case {0} - check empty servers." "").format(test_num)
        cmd = "{0} --master={1} --slaves={2} {3}".format(cmd_base, master_con, slaves_con, ssl_util_opts())
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Create example database on master and wait for it to be replicated
        # on all slaves.
        if self.debug:
            print("\nCreate test database and tables on master.")
        rpl_sync.create_test_db(self.server1)

        # Wait for slaves to catch up, otherwise mysqlrplsync might find tables
        # missing on slaves (which is normal).
        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves()

        # Load data on the master in a separated thread to perform the data
        # consistency checks at the same time.
        load_thread = threading.Thread(target=rpl_sync.load_test_data, args=(self.server1,))
        load_thread.daemon = True
        load_thread.start()
        if self.debug:
            print("\nThread to load/insert data started.")
            start_time = time.time()
            end_time = None

        # Check data consistency specifying the master and using discovery.
        test_num += 1
        comment = (
            "Test case {0} - data consistency check with active " "replication using master and slaves discovery." ""
        ).format(test_num)
        cmd = ("{0} --master={1} --discover-slaves-login=root:root {2}" "").format(
            cmd_base, master_con, ssl_util_opts()
        )
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            alive = load_thread.is_alive()
            print("\nIs thread (loading data) still alive? " "{0}.".format(alive))
            if not alive and not end_time:
                end_time = time.time()
                print("\nTime to load data took less than: {0} " "sec.".format(end_time - start_time))
            else:
                print("\nWaiting for thread (loading data) to finish.")

        # Wait for all the data to finish to be loaded.
        load_thread.join()
        if self.debug and not end_time:
            end_time = time.time()
            print("\nTime to load data: {0} " "sec.".format(end_time - start_time))

        # Drop test database and recreate it on master.
        if self.debug:
            print("\nDrop test database on master.")
        rpl_sync.drop_test_db(self.server1)
        if self.debug:
            print("\nCreate test database and tables on master.")
        rpl_sync.create_test_db(self.server1)

        # Wait for slaves to catch up (avoiding non-deterministic results).
        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves()

        # Start a new thread to load/insert data (can only be started once).
        load_thread = threading.Thread(target=rpl_sync.load_test_data, args=(self.server1,))
        load_thread.daemon = True
        load_thread.start()
        if self.debug:
            print("\nThread to load/insert data started.")
            start_time = time.time()
            end_time = None

        # Check data consistency specifying only the slaves.
        test_num += 1
        comment = (
            "Test case {0} - data consistency check with active " "replication only between slaves (no master)." ""
        ).format(test_num)
        cmd = "{0} --slaves={1} {2}".format(cmd_base, slaves_con, ssl_util_opts())
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            alive = load_thread.is_alive()
            print("\nIs thread (loading data) still alive? " "{0}.".format(alive))
            if not alive and not end_time:
                end_time = time.time()
                print("\nTime to load data took less than: {0} " "sec.".format(end_time - start_time))
            else:
                print("Waiting for thread (loading data) to finish.")

        # Wait for all the data to finish to be loaded.
        load_thread.join()
        if self.debug and not end_time:
            end_time = time.time()
            print("\nTime to load data: {0} " "sec.".format(end_time - start_time))

        # Perform data consistency check after loading all data.
        test_num += 1
        comment = ("Test case {0} - data consistency check between master and " "specified slaves.").format(test_num)
        cmd = "{0} --master={1} --slaves={2} {3}".format(cmd_base, master_con, slaves_con, ssl_util_opts())
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Mask out non-deterministic data
        self.do_masks()

        return True
Esempio n. 2
0
    def run(self):
        cmd_base = "mysqlrplsync.py"
        master1_con = self.build_connection_string(self.server1).strip(' ')
        master2_con = self.build_connection_string(self.server2).strip(' ')
        slave1_con = self.build_connection_string(self.server3).strip(' ')
        slave2_con = self.build_connection_string(self.server4).strip(' ')
        slaves_con = ",".join([slave1_con, slave2_con])
        slave3_con = self.build_connection_string(self.server5).strip(' ')
        slave4_con = self.build_connection_string(self.server6).strip(' ')
        slave5_con = self.build_connection_string(self.server7).strip(' ')

        if self.debug:
            print("\nCreate test databases and tables on master.")
        rpl_sync.create_test_db(self.server1, db_num=4)

        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves([self.server3, self.server4])

        # Skip check of databases with replication filters (case 1).
        # master: --binlog-do-db=test_rplsync_db1
        # slave1: --replicate-do-table=test_rplsync_db1.t1
        # slave2: --replicate-ignore-table=test_rplsync_db1.t2
        #         --replicate-wild-ignore-table=test\_rplsync\_db1.%3
        test_num = 1
        comment = ("Test case {0} - check replication filters skip (case 1)."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2} -v".format(
            cmd_base, master1_con, slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - check replication filters skip (case 1) - "
                   "only with slaves.").format(test_num)
        cmd = "{0} --slaves={1} -v".format(cmd_base, slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            print("\nDrop test databases on master.")
        rpl_sync.drop_test_db(self.server1, db_num=4)

        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves([self.server3, self.server4])

        if self.debug:
            print("\nReset topology with a new master.")
        self.reset_master([self.server2, self.server3, self.server4])
        self.reset_topology([self.server3, self.server4], master=self.server2)

        if self.debug:
            print("\nCreate test databases and tables on master.")
        rpl_sync.create_test_db(self.server2, db_num=4)

        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves([self.server3, self.server4], master=self.server2)

        # Skip check of databases with replication filters (case 2).
        # master: --binlog-ignore-db=test_rplsync_db2
        # slave1: --replicate-do-table=test_rplsync_db1.t1
        # slave2: --replicate-ignore-table=test_rplsync_db1.t2
        #         --replicate-wild-ignore-table=test\_rplsync\_db1.%3
        test_num += 1
        comment = ("Test case {0} - check replication filters skip (case 2)."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2} -v".format(
            cmd_base, master2_con, slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - check replication filters skip (case 2) - "
                   "only with slaves.").format(test_num)
        cmd = "{0} --slaves={1} -v".format(cmd_base, slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            print("\nReset topology with new slaves.")
        self.reset_master(
            [self.server2, self.server5, self.server6, self.server7])
        self.reset_topology([self.server5, self.server6, self.server7],
                            master=self.server2)

        # Options replicate-do-db, replicate-ignore-db, and
        # replicate-wild-do-db are not supported due to known issues on the
        # server, leading to inconsistent GTID_EXECUTED sets.
        test_num += 1
        comment = ("Test case {0} - error using replicate-do-db."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2}".format(cmd_base, master2_con,
                                                     slave3_con)
        res = self.run_test_case(1, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - error using replicate-ignore-db."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2}".format(cmd_base, master2_con,
                                                     slave4_con)
        res = self.run_test_case(1, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - error using replicate-wild-do-db."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2}".format(cmd_base, master2_con,
                                                     slave5_con)
        res = self.run_test_case(1, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Mask out non-deterministic data
        self.do_masks()

        return True
Esempio n. 3
0
    def run(self):
        cmd_base = "mysqlrplsync.py"
        master_con = self.build_connection_string(self.server1).strip(' ')
        slave1_con = self.build_connection_string(self.server2).strip(' ')
        slave2_con = self.build_connection_string(self.server3).strip(' ')
        slaves_con = "{0},{1}".format(slave1_con, slave2_con)

        # Check the data consistency of empty servers.
        test_num = 1
        comment = ("Test case {0} - check empty servers."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2} {3}".format(cmd_base, master_con,
                                                         slaves_con,
                                                         ssl_util_opts())
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Create example database on master and wait for it to be replicated
        # on all slaves.
        if self.debug:
            print("\nCreate test database and tables on master.")
        rpl_sync.create_test_db(self.server1)

        # Wait for slaves to catch up, otherwise mysqlrplsync might find tables
        # missing on slaves (which is normal).
        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves()

        # Load data on the master in a separated thread to perform the data
        # consistency checks at the same time.
        load_thread = threading.Thread(target=rpl_sync.load_test_data,
                                       args=(self.server1,))
        load_thread.daemon = True
        load_thread.start()
        if self.debug:
            print("\nThread to load/insert data started.")
            start_time = time.time()
            end_time = None

        # Check data consistency specifying the master and using discovery.
        test_num += 1
        comment = ("Test case {0} - data consistency check with active "
                   "replication using master and slaves discovery."
                   "").format(test_num)
        cmd = ("{0} --master={1} --discover-slaves-login=root:root {2}"
               "").format(cmd_base, master_con, ssl_util_opts())
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            alive = load_thread.is_alive()
            print("\nIs thread (loading data) still alive? "
                  "{0}.".format(alive))
            if not alive and not end_time:
                end_time = time.time()
                print("\nTime to load data took less than: {0} "
                      "sec.".format(end_time - start_time))
            else:
                print("\nWaiting for thread (loading data) to finish.")

        # Wait for all the data to finish to be loaded.
        load_thread.join()
        if self.debug and not end_time:
            end_time = time.time()
            print("\nTime to load data: {0} "
                  "sec.".format(end_time - start_time))

        # Drop test database and recreate it on master.
        if self.debug:
            print("\nDrop test database on master.")
        rpl_sync.drop_test_db(self.server1)
        if self.debug:
            print("\nCreate test database and tables on master.")
        rpl_sync.create_test_db(self.server1)

        # Wait for slaves to catch up (avoiding non-deterministic results).
        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves()

        # Start a new thread to load/insert data (can only be started once).
        load_thread = threading.Thread(target=rpl_sync.load_test_data,
                                       args=(self.server1,))
        load_thread.daemon = True
        load_thread.start()
        if self.debug:
            print("\nThread to load/insert data started.")
            start_time = time.time()
            end_time = None

        # Check data consistency specifying only the slaves.
        test_num += 1
        comment = ("Test case {0} - data consistency check with active "
                   "replication only between slaves (no master)."
                   "").format(test_num)
        cmd = "{0} --slaves={1} {2}".format(cmd_base, slaves_con,
                                            ssl_util_opts())
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            alive = load_thread.is_alive()
            print("\nIs thread (loading data) still alive? "
                  "{0}.".format(alive))
            if not alive and not end_time:
                end_time = time.time()
                print("\nTime to load data took less than: {0} "
                      "sec.".format(end_time - start_time))
            else:
                print("Waiting for thread (loading data) to finish.")

        # Wait for all the data to finish to be loaded.
        load_thread.join()
        if self.debug and not end_time:
            end_time = time.time()
            print("\nTime to load data: {0} "
                  "sec.".format(end_time - start_time))

        # Perform data consistency check after loading all data.
        test_num += 1
        comment = ("Test case {0} - data consistency check between master and "
                   "specified slaves.").format(test_num)
        cmd = "{0} --master={1} --slaves={2} {3}".format(cmd_base, master_con,
                                                         slaves_con,
                                                         ssl_util_opts())
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Mask out non-deterministic data
        self.do_masks()

        return True
    def run(self):
        cmd_base = "mysqlrplsync.py"
        master1_con = self.build_connection_string(self.server1).strip(' ')
        master2_con = self.build_connection_string(self.server2).strip(' ')
        slave1_con = self.build_connection_string(self.server3).strip(' ')
        slave2_con = self.build_connection_string(self.server4).strip(' ')
        slaves_con = ",".join([slave1_con, slave2_con])
        slave3_con = self.build_connection_string(self.server5).strip(' ')
        slave4_con = self.build_connection_string(self.server6).strip(' ')
        slave5_con = self.build_connection_string(self.server7).strip(' ')

        if self.debug:
            print("\nCreate test databases and tables on master.")
        rpl_sync.create_test_db(self.server1, db_num=4)

        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves([self.server3, self.server4])

        # Skip check of databases with replication filters (case 1).
        # master: --binlog-do-db=test_rplsync_db1
        # slave1: --replicate-do-table=test_rplsync_db1.t1
        # slave2: --replicate-ignore-table=test_rplsync_db1.t2
        #         --replicate-wild-ignore-table=test\_rplsync\_db1.%3
        test_num = 1
        comment = ("Test case {0} - check replication filters skip (case 1)."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2} -v".format(cmd_base, master1_con,
                                                        slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - check replication filters skip (case 1) - "
                   "only with slaves.").format(test_num)
        cmd = "{0} --slaves={1} -v".format(cmd_base, slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            print("\nDrop test databases on master.")
        rpl_sync.drop_test_db(self.server1, db_num=4)

        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves([self.server3, self.server4])

        if self.debug:
            print("\nReset topology with a new master.")
        self.reset_master([self.server2, self.server3, self.server4])
        self.reset_topology([self.server3, self.server4], master=self.server2)

        if self.debug:
            print("\nCreate test databases and tables on master.")
        rpl_sync.create_test_db(self.server2, db_num=4)

        if self.debug:
            print("\nWait for slaves to catch up with master.")
        self.wait_for_slaves([self.server3, self.server4], master=self.server2)

        # Skip check of databases with replication filters (case 2).
        # master: --binlog-ignore-db=test_rplsync_db2
        # slave1: --replicate-do-table=test_rplsync_db1.t1
        # slave2: --replicate-ignore-table=test_rplsync_db1.t2
        #         --replicate-wild-ignore-table=test\_rplsync\_db1.%3
        test_num += 1
        comment = ("Test case {0} - check replication filters skip (case 2)."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2} -v".format(cmd_base, master2_con,
                                                        slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - check replication filters skip (case 2) - "
                   "only with slaves.").format(test_num)
        cmd = "{0} --slaves={1} -v".format(cmd_base, slaves_con)
        res = self.run_test_case(0, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        if self.debug:
            print("\nReset topology with new slaves.")
        self.reset_master([self.server2, self.server5, self.server6,
                           self.server7])
        self.reset_topology([self.server5, self.server6, self.server7],
                            master=self.server2)

        # Options replicate-do-db, replicate-ignore-db, and
        # replicate-wild-do-db are not supported due to known issues on the
        # server, leading to inconsistent GTID_EXECUTED sets.
        test_num += 1
        comment = ("Test case {0} - error using replicate-do-db."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2}".format(cmd_base, master2_con,
                                                     slave3_con)
        res = self.run_test_case(1, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - error using replicate-ignore-db."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2}".format(cmd_base, master2_con,
                                                     slave4_con)
        res = self.run_test_case(1, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} - error using replicate-wild-do-db."
                   "").format(test_num)
        cmd = "{0} --master={1} --slaves={2}".format(cmd_base, master2_con,
                                                     slave5_con)
        res = self.run_test_case(1, cmd, comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Mask out non-deterministic data
        self.do_masks()

        return True