示例#1
0
        "switchover_interval": opt.switchover_interval,
        "from_beginning": opt.from_beginning,
        "report_values": opt.report_values,
        'format': opt.format,
        "rpl_user": opt.rpl_user,
        "daemon": opt.daemon,
        "pidfile": opt.pidfile,
        "logging": opt.log_file is not None,
        "log_file": opt.log_file,
    }

    # Add ssl values to options instead of connection.
    options.update(get_ssl_dict(opt))

    # Log MySQL Utilities version string
    if opt.log_file:
        logging.info(
            MSG_UTILITIES_VERSION.format(utility=program,
                                         version=VERSION_STRING))
    try:
        start_ms_replication(slave_vals, masters_vals, options)
    except UtilError:
        _, e, _ = sys.exc_info()
        errmsg = e.errmsg.strip(" ")
        if opt.log_file:
            logging.log(logging.CRITICAL, errmsg)
        print("ERROR: {0}".format(errmsg))
        sys.exit(1)

    sys.exit(0)
    def run(self):
        master_conn = self.build_connection_string(self.server1).strip(' ')
        slave_conn = self.build_connection_string(self.server2).strip(' ')

        # For this test, it's OK when master and slave are the same
        master_str = "--master={0}".format(master_conn)
        slave_str = "--slave={0}".format(slave_conn)

        # command used in test cases: replace 3 element with location of
        # log file.
        cmd = [
            "mysqlrpladmin.py",
            master_str,
            slave_str,
            "--log={0}".format(_LOGNAME),
            "health",
        ]

        # Test Case 1
        test_num = 1
        comment = "Test Case {0} - Log file is newly created".format(test_num)
        res = mutlib.System_test.run_test_case(self, 0, ' '.join(cmd), comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Test Case 2
        test_num += 1
        comment = "Test Case {0} - Log file is reopened".format(test_num)
        res = mutlib.System_test.run_test_case(self, 0, ' '.join(cmd), comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Test Case 3
        test_num += 1
        comment = ("Test Case {0} - Log file can not be "
                   "written to".format(test_num))
        os.chmod(_LOGNAME, stat.S_IREAD)  # Make log read-only
        res = mutlib.System_test.run_test_case(self, 2, ' '.join(cmd), comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Find MySQL and Utilities versions in the log
        self.find_stop_phrase(
            _LOGNAME, comment,
            MSG_UTILITIES_VERSION.format(utility="mysqlrpladmin",
                                         version=VERSION_STRING))

        # Find master MySQL server version in the log
        master_host_port = ("{host}:{port}".format(
            **get_connection_dictionary(master_conn)))
        self.find_stop_phrase(
            _LOGNAME, comment,
            MSG_MYSQL_VERSION.format(server=master_host_port,
                                     version=self.server1.get_version()))

        # Find slave MySQL server version in the log
        slave_host_port = ("{host}:{port}".format(
            **get_connection_dictionary(slave_conn)))
        self.find_stop_phrase(
            _LOGNAME, comment,
            MSG_MYSQL_VERSION.format(server=slave_host_port,
                                     version=self.server2.get_version()))

        # Mask out non-deterministic data
        rpl_admin.test.do_masks(self)
        self.remove_result("NOTE: Log file 'temp_log.txt' does not exist. "
                           "Will be created.")

        return True
示例#3
0
import rpl_admin_gtid

from mysql.utilities.common.server import get_local_servers
from mysql.utilities.common.tools import delete_directory
from mysql.utilities.command.rpl_admin import WARNING_SLEEP_TIME
from mysql.utilities.common.server import get_connection_dictionary
from mysql.utilities.common.messages import (MSG_UTILITIES_VERSION,
                                             MSG_MYSQL_VERSION)
from mysql.utilities.exception import MUTLibError, UtilError
from mysql.utilities import VERSION_STRING


FAILOVER_LOG = "{0}fail_log.txt"
_TIMEOUT = 30
_UTILITIES_VERSION_PHRASE = MSG_UTILITIES_VERSION.format(
    utility="mysqlfailover", version=VERSION_STRING)


class test(rpl_admin_gtid.test):
    """test replication failover console
    This test exercises the mysqlfailover utility failover event and modes.
    It uses the rpl_admin_gtid test for setup and teardown methods.
    """

    log_range = range(1, 5)

    # TODO: Perform analysis as to whether any of these methods need to be
    #       generalized and placed in the mutlib for all tests to access.

    temp_files = None
    test_results = None
示例#4
0
        "interval": opt.interval,
        "switchover_interval": opt.switchover_interval,
        "from_beginning": opt.from_beginning,
        "report_values": opt.report_values,
        'format': opt.format,
        "rpl_user": opt.rpl_user,
        "daemon": opt.daemon,
        "pidfile": opt.pidfile,
        "logging": opt.log_file is not None,
        "log_file": opt.log_file,
    }

    # Add ssl values to options instead of connection.
    options.update(get_ssl_dict(opt))

    # Log MySQL Utilities version string
    if opt.log_file:
        logging.info(MSG_UTILITIES_VERSION.format(utility=program,
                                                  version=VERSION_STRING))
    try:
        start_ms_replication(slave_vals, masters_vals, options)
    except UtilError:
        _, e, _ = sys.exc_info()
        errmsg = e.errmsg.strip(" ")
        if opt.log_file:
            logging.log(logging.CRITICAL, errmsg)
        print("ERROR: {0}".format(errmsg))
        sys.exit(1)

    sys.exit(0)
"""

import os
import stat

import mutlib
import rpl_admin

from mysql.utilities.exception import MUTLibError
from mysql.utilities.common.server import get_connection_dictionary
from mysql.utilities.common.messages import (MSG_UTILITIES_VERSION,
                                             MSG_MYSQL_VERSION)
from mysql.utilities import VERSION_STRING

_LOGNAME = "temp_log.txt"
_UTILITIES_VERSION_PHRASE = MSG_UTILITIES_VERSION.format(
    utility="mysqlrpladmin", version=VERSION_STRING)


class test(rpl_admin.test):
    """test replication administration commands
    This tests checks handling of accessibility of the log file (BUG#14208415)
    """
    def check_prerequisites(self):
        if self.servers.get_server(0).check_version_compat(5, 6, 5):
            raise MUTLibError("Test requires server version prior to 5.6.5")
        return self.check_num_servers(1)

    def setup(self):
        self.res_fname = "result.txt"
        return rpl_admin.test.setup(self)
    def run(self):
        master_conn = self.build_connection_string(self.server1).strip(' ')
        slave_conn = self.build_connection_string(self.server2).strip(' ')

        # For this test, it's OK when master and slave are the same
        master_str = "--master={0}".format(master_conn)
        slave_str = "--slave={0}".format(slave_conn)

        # command used in test cases: replace 3 element with location of
        # log file.
        cmd = [
            "mysqlrpladmin.py",
            master_str,
            slave_str,
            "--log={0}".format(_LOGNAME),
            "health",
        ]

        # Test Case 1
        test_num = 1
        comment = "Test Case {0} - Log file is newly created".format(test_num)
        res = mutlib.System_test.run_test_case(
            self, 0, ' '.join(cmd), comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Test Case 2
        test_num += 1
        comment = "Test Case {0} - Log file is reopened".format(test_num)
        res = mutlib.System_test.run_test_case(
            self, 0, ' '.join(cmd), comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Test Case 3
        test_num += 1
        comment = ("Test Case {0} - Log file can not be "
                   "written to".format(test_num))
        os.chmod(_LOGNAME, stat.S_IREAD)  # Make log read-only
        res = mutlib.System_test.run_test_case(
            self, 2, ' '.join(cmd), comment)
        if not res:
            raise MUTLibError("{0}: failed".format(comment))

        # Find MySQL and Utilities versions in the log
        self.find_stop_phrase(_LOGNAME, comment, MSG_UTILITIES_VERSION.format(
            utility="mysqlrpladmin", version=VERSION_STRING))

        # Find master MySQL server version in the log
        master_host_port = (
            "{host}:{port}".format(**get_connection_dictionary(master_conn)))
        self.find_stop_phrase(_LOGNAME, comment, MSG_MYSQL_VERSION.format(
            server=master_host_port, version=self.server1.get_version()))

        # Find slave MySQL server version in the log
        slave_host_port = (
            "{host}:{port}".format(**get_connection_dictionary(slave_conn)))
        self.find_stop_phrase(_LOGNAME, comment, MSG_MYSQL_VERSION.format(
            server=slave_host_port, version=self.server2.get_version()))

        # Mask out non-deterministic data
        rpl_admin.test.do_masks(self)
        self.remove_result("NOTE: Log file 'temp_log.txt' does not exist. "
                           "Will be created.")

        return True
import os
import stat

import mutlib
import rpl_admin

from mysql.utilities.exception import MUTLibError
from mysql.utilities.common.server import get_connection_dictionary
from mysql.utilities.common.messages import (MSG_UTILITIES_VERSION,
                                             MSG_MYSQL_VERSION)
from mysql.utilities import VERSION_STRING


_LOGNAME = "temp_log.txt"
_UTILITIES_VERSION_PHRASE = MSG_UTILITIES_VERSION.format(
    utility="mysqlrpladmin", version=VERSION_STRING)


class test(rpl_admin.test):
    """test replication administration commands
    This tests checks handling of accessibility of the log file (BUG#14208415)
    """

    def check_prerequisites(self):
        if self.servers.get_server(0).check_version_compat(5, 6, 5):
            raise MUTLibError("Test requires server version prior to 5.6.5")
        return self.check_num_servers(1)

    def setup(self):
        self.res_fname = "result.txt"
        return rpl_admin.test.setup(self)
示例#8
0
    def test_rplms(self, cmd, logfile, comment, kill_process=True,
                   stop_phrase=None):
        """Test multi-source replication.

        cmd[in]           Command to be executed.
        logfile[in]       Log filename.
        comment[in]       Test comment.
        kill_process[in]  True if the process is to be killed.
        stop_phrase[in]   Stop phrase to be searched in the log.

        This method create a process by executing the command and waits for
        the round-robin scheduling to switch all the masters. At the end
        compares the databases.
        """
        # Since this test case expects the process to stop, we can launch it
        # via a subprocess and wait for it to finish.
        if self.debug:
            print(comment)
            print("# COMMAND: {0}".format(cmd))

        # Run command
        proc, f_out = self.start_process(cmd)

        # Wait for process to load
        if self.debug:
            print("# Waiting for process to start.")
        i = 1
        time.sleep(1)
        while proc.poll() is not None:
            time.sleep(1)
            i += 1
            if i > _TIMEOUT:
                if self.debug:
                    print("# Timeout process to start.")
                raise MUTLibError("{0}: failed - timeout waiting for "
                                  "process to start.".format(comment))

        # Wait for logfile file to be created
        if self.debug:
            print("# Waiting for logfile to be created.")
        for i in range(_TIMEOUT):
            if os.path.exists(logfile):
                break
            else:
                time.sleep(1)
        else:
            raise MUTLibError("{0}: failed - timeout waiting for "
                              "logfile '{1}' to be "
                              "created.".format(comment, logfile))

        # Wait for switching all the masters
        self.wait_for_switching_all_masters(logfile, comment)

        # Compare databases
        self.compare_databases(comment)

        # Kill process
        if kill_process:
            self.kill_process(proc, f_out, comment)

        # Find stop phrase
        if stop_phrase:
            self.find_stop_phrase(logfile, comment, stop_phrase)

        # Find MySQL Utilities version in the log
        utils_phrase = MSG_UTILITIES_VERSION.format(utility="mysqlrplms",
                                                    version=VERSION_STRING)
        self.find_stop_phrase(logfile, comment, utils_phrase)

        # Find MySQL servers versions in the log
        for server in (self.server1, self.server2, self.server3,):
            host_port = "{host}:{port}".format(
                **get_connection_dictionary(server))
            server_version = server.get_version()
            mysql_phrase = MSG_MYSQL_VERSION.format(server=host_port,
                                                    version=server_version)
            self.find_stop_phrase(logfile, comment, mysql_phrase)

        # Cleanup after test case
        try:
            os.unlink(logfile)
        except OSError:
            pass
示例#9
0
    def test_rplms(self, cmd, logfile, comment, kill_process=True,
                   stop_phrase=None):
        """Test multi-source replication.

        cmd[in]           Command to be executed.
        logfile[in]       Log filename.
        comment[in]       Test comment.
        kill_process[in]  True if the process is to be killed.
        stop_phrase[in]   Stop phrase to be searched in the log.

        This method create a process by executing the command and waits for
        the round-robin scheduling to switch all the masters. At the end
        compares the databases.
        """
        # Since this test case expects the process to stop, we can launch it
        # via a subprocess and wait for it to finish.
        if self.debug:
            print(comment)
            print("# COMMAND: {0}".format(cmd))

        # Run command
        proc, f_out = self.start_process(cmd)

        # Wait for process to load
        if self.debug:
            print("# Waiting for process to start.")
        i = 1
        time.sleep(1)
        while proc.poll() is not None:
            time.sleep(1)
            i += 1
            if i > _TIMEOUT:
                if self.debug:
                    print("# Timeout process to start.")
                raise MUTLibError("{0}: failed - timeout waiting for "
                                  "process to start.".format(comment))

        # Wait for logfile file to be created
        if self.debug:
            print("# Waiting for logfile to be created.")
        for i in range(_TIMEOUT):
            if os.path.exists(logfile):
                break
            else:
                time.sleep(1)
        else:
            raise MUTLibError("{0}: failed - timeout waiting for "
                              "logfile '{1}' to be "
                              "created.".format(comment, logfile))

        # Wait for switching all the masters
        self.wait_for_switching_all_masters(logfile, comment)

        # Compare databases
        self.compare_databases(comment)

        # Kill process
        if kill_process:
            self.kill_process(proc, f_out, comment)

        # Find stop phrase
        if stop_phrase:
            self.find_stop_phrase(logfile, comment, stop_phrase)

        # Find MySQL Utilities version in the log
        utils_phrase = MSG_UTILITIES_VERSION.format(utility="mysqlrplms",
                                                    version=VERSION_STRING)
        self.find_stop_phrase(logfile, comment, utils_phrase)

        # Find MySQL servers versions in the log
        for server in (self.server1, self.server2, self.server3,):
            host_port = "{host}:{port}".format(
                **get_connection_dictionary(server))
            server_version = server.get_version()
            mysql_phrase = MSG_MYSQL_VERSION.format(server=host_port,
                                                    version=server_version)
            self.find_stop_phrase(logfile, comment, mysql_phrase)

        # Cleanup after test case
        try:
            os.unlink(logfile)
        except OSError:
            pass
示例#10
0
import rpl_admin_gtid

from mysql.utilities.common.server import get_local_servers
from mysql.utilities.common.tools import delete_directory
from mysql.utilities.command.rpl_admin import WARNING_SLEEP_TIME
from mysql.utilities.common.server import get_connection_dictionary
from mysql.utilities.common.messages import (MSG_UTILITIES_VERSION,
                                             MSG_MYSQL_VERSION)
from mysql.utilities.exception import MUTLibError, UtilError
from mysql.utilities import VERSION_STRING


FAILOVER_LOG = "{0}fail_log.txt"
_TIMEOUT = 30
_UTILITIES_VERSION_PHRASE = MSG_UTILITIES_VERSION.format(
    utility="mysqlfailover", version=VERSION_STRING)


class test(rpl_admin_gtid.test):
    """test replication failover console
    This test exercises the mysqlfailover utility failover event and modes.
    It uses the rpl_admin_gtid test for setup and teardown methods.
    """

    log_range = range(1, 5)

    # TODO: Perform analysis as to whether any of these methods need to be
    #       generalized and placed in the mutlib for all tests to access.

    temp_files = None
    test_results = None