コード例 #1
0
ファイル: test_cli.py プロジェクト: ovaistariq/proxysql-tools
def test__ping_command_can_be_executed(proxysql_manager, tmpdir):
    config = proxysql_tools_config(proxysql_manager, '127.0.0.1', '3306',
                                   'user', 'pass', 10, 11, 'monitor',
                                   'monitor')
    config_file = str(tmpdir.join('proxysql-tool.cfg'))
    with open(config_file, 'w') as fh:
        config.write(fh)

    runner = CliRunner()
    result = runner.invoke(main, ['--config', config_file, 'ping'])
    assert result.exit_code == 0
コード例 #2
0
ファイル: test_cli.py プロジェクト: shawn0915/proxysql-tools
def test__galera_user_create_using_options(proxysql_instance, tmpdir):
    config = proxysql_tools_config(proxysql_instance, '127.0.0.1', '3306',
                                   'user', 'pass', 10, 11, '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', '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='******'))
            row = cursor.fetchall()[0]
            assert row
            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.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()
コード例 #3
0
ファイル: test_cli.py プロジェクト: shawn0915/proxysql-tools
def test__galera_user_list_can_be_executed(proxysql_instance, tmpdir):
    config = proxysql_tools_config(proxysql_instance, '127.0.0.1', '3306',
                                   'user', 'pass', 10, 11, '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', 'user', 'create', 'foo'])
    assert result.exit_code == 0
    result = runner.invoke(main,
                           ['--config', config_file, 'galera', 'user', 'list'])
    assert result.exit_code == 0
コード例 #4
0
ファイル: test_cli.py プロジェクト: shawn0915/proxysql-tools
def test__galera_user_delete(proxysql_instance, tmpdir):
    config = proxysql_tools_config(proxysql_instance, '127.0.0.1', '3306',
                                   'user', 'pass', 10, 11, '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', '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', 'delete', '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()
コード例 #5
0
ファイル: test_cli.py プロジェクト: shawn0915/proxysql-tools
def test__galera_user_set_password_if_user_is_not_exist(
        proxysql_instance, tmpdir):
    config = proxysql_tools_config(proxysql_instance, '127.0.0.1', '3306',
                                   'user', 'pass', 10, 11, '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', 'user', 'set_password', 'foo'],
        input='test\ntest\n')

    assert result.exit_code == 1
コード例 #6
0
ファイル: test_cli.py プロジェクト: shawn0915/proxysql-tools
def test__galera_user_modify_user_if_user_is_not_exist(proxysql_instance,
                                                       tmpdir):
    config = proxysql_tools_config(proxysql_instance, '127.0.0.1', '3306',
                                   'user', 'pass', 10, 11, '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', 'user', 'modify', 'foo',
        '--no-active', '--use_ssl', '--default_hostgroup', '1',
        '--default_schema', 'foo', '--schema_locked',
        '--transaction_persistent', '--fast_forward', '--no-backend',
        '--no-frontend', '--max_connections', '100'
    ])
    assert result.exit_code == 1
コード例 #7
0
ファイル: test_cli.py プロジェクト: ovaistariq/proxysql-tools
def test__galera_register_command_can_register_cluster_with_proxysql(
        percona_xtradb_cluster_node, proxysql_manager, tmpdir):
    hostgroup_writer = 10
    hostgroup_reader = 11

    # To start off there should be no nodes in the hostgroups
    assert len(proxysql_manager.fetch_backends(hostgroup_writer)) == 0
    assert len(proxysql_manager.fetch_backends(hostgroup_reader)) == 0

    galera_man = GaleraManager(percona_xtradb_cluster_node.host,
                               percona_xtradb_cluster_node.port,
                               percona_xtradb_cluster_node.username,
                               percona_xtradb_cluster_node.password)
    galera_man.discover_cluster_nodes()

    # Validate that there is one healthy node in the cluster
    assert len(galera_man.nodes) == 1

    # Setup the config object
    config = proxysql_tools_config(
        proxysql_manager, percona_xtradb_cluster_node.host,
        percona_xtradb_cluster_node.port, percona_xtradb_cluster_node.username,
        percona_xtradb_cluster_node.password, hostgroup_writer,
        hostgroup_reader, 'monitor', 'monitor')

    config_file = str(tmpdir.join('proxysql-tool.cfg'))
    with open(config_file, 'w') as fh:
        config.write(fh)

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

    writer_backends = proxysql_manager.fetch_backends(hostgroup_writer)
    reader_backends = proxysql_manager.fetch_backends(hostgroup_reader)

    assert len(writer_backends) == len(reader_backends) == 1
    assert writer_backends[0].hostname == reader_backends[0].hostname
    assert writer_backends[0].port == reader_backends[0].port
    assert writer_backends[0].status == reader_backends[0].status
コード例 #8
0
def config():
    proxysql_instance = ProxySQL()
    data = proxysql_tools_config(proxysql_instance, '127.0.0.1', '3306',
                                 'user', 'pass', 10, 11, 'monitor', 'monitor')
    return data