Esempio n. 1
0
    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(' ')
        slave3_conn = self.build_connection_string(self.server4).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(master_conn.split('@')[0])

        comment = ("Test case {0} - mysqlbinlogpurge: with discover option"
                   "".format(test_num))
        cmds = "{0} {1}".format(cmd_str, cmd_opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 1 and 5 must not exists
        if not res or True in binlog_range_files_exists(
            (1, 5), self.master_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)

        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: with discover "
                   "and verbose options".format(test_num))
        cmds = ("{0} {1} {2} -vv"
                "").format(cmd_str, cmd_opts, "binlog_purge{0}.log".format(1))
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 6 and 10 must not exists
        if not res or True in binlog_range_files_exists(
            (6, 10), self.master_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self,
                                      slaves_list=self.slaves,
                                      master=self.server1)

        cmd_opts = "--slaves={0},{1},{2} ".format(slave1_conn, slave2_conn,
                                                  slave3_conn)
        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: slaves option"
                   "".format(test_num))
        cmds = "{0} {1} ".format(cmd_str, cmd_opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 11 and 15 must not exists
        if not res or True in binlog_range_files_exists(
            (11, 15), self.master_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self,
                                      slaves_list=self.slaves,
                                      master=self.server1)

        cmd_opts = "--slaves={0},{1},{2} ".format(slave1_conn, slave2_conn,
                                                  slave3_conn)
        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: slaves and verbose "
                   "options".format(test_num))
        cmds = "{0} {1} -vv".format(cmd_str, cmd_opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 16 and 20 must not exists
        if not res or True in binlog_range_files_exists(
            (16, 20), self.master_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self,
                                      slaves_list=self.slaves,
                                      master=self.server1)

        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: --binlog "
                   "option".format(test_num))
        opts = "{0} --binlog={1}".format(cmd_opts, "mysql-bin.0000023")
        cmds = "{0} {1}".format(cmd_str, opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 21 and 22 must not exists
        if not res or True in binlog_range_files_exists(
            (21, 22), self.master_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self,
                                      slaves_list=self.slaves,
                                      master=self.server1)

        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: --binlog "
                   "option and verbose".format(test_num))
        opts = "{0} --binlog={1}".format(cmd_opts, "mysql-bin.27")
        cmds = "{0} {1} -v".format(cmd_str, opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 23 and 26 must not exists
        if not res or True in binlog_range_files_exists(
            (23, 26), self.master_datadir, debug=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))

        io_reading = "I/O thread is currently reading: mysql-bin.{0}"
        sql_executed = "executed by the SQL thread: mysql-bin.{0}"

        # Mask binlog file numbers range, limited by calls to flush logs
        for num in range(5, 62):
            self.replace_substring(io_reading.format(repr(num).zfill(6)),
                                   io_reading.format("XXXXXX"))
            self.replace_substring(sql_executed.format(repr(num).zfill(6)),
                                   sql_executed.format("XXXXXX"))

        self.replace_result("# File position of the I/O thread:",
                            "# File position of the I/O thread: XXX\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} - 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} -mysqlbinlogpurge with verbose (-vv)"
                   "".format(test_num))
        cmd = "{0} -vv".format(cmd_str)
        res = self.run_test_case(0, cmd, comment)
        # Binlog Files 1 and 2 must not exists
        if not res or True in binlog_range_files_exists(
            (1, 2), self.server1_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge No binlog files to purge"
                   "".format(test_num))
        cmd = "{0}".format(cmd_str)
        res = self.run_test_case(0, cmd, comment)
        # Binlog File 3 must exists, no binlog was flushed
        if not res or False in binlog_range_files_exists(
            (3, 3), self.server1_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        # Flush master binary logs
        self.server1.exec_query("FLUSH LOGS")

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge dry-run (-d)"
                   "".format(test_num))
        cmd = "{0} -d".format(cmd_str)
        res = self.run_test_case(0, cmd, comment)
        # Binlog File 3 must exists (-d used)
        if not res or False in binlog_range_files_exists(
            (3, 3), self.server1_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        for _ in range(3):
            self.server1.exec_query("FLUSH LOGS")

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge --binlog option"
                   "".format(test_num))
        cmd = "{0} --binlog={1} -vv".format(cmd_str, "mysql-bin.000004")
        res = self.run_test_case(0, cmd, comment)
        # Binlog File 3 must not exists
        if not res or True in binlog_range_files_exists(
            (3, 3), self.server1_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge --binlog option"
                   " warning not found".format(test_num))
        cmd = "{0} --binlog={1} -vv".format(cmd_str, "mysql-bin.000003")
        res = self.run_test_case(0, cmd, comment)
        # Binlog Files 4 to 7 must exists
        if not res or False in binlog_range_files_exists(
            (4, 7), self.server1_datadir, debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        # Remove version information
        self.remove_result_and_lines_after(
            "MySQL Utilities mysqlbinlogpurge"
            " version", 6)

        self.replace_result(
            "WARNING: Could not find the given binlog name: ",
            "WARNING: Could not find the given binlog name: 'mysql-bin.000003'"
            " in the binlog files listed in the server: XXXX-XXXX:XXXX\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} - 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} -mysqlbinlogpurge with verbose (-vv)"
                   "".format(test_num))
        cmd = "{0} -vv".format(cmd_str)
        res = self.run_test_case(0, cmd, comment)
        # Binlog Files 1 and 2 must not exists
        if not res or True in binlog_range_files_exists((1, 2),
                                                        self.server1_datadir,
                                                        debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge No binlog files to purge"
                   "".format(test_num))
        cmd = "{0}".format(cmd_str)
        res = self.run_test_case(0, cmd, comment)
        # Binlog File 3 must exists, no binlog was flushed
        if not res or False in binlog_range_files_exists((3, 3),
                                                         self.server1_datadir,
                                                         debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        # Flush master binary logs
        self.server1.exec_query("FLUSH LOGS")

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge dry-run (-d)"
                   "".format(test_num))
        cmd = "{0} -d".format(cmd_str)
        res = self.run_test_case(0, cmd, comment)
        # Binlog File 3 must exists (-d used)
        if not res or False in binlog_range_files_exists((3, 3),
                                                         self.server1_datadir,
                                                         debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        for _ in range(3):
            self.server1.exec_query("FLUSH LOGS")

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge --binlog option"
                   "".format(test_num))
        cmd = "{0} --binlog={1} -vv".format(cmd_str, "mysql-bin.000004")
        res = self.run_test_case(0, cmd, comment)
        # Binlog File 3 must not exists
        if not res or True in binlog_range_files_exists((3, 3),
                                                        self.server1_datadir,
                                                        debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        test_num += 1
        comment = ("Test case {0} -mysqlbinlogpurge --binlog option"
                   " warning not found".format(test_num))
        cmd = "{0} --binlog={1} -vv".format(cmd_str, "mysql-bin.000003")
        res = self.run_test_case(0, cmd, comment)
        # Binlog Files 4 to 7 must exists
        if not res or False in binlog_range_files_exists((4, 7),
                                                         self.server1_datadir,
                                                         debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        # Remove version information
        self.remove_result_and_lines_after("MySQL Utilities mysqlbinlogpurge"
                                           " version", 6)

        self.replace_result(
            "WARNING: Could not find the given binlog name: ",
            "WARNING: Could not find the given binlog name: 'mysql-bin.000003'"
            " in the binlog files listed in the server: XXXX-XXXX:XXXX\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(' ')
        slave3_conn = self.build_connection_string(self.server4).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(master_conn.split('@')[0])

        comment = ("Test case {0} - mysqlbinlogpurge: with discover option"
                   "".format(test_num))
        cmds = "{0} {1}".format(cmd_str, cmd_opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 1 and 5 must not exists
        if not res or True in binlog_range_files_exists((1, 5),
                                                        self.master_datadir,
                                                        debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)

        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: with discover "
                   "and verbose options".format(test_num))
        cmds = ("{0} {1} -vv"
                "").format(cmd_str, cmd_opts, "binlog_purge{0}.log".format(1))
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 6 and 10 must not exists
        if not res or True in binlog_range_files_exists((6, 10),
                                                        self.master_datadir,
                                                        debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self, slaves_list=self.slaves,
                                      master=self.server1)

        cmd_opts = "--slaves={0},{1},{2} ".format(slave1_conn, slave2_conn,
                                                  slave3_conn)
        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: slaves option"
                   "".format(test_num))
        cmds = "{0} {1} ".format(cmd_str, cmd_opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 11 and 15 must not exists
        if not res or True in binlog_range_files_exists((11, 15),
                                                        self.master_datadir,
                                                        debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self, slaves_list=self.slaves,
                                      master=self.server1)

        cmd_opts = "--slaves={0},{1},{2} ".format(slave1_conn, slave2_conn,
                                                  slave3_conn)
        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: slaves and verbose "
                   "options".format(test_num))
        cmds = "{0} {1} -vv".format(cmd_str, cmd_opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 16 and 20 must not exists
        if not res or True in binlog_range_files_exists((16, 20),
                                                        self.master_datadir,
                                                        debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self, slaves_list=self.slaves,
                                      master=self.server1)

        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: --binlog "
                   "option".format(test_num))
        opts = "{0} --binlog={1}".format(cmd_opts, "mysql-bin.0000023")
        cmds = "{0} {1}".format(cmd_str, opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 21 and 22 must not exists
        if not res or True in binlog_range_files_exists((21, 22),
                                                        self.master_datadir,
                                                        debug=self.debug):
            raise MUTLibError("{0}: failed".format(comment))

        flush_server_logs_(self.server1)
        rpl_admin.test.reset_topology(self, slaves_list=self.slaves,
                                      master=self.server1)

        test_num += 1
        comment = ("Test case {0} - mysqlbinlogpurge: --binlog "
                   "option and verbose".format(test_num))
        opts = "{0} --binlog={1}".format(cmd_opts, "mysql-bin.27")
        cmds = "{0} {1} -v".format(cmd_str, opts)
        res = self.run_test_case(0, cmds, comment)
        # Binlog Files 23 and 26 must not exists
        if not res or True in binlog_range_files_exists((23, 26),
                                                        self.master_datadir,
                                                        debug=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))

        io_reading = "I/O thread is currently reading: mysql-bin.{0}"
        sql_executed = "executed by the SQL thread: mysql-bin.{0}"

        # Mask binlog file numbers range, limited by calls to flush logs
        for num in range(5, 62):
            self.replace_substring(io_reading.format(repr(num).zfill(6)),
                                   io_reading.format("XXXXXX"))
            self.replace_substring(sql_executed.format(repr(num).zfill(6)),
                                   sql_executed.format("XXXXXX"))

        self.replace_result(
            "# File position of the I/O thread:",
            "# File position of the I/O thread: XXX\n"
        )

        return True