Example #1
0
def test__galera_server_status(percona_xtradb_cluster_three_node,
                               proxysql_instance, tmpdir):
    wait_for_cluster_nodes_to_become_healthy(percona_xtradb_cluster_three_node)
    hostgroup_writer = 10
    hostgroup_reader = 11

    rw_map = {0: hostgroup_writer, 1: hostgroup_reader, 2: hostgroup_reader}
    for i in xrange(3):
        backend = ProxySQLMySQLBackend(
            hostname=percona_xtradb_cluster_three_node[i]['ip'],
            port=percona_xtradb_cluster_three_node[0]['mysql_port'],
            hostgroup_id=rw_map[i])
        proxysql_instance.register_backend(backend)

    blacklist = '{}:3306'.format(percona_xtradb_cluster_three_node[2]['ip'])
    nodes = [
        percona_xtradb_cluster_three_node[0]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[1]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[2]['ip'] + ':3306'
    ]
    config = proxysql_tools_config_2(proxysql_instance, nodes, 'root', 'r00t',
                                     hostgroup_writer, hostgroup_reader,
                                     blacklist, 'monitor', 'monitor')
    config_file = str(tmpdir.join('proxysql-tool.cfg'))
    with open(config_file, 'w') as fh:
        config.write(fh)
        proxysql_tools.LOG.debug('proxysql-tools config: \n%s', config)
    runner = CliRunner()
    result = runner.invoke(main,
                           ['--config', config_file, 'galera', 'register'])
    assert result.exit_code == 0

    result = runner.invoke(
        main, ['--config', config_file, 'galera', 'server', 'status'])
    assert result.exit_code == 0
Example #2
0
def test__galera_user_set_password_if_user_is_exist(
        percona_xtradb_cluster_three_node, proxysql_instance, tmpdir):
    wait_for_cluster_nodes_to_become_healthy(percona_xtradb_cluster_three_node)
    hostgroup_writer = 10
    hostgroup_reader = 11

    rw_map = {0: hostgroup_writer, 1: hostgroup_reader, 2: hostgroup_reader}
    for i in xrange(3):
        backend = ProxySQLMySQLBackend(
            hostname=percona_xtradb_cluster_three_node[i]['ip'],
            port=percona_xtradb_cluster_three_node[0]['mysql_port'],
            hostgroup_id=rw_map[i])
        proxysql_instance.register_backend(backend)

    blacklist = '{}:3306'.format(percona_xtradb_cluster_three_node[2]['ip'])
    nodes = [
        percona_xtradb_cluster_three_node[0]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[1]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[2]['ip'] + ':3306'
    ]
    config = proxysql_tools_config_2(proxysql_instance, nodes, 'root', 'r00t',
                                     hostgroup_writer, hostgroup_reader,
                                     blacklist, 'monitor', 'monitor')
    config_file = str(tmpdir.join('proxysql-tool.cfg'))
    with open(config_file, 'w') as fh:
        config.write(fh)
        proxysql_tools.LOG.debug('proxysql-tools config: \n%s', config)
    runner = CliRunner()
    result = runner.invoke(main,
                           ['--config', config_file, 'galera', 'register'])
    assert result.exit_code == 0

    result = runner.invoke(
        main, ['--config', config_file, 'galera', 'user', 'create', 'foo'])
    assert result.exit_code == 0

    connection = pymysql.connect(host=proxysql_instance.host,
                                 port=proxysql_instance.port,
                                 user=proxysql_instance.user,
                                 passwd=proxysql_instance.password,
                                 connect_timeout=20,
                                 cursorclass=DictCursor)
    try:
        with connection.cursor() as cursor:
            cursor.execute(
                "SELECT * FROM mysql_users WHERE username = '******'".
                format(username='******'))
            assert cursor.fetchall() != ()

    finally:
        connection.close()

    result = runner.invoke(
        main,
        ['--config', config_file, 'galera', 'user', 'set_password', 'foo'],
        input='test\ntest\n')

    assert result.exit_code == 0

    connection = pymysql.connect(host=proxysql_instance.host,
                                 port=proxysql_instance.port,
                                 user=proxysql_instance.user,
                                 passwd=proxysql_instance.password,
                                 connect_timeout=20,
                                 cursorclass=DictCursor)
    try:
        with connection.cursor() as cursor:
            cursor.execute(
                "SELECT * FROM mysql_users WHERE username = '******'".
                format(username='******'))

            row = cursor.fetchall()[0]
            user = ProxySQLMySQLUser(
                username=row['username'],
                password=row['password'],
                active=row['active'],
                use_ssl=row['use_ssl'],
                default_hostgroup=row['default_hostgroup'],
                default_schema=row['default_schema'],
                schema_locked=row['schema_locked'],
                transaction_persistent=row['transaction_persistent'],
                fast_forward=row['fast_forward'],
                backend=row['backend'],
                frontend=row['frontend'],
                max_connections=row['max_connections'])
            assert user.password
            assert user.active
            assert not user.use_ssl
            assert user.default_hostgroup == 0
            assert user.default_schema == 'information_schema'
            assert not user.schema_locked
            assert not user.transaction_persistent
            assert not user.fast_forward
            assert user.backend
            assert user.frontend
            assert user.max_connections == 10000
    finally:
        connection.close()
