Example #1
0
def test_set_weight(cartridge_cmd, project_with_vshard_replicasets):
    project = project_with_vshard_replicasets.project
    instances = project_with_vshard_replicasets.instances
    replicasets = project_with_vshard_replicasets.replicasets

    hot_storage_rpl = replicasets['hot-storage']
    hot_master = instances['hot-master']
    admin_api_url = hot_master.get_admin_api_url()

    NEW_WEIGHT = 123.45

    # set replicaset weight
    cmd = [
        cartridge_cmd, 'replicasets', 'set-weight',
        '--replicaset', hot_storage_rpl.name,
        str(NEW_WEIGHT),
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0
    assert get_log_lines(output) == [
        '• Replica set %s weight is set to %s' % (hot_storage_rpl.name, NEW_WEIGHT),
    ]

    replicasets = get_replicasets(admin_api_url)
    hot_replicaset = get_replicaset_by_alias(replicasets, hot_storage_rpl.name)
    assert hot_replicaset is not None
    assert hot_replicaset['weight'] == NEW_WEIGHT
Example #2
0
def test_add_roles_vshard_group(cartridge_cmd,
                                project_with_replicaset_no_roles):
    project = project_with_replicaset_no_roles.project
    instances = project_with_replicaset_no_roles.instances
    replicasets = project_with_replicaset_no_roles.replicasets

    VSHARD_STORAGE_ROLE = 'vshard-storage'
    HOT_GROUP_NAME = 'hot'

    rpl = replicasets['some-rpl']
    instance = instances['some-instance']
    admin_api_url = instance.get_admin_api_url()

    # add vshard-storage role
    cmd = [
        cartridge_cmd,
        'replicasets',
        'add-roles',
        '--replicaset',
        rpl.name,
        '--vshard-group',
        HOT_GROUP_NAME,
        VSHARD_STORAGE_ROLE,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0

    exp_res_roles = [VSHARD_STORAGE_ROLE]
    exp_res_roles_list = ['%s (%s)' % (VSHARD_STORAGE_ROLE, HOT_GROUP_NAME)]

    assert_add_roles_log(
        output,
        rpl.name,
        roles_to_add=[VSHARD_STORAGE_ROLE],
        res_roles_list=exp_res_roles_list,
    )

    replicasets = get_replicasets(admin_api_url)
    router_replicaset = get_replicaset_by_alias(replicasets, rpl.name)
    assert router_replicaset is not None
    assert router_replicaset['vshard_group'] == HOT_GROUP_NAME
    assert set(router_replicaset['roles']) == set(exp_res_roles)
Example #3
0
def assert_joined_replicaset(admin_api_url,
                             replicaset_alias,
                             instances,
                             exp_replicasets_num=1):
    replicasets = get_replicasets(admin_api_url)
    assert len(replicasets) == exp_replicasets_num

    replicaset = get_replicaset_by_alias(replicasets, replicaset_alias)
    assert replicaset is not None

    assert replicaset == {
        'alias': replicaset_alias,
        'roles': [],
        'vshard_group': None,
        'all_rw': False,
        'weight': None,
        'servers': [{
            'uri': i.advertise_uri,
            'alias': i.name
        } for i in instances]
    }
Example #4
0
def test_set_failover_priority(cartridge_cmd, project_with_vshard_replicasets):
    project = project_with_vshard_replicasets.project
    instances = project_with_vshard_replicasets.instances
    replicasets = project_with_vshard_replicasets.replicasets

    hot_storage_rpl = replicasets['hot-storage']
    hot_master = instances['hot-master']
    hot_replica = instances['hot-replica']

    admin_api_url = hot_master.get_admin_api_url()

    # set replicaset failover priority
    cmd = [
        cartridge_cmd,
        'replicasets',
        'set-failover-priority',
        '--replicaset',
        hot_storage_rpl.name,
        hot_replica.name,
        hot_master.name,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0

    exp_failover_priority = [hot_replica.name, hot_master.name]

    log_lines = get_log_lines(output)
    assert log_lines[:1] == [
        "• Replica set hot-storage failover priority was set to:",
    ]

    failover_priority_list = get_list_from_log_lines(log_lines[1:])
    assert failover_priority_list == exp_failover_priority

    replicasets = get_replicasets(admin_api_url)
    hot_replicaset = get_replicaset_by_alias(replicasets, hot_storage_rpl.name)
    assert hot_replicaset is not None

    servers_names = [s['alias'] for s in hot_replicaset['servers']]
    assert servers_names == exp_failover_priority

    # specify only one instance
    cmd = [
        cartridge_cmd,
        'replicasets',
        'set-failover-priority',
        '--replicaset',
        hot_storage_rpl.name,
        hot_master.name,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0

    exp_failover_priority = [hot_master.name, hot_replica.name]

    log_lines = get_log_lines(output)
    assert log_lines[:1] == [
        "• Replica set hot-storage failover priority was set to:",
    ]

    failover_priority_list = get_list_from_log_lines(log_lines[1:])
    assert failover_priority_list == exp_failover_priority

    replicasets = get_replicasets(admin_api_url)
    hot_replicaset = get_replicaset_by_alias(replicasets, hot_storage_rpl.name)
    assert hot_replicaset is not None

    servers_names = [s['alias'] for s in hot_replicaset['servers']]
    assert servers_names == exp_failover_priority
Example #5
0
def test_add_remove_roles(cartridge_cmd, project_with_replicaset_no_roles):
    project = project_with_replicaset_no_roles.project
    instances = project_with_replicaset_no_roles.instances
    replicasets = project_with_replicaset_no_roles.replicasets

    VSHARD_ROUTER_ROLE = 'vshard-router'
    APP_CUSTOM_ROLE = 'app.roles.custom'
    FAILOVER_COORDINATOR_ROLE = 'failover-coordinator'

    rpl = replicasets['some-rpl']
    instance = instances['some-instance']
    admin_api_url = instance.get_admin_api_url()

    # add vshard-router and app.roles.custom roles to replicaset
    cmd = [
        cartridge_cmd,
        'replicasets',
        'add-roles',
        '--replicaset',
        rpl.name,
        VSHARD_ROUTER_ROLE,
        APP_CUSTOM_ROLE,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0

    exp_res_roles_list = [VSHARD_ROUTER_ROLE, APP_CUSTOM_ROLE]
    assert_add_roles_log(
        output,
        rpl.name,
        roles_to_add=[VSHARD_ROUTER_ROLE, APP_CUSTOM_ROLE],
        res_roles_list=exp_res_roles_list,
    )

    replicasets = get_replicasets(admin_api_url)
    router_replicaset = get_replicaset_by_alias(replicasets, rpl.name)
    assert router_replicaset is not None
    assert set(router_replicaset['roles']) == set(exp_res_roles_list)

    # add failover-coordinator and app.roles.custom (again) roles to replicaset
    cmd = [
        cartridge_cmd,
        'replicasets',
        'add-roles',
        '--replicaset',
        rpl.name,
        FAILOVER_COORDINATOR_ROLE,
        APP_CUSTOM_ROLE,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0

    exp_res_roles_list = [
        VSHARD_ROUTER_ROLE,
        FAILOVER_COORDINATOR_ROLE,
        APP_CUSTOM_ROLE,
    ]
    assert_add_roles_log(
        output,
        rpl.name,
        roles_to_add=[FAILOVER_COORDINATOR_ROLE, APP_CUSTOM_ROLE],
        res_roles_list=exp_res_roles_list,
    )

    replicasets = get_replicasets(admin_api_url)
    router_replicaset = get_replicaset_by_alias(replicasets, rpl.name)
    assert router_replicaset is not None
    assert set(router_replicaset['roles']) == set(exp_res_roles_list)

    # remove metrics and failover-coordinator roles from replicaset
    cmd = [
        cartridge_cmd,
        'replicasets',
        'remove-roles',
        '--replicaset',
        rpl.name,
        FAILOVER_COORDINATOR_ROLE,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0

    exp_res_roles_list = [
        VSHARD_ROUTER_ROLE,
        APP_CUSTOM_ROLE,
    ]

    assert_remove_roles_log(
        output,
        rpl.name,
        roles_to_remove=[FAILOVER_COORDINATOR_ROLE],
        res_roles_list=exp_res_roles_list,
    )

    replicasets = get_replicasets(admin_api_url)
    router_replicaset = get_replicaset_by_alias(replicasets, rpl.name)
    assert router_replicaset is not None
    assert set(router_replicaset['roles']) == set(exp_res_roles_list)