def setup(self):
        try:
            mysqld = "--log-bin=mysql-bin {0}".format(ssl_server_opts())
            self.servers.spawn_server('ssl_server', mysqld, kill=False)
        except MUTLibError as err:
            raise MUTLibError("Cannot spawn needed servers: {0}"
                              "".format(err.errmsg))

        index = self.servers.find_server_by_name('ssl_server')
        self.server1 = self.servers.get_server(index)

        for server in [self.server1]:
            try:
                grant_proxy_ssl_privileges(server, ssl_user, ssl_pass)
                grant_proxy_ssl_privileges(server,
                                           "ssl_opt",
                                           "ssl_opt_pass",
                                           ssl=False)
            except UtilError as err:
                raise MUTLibError("{0} on:{1}".format(err.errmsg, server.role))

        conn_info = {
            'user': ssl_user,
            'passwd': ssl_pass,
            'host': self.server1.host,
            'port': self.server1.port,
            'ssl_ca': ssl_c_ca,
            'ssl_cert': ssl_c_cert,
            'ssl_key': ssl_c_key,
            'ssl': 1
        }

        self.server1 = Server.fromServer(self.server1, conn_info)
        self.server1.connect()

        res = self.server1.exec_query("SHOW STATUS LIKE 'Ssl_cipher'")
        if not res[0][1]:
            raise MUTLibError("Cannot spawn a SSL server.")

        self.drop_all()
        self.load_test_data()

        return True
Exemple #2
0
    def setup(self):
        # Remove previews configuration files (leftover from previous test).
        try:
            os.unlink(self.config_file_path)
        except OSError:
            pass
        # use --log-error option in order to normalize serverinfo
        # output between 5.6 and 5.7 servers by setting log_err to stderr
        startup_opts = "{0} --log-error=error_log".format(ssl_server_opts())
        try:
            self.servers.spawn_server('ssl_server', startup_opts, kill=False)
        except MUTLibError as err:
            raise MUTLibError("Cannot spawn needed servers: {0}"
                              "".format(err.errmsg))

        index = self.servers.find_server_by_name('ssl_server')
        self.server1 = self.servers.get_server(index)

        for server in [self.server1]:
            try:
                grant_proxy_ssl_privileges(server, ssl_user, ssl_pass)
            except UtilError as err:
                raise MUTLibError("{0} on: {1}".format(err.errmsg,
                                                       server.role))

        conn_info = {
            'user': ssl_user,
            'passwd': ssl_pass,
            'host': self.server1.host,
            'port': self.server1.port,
            'ssl_ca': ssl_c_ca,
            'ssl_cert': ssl_c_cert,
            'ssl_key': ssl_c_key,
        }

        self.server2 = Server.fromServer(self.server1, conn_info)
        self.server2.connect()

        res = self.server2.exec_query("SHOW STATUS LIKE 'Ssl_cipher'")
        if not res[0][1]:
            raise MUTLibError('Cannot setup SSL server for test')

        config_p = ConfigParser.ConfigParser()
        with open(self.config_file_path, 'w') as config_f:

            config_p.add_section('client')
            config_p.set('client', 'user', self.server1.user)
            config_p.set('client', 'password', self.server1.passwd)
            config_p.set('client', 'host', self.server1.host)
            config_p.set('client', 'port', self.server1.port)

            self.test_group_names.append(('simple group name', 'simple_login'))
            config_p.add_section('simple_login')
            config_p.set('simple_login', 'user', self.server1.user)
            config_p.set('simple_login', 'password', self.server1.passwd)
            config_p.set('simple_login', 'host', self.server1.host)
            config_p.set('simple_login', 'port', self.server1.port)

            group_name = 'very_loooooooooooooooooooooooong_group_name'
            self.test_group_names.append(('long group name ', group_name))
            config_p.add_section(group_name)
            config_p.set(group_name, 'user', self.server1.user)
            config_p.set(group_name, 'password', self.server1.passwd)
            config_p.set(group_name, 'host', self.server1.host)

            config_p.set(group_name, 'port', self.server1.port)

            group_name = 'c0Mpl1-cat3d//name_group'
            self.test_group_names.append(
                ('complicated group name ', group_name))
            config_p.add_section(group_name)
            config_p.set(group_name, 'user', self.server1.user)
            config_p.set(group_name, 'password', self.server1.passwd)
            config_p.set(group_name, 'host', self.server1.host)
            config_p.set(group_name, 'port', self.server1.port)

            config_p.add_section('ssl-login')
            self.test_group_names.append(('login with ssl', 'ssl-login'))
            config_p.set('ssl-login', 'user', self.server2.user)
            config_p.set('ssl-login', 'password', self.server2.passwd)
            config_p.set('ssl-login', 'host', self.server2.host)
            config_p.set('ssl-login', 'port', self.server2.port)
            config_p.set('ssl-login', 'ssl-ca', self.server2.ssl_ca)
            config_p.set('ssl-login', 'ssl-cert', self.server2.ssl_cert)
            config_p.set('ssl-login', 'ssl-key', self.server2.ssl_key)
            config_p.write(config_f)

        return True
