Esempio n. 1
0
 def check_started():
     for container_info in percona_xtradb_cluster_info:
         node = GaleraNode(host=container_info['ip'],
                           user='******',
                           password=container_info['root_password'])
         node.execute('SELECT 1')
     return True
Esempio n. 2
0
 def __init__(self, cluster_hosts, user='******', password=None):
     self._nodes = []
     for host in self._split_cluster_host(cluster_hosts):
         self._nodes.append(
             GaleraNode(host=host[0],
                        port=host[1],
                        user=user,
                        password=password))
Esempio n. 3
0
def percona_xtradb_cluster_node(percona_xtradb_cluster_one_node):
    node = GaleraNode(host=percona_xtradb_cluster_one_node[0]['ip'],
                      user='******',
                      password=PXC_ROOT_PASSWORD)

    def check_started():
        node.execute('SELECT 1')
        return True

    # Allow the cluster node to startup completely.
    eventually(check_started, retries=15, sleep_time=4)

    return node
Esempio n. 4
0
def register_synced_backends(
        galera_cluster,
        proxysql,  # pylint: disable=too-many-arguments
        hostgroup_id,
        comment=None,
        limit=None,
        ignore_backend=None):
    """
    Find SYNCED node and register it as a backend.

    :param galera_cluster: GaleraCluster instance.
    :type galera_cluster: GaleraCluster
    :param proxysql: ProxySQL instance
    :type proxysql: ProxySQL
    :param hostgroup_id: hostgroup_id
    :type hostgroup_id: int
    :param comment: Optional comment to add to mysql_server
    :type comment: str
    :param limit: Register not more than limit number of backends
    :type limit: int
    :param ignore_backend: Do not register this backend
    :type ignore_backend: ProxySQLMySQLBackend
    """
    try:
        galera_nodes = galera_cluster.find_synced_nodes()

        if ignore_backend:
            node = GaleraNode(ignore_backend.hostname,
                              port=ignore_backend.port)
            LOG.debug('Ignoring backend %s', ignore_backend)
            if node in galera_nodes:
                LOG.debug('Remove %s from candidates', ignore_backend)
                galera_nodes.remove(node)

        if limit:
            candidate_nodes = galera_nodes[:limit]
        else:
            candidate_nodes = galera_nodes

        for galera_node in candidate_nodes:
            backend = ProxySQLMySQLBackend(galera_node.host,
                                           hostgroup_id=hostgroup_id,
                                           port=galera_node.port,
                                           comment=comment)
            proxysql.register_backend(backend)
            LOG.info('Added backend %s to hostgroup %d', backend, hostgroup_id)

    except GaleraClusterSyncedNodeNotFound as err:
        LOG.error(err)
Esempio n. 5
0
def galera_node1():
    return GaleraNode('192.168.90.2', password='******')
Esempio n. 6
0
def test_nodes():
    gc = GaleraCluster('foo:1')
    assert gc.nodes == [GaleraNode('foo', port=1)]
Esempio n. 7
0
def galera_node():
    return GaleraNode('foo', port=1234, user='******', password='******')
Esempio n. 8
0
def test__galera_register_writer_node_is_reader_when_readers_list_is_empty(
        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)

    desync_node = GaleraNode(
        host=percona_xtradb_cluster_three_node[1]['ip'],
        port=percona_xtradb_cluster_three_node[1]['mysql_port'],
        user='******',
        password='******')
    desync_node.execute('set global wsrep_desync=ON;')

    desync_node = GaleraNode(
        host=percona_xtradb_cluster_three_node[2]['ip'],
        port=percona_xtradb_cluster_three_node[2]['mysql_port'],
        user='******',
        password='******')
    desync_node.execute('set global wsrep_desync=ON;')

    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

    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.offline_soft
            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[2]['ip']))
            row = cursor.fetchall()[0]
            assert row['status'] == BackendStatus.offline_soft

            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[0]['ip']))
            assert cursor.fetchall() != ()

    finally:
        connection.close()