Example #3
0
def test__galera_server_set_sync(percona_xtradb_cluster_three_node,
                                 proxysql_instance, tmpdir):
    wait_for_cluster_nodes_to_become_healthy(percona_xtradb_cluster_three_node)
    hostgroup_writer = 10
    hostgroup_reader = 11

    rw_map = {0: hostgroup_writer, 1: hostgroup_reader, 2: hostgroup_reader}
    for i in xrange(3):
        backend = ProxySQLMySQLBackend(
            hostname=percona_xtradb_cluster_three_node[i]['ip'],
            port=percona_xtradb_cluster_three_node[0]['mysql_port'],
            hostgroup_id=rw_map[i])
        proxysql_instance.register_backend(backend)

    blacklist = '{}:3306'.format(percona_xtradb_cluster_three_node[2]['ip'])
    nodes = [
        percona_xtradb_cluster_three_node[0]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[1]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[2]['ip'] + ':3306'
    ]
    config = proxysql_tools_config_2(proxysql_instance, nodes, 'root', 'r00t',
                                     hostgroup_writer, hostgroup_reader,
                                     blacklist, 'monitor', 'monitor')
    config_file = str(tmpdir.join('proxysql-tool.cfg'))
    with open(config_file, 'w') as fh:
        config.write(fh)
        proxysql_tools.LOG.debug('proxysql-tools config: \n%s', config)
    runner = CliRunner()
    result = runner.invoke(main,
                           ['--config', config_file, 'galera', 'register'])
    assert result.exit_code == 0

    result = runner.invoke(main, [
        '--config', config_file, 'galera', 'server', 'set_sync',
        percona_xtradb_cluster_three_node[1]['ip'], '3306'
    ])
    assert result.exit_code == 0

    result = runner.invoke(main,
                           ['--config', config_file, 'galera', 'register'])
    assert result.exit_code == 0

    connection = pymysql.connect(host=proxysql_instance.host,
                                 port=proxysql_instance.port,
                                 user=proxysql_instance.user,
                                 passwd=proxysql_instance.password,
                                 connect_timeout=20,
                                 cursorclass=DictCursor)
    try:
        with connection.cursor() as cursor:
            cursor.execute(
                'SELECT `hostgroup_id`, `hostname`, '
                '`port`, `status`, `weight`, `compression`, '
                '`max_connections`, `max_replication_lag`, '
                '`use_ssl`, `max_latency_ms`, `comment`'
                ' FROM `mysql_servers`'
                ' WHERE hostgroup_id = %s'
                ' AND hostname = %s',
                (hostgroup_reader, percona_xtradb_cluster_three_node[1]['ip']))
            row = cursor.fetchall()[0]
            assert row['status'] == BackendStatus.online
    finally:
        connection.close()
Example #4
0
def test__galera_register_shutdowned_writer_is_deregistered(
        percona_xtradb_cluster_three_node, proxysql_instance, tmpdir):
    wait_for_cluster_nodes_to_become_healthy(percona_xtradb_cluster_three_node)
    hostgroup_writer = 10
    hostgroup_reader = 11

    backend_unreg = ProxySQLMySQLBackend(
        hostname=percona_xtradb_cluster_three_node[0]['ip'],
        port=percona_xtradb_cluster_three_node[0]['mysql_port'],
        hostgroup_id=hostgroup_writer)
    proxysql_instance.register_backend(backend_unreg)

    backend = ProxySQLMySQLBackend(
        hostname=percona_xtradb_cluster_three_node[1]['ip'],
        port=percona_xtradb_cluster_three_node[1]['mysql_port'],
        hostgroup_id=hostgroup_reader)
    proxysql_instance.register_backend(backend)

    backend = ProxySQLMySQLBackend(
        hostname=percona_xtradb_cluster_three_node[2]['ip'],
        port=percona_xtradb_cluster_three_node[2]['mysql_port'],
        hostgroup_id=hostgroup_reader)
    proxysql_instance.register_backend(backend)

    blacklist = '{}:3306'.format(percona_xtradb_cluster_three_node[2]['ip'])
    nodes = [
        percona_xtradb_cluster_three_node[0]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[1]['ip'] + ':3306',
        percona_xtradb_cluster_three_node[2]['ip'] + ':3306'
    ]

    shutdown_container(percona_xtradb_cluster_three_node[0]['id'])
    config = proxysql_tools_config_2(proxysql_instance, nodes, 'root', 'r00t',
                                     hostgroup_writer, hostgroup_reader,
                                     blacklist, 'monitor', 'monitor')
    config_file = str(tmpdir.join('proxysql-tool.cfg'))
    with open(config_file, 'w') as fh:
        config.write(fh)
        proxysql_tools.LOG.debug('proxysql-tools config: \n%s', config)
    runner = CliRunner()
    result = runner.invoke(main,
                           ['--config', config_file, 'galera', 'register'])
    assert result.exit_code == 0

    connection = pymysql.connect(host=proxysql_instance.host,
                                 port=proxysql_instance.port,
                                 user=proxysql_instance.user,
                                 passwd=proxysql_instance.password,
                                 connect_timeout=20,
                                 cursorclass=DictCursor)
    try:
        with connection.cursor() as cursor:
            cursor.execute(
                'SELECT `hostgroup_id`, `hostname`, '
                '`port`'
                ' FROM `mysql_servers`'
                ' WHERE hostgroup_id = %s '
                ' AND `hostname` = %s '
                ' AND `port` = %s',
                (backend_unreg.hostgroup_id, backend_unreg.hostname,
                 backend_unreg.port))
            assert cursor.fetchall() == ()

            cursor.execute(
                'SELECT `hostgroup_id`, `hostname`, '
                '`port`'
                ' FROM `mysql_servers`'
                ' WHERE hostgroup_id = %s ', (backend_unreg.hostgroup_id, ))
            assert cursor.fetchall() != ()

    finally:
        connection.close()