Exemple #3
0
    def run(self):
        quote_char = "'" if os.name == "posix" else '"'
        self.server0 = self.servers.get_server(0)
        cmd_str = "mysqlserverclone.py --server={0} --delete-data ".format(
            self.build_connection_string(self.server0))

        port1 = self.servers.get_next_port()
        cmd_str = "{0} --new-port={1} --root-password=root ".format(
            cmd_str, port1)
        test_num = 1
        comment = "Test case {0} - clone a running server".format(test_num)
        self.results.append(comment + "\n")
        # Create a new-dir whose size with socket file is > 107 chars
        o_path_size = 108 - (len(os.getcwd()) + 22 + len(str(port1)))
        full_datadir = os.path.join(
            os.getcwd(), "temp_{0}_lo{1}ng".format(port1, 'o' * o_path_size))
        cmd_str = ("{0}--new-data={2}{1}{2} "
                   "".format(cmd_str, full_datadir, quote_char))
        res = self.exec_util(cmd_str, "start.txt")
        with open("start.txt") as f:
            for line in f:
                # Don't save lines that have [Warning]
                if "[Warning]" in line:
                    continue
                self.results.append(line)
        if res:
            raise MUTLibError("{0}: failed".format(comment))

        self.new_server = self.check_connect(port1)

        # Get basedir
        rows = self.server0.exec_query("SHOW VARIABLES LIKE 'basedir'")
        if not rows:
            raise UtilError("Unable to determine basedir of running server.")

        basedir = os.path.normpath(rows[0][1])
        port2 = int(self.servers.get_next_port())
        cmd_str = ("mysqlserverclone.py --root-password=root --delete-data "
                   "--new-port={0} --basedir={2}{1}{2} "
                   "".format(port2, basedir, quote_char))

        test_num += 1
        comment = ("Test case {0} - clone a server from "
                   "basedir".format(test_num))
        self.results.append(comment + "\n")
        full_datadir = os.path.join(os.getcwd(), "temp_{0}".format(port2))
        cmd_str = ("{0} --new-data={2}{1}{2} "
                   "".format(cmd_str, full_datadir, quote_char))

        res = self.exec_util(cmd_str, "start.txt")
        with open("start.txt") as f:
            for line in f:
                # Don't save lines that have [Warning]
                if "[Warning]" in line:
                    continue
                self.results.append(line)
        if res:
            raise MUTLibError("{0}: failed".format(comment))

        server = self.check_connect(port2, "cloned_server_basedir")
        self.servers.stop_server(server)
        self.servers.clear_last_port()

        # Test clone server option mysqld with SSL and basedir option
        # Also Used for next test, clone a running server with SSL
        test_num += 1
        comment = ("Test case {0} - clone a server from "
                   "basedir with SSL".format(test_num))
        self.results.append(comment + "\n")
        cmd_str = '{0} --mysqld="{1}"'.format(cmd_str, ssl_server_opts())
        res = self.exec_util(cmd_str, "start.txt")
        with open("start.txt") as f:
            for line in f:
                # Don't save lines that have [Warning]
                if "[Warning]" in line:
                    continue
                self.results.append(line)
        if res:
            raise MUTLibError("{0}: failed".format(comment))

        ssl_server = self.check_connect(port2, "cloned_server_basedir")
        ssl_server.exec_query(CREATE_SSL_USER_2)

        test_num += 1
        comment = ("Test case {0} - clone a running server with SSL "
                   "and using spaces in the path".format(test_num))
        port3 = int(self.servers.get_next_port())
        self.results.append(comment + "\n")
        full_datadir = os.path.join(os.getcwd(), "temp with spaces "
                                    "{0}".format(port3))
        cmd_str = ("mysqlserverclone.py --server={0} --delete-data ").format(
            self.build_custom_connection_string(ssl_server, "root_ssl",
                                                "root_ssl"))
        cmd_str = ("{0} --new-data={2}{1}{2} "
                   "".format(cmd_str, full_datadir, quote_char))
        cmd_str = ('{0} {1} --new-port={2} --root-password=root --mysqld='
                   '"{3}"').format(cmd_str,
                                   SSL_OPTS_UTIL.format(STD_DATA_PATH), port3,
                                   ssl_server_opts())
        res = self.exec_util(cmd_str, "start.txt")
        with open("start.txt") as f:
            for line in f:
                # Don't save lines that have [Warning]
                if "[Warning]" in line:
                    continue
                self.results.append(line)
        if res:
            raise MUTLibError("{0}: failed".format(comment))

        new_server = self.check_connect(port3)
        new_server.exec_query(CREATE_SSL_USER_2)

        conn_ssl = {
            "user": "******",
            "passwd": "root_ssl",
            "ssl_cert": SSL_CERT.format(STD_DATA_PATH),
            "ssl_ca": SSL_CA.format(STD_DATA_PATH),
            "ssl_key": SSL_KEY.format(STD_DATA_PATH),
        }

        new_server_ssl = self.check_connect(port3, conn_dict=conn_ssl)

        self.servers.stop_server(ssl_server)
        self.servers.clear_last_port()

        self.servers.stop_server(new_server_ssl)
        self.servers.clear_last_port()

        self.replace_result(
            "# Cloning the MySQL server running on",
            "# Cloning the MySQL server running on xxxxx-"
            "xxxxx.\n")

        self.replace_result("#  -uroot", "#  -uroot [...]\n")
        self.replace_result("# Cloning the MySQL server located at",
                            "# Cloning the MySQL server located at XXXX\n")
        # Since it may or may not appear, depending on size of path or Windows,
        # remove it
        self.remove_result("# WARNING: The socket file path '")

        return True