Example #1
0
def test_call_many_args(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    base_cmd = [
        cartridge_cmd, 'admin',
        '--name', project.name,
        '--run-dir', run_dir,
        'echo_user',
    ]

    # all args
    cmd = base_cmd + [
        '--username', 'Elizabeth',
        '--age', '23',
        '--loves-cakes',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Hi, Elizabeth!',
        '• You are 23 years old',
        '• I know that you like cakes!',
    ]

    # age missed
    # check that default number flag value (0) isn't passed
    cmd = base_cmd + [
        '--username', 'Elizabeth',
        '--loves-cakes',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        "• Hi, Elizabeth!",
        "• I don't know your age",
        "• I know that you like cakes!",
    ]

    # bool flag is false
    cmd = base_cmd + [
        '--username', 'Elizabeth',
        '--loves-cakes=false',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        "• Hi, Elizabeth!",
        "• I don't know your age",
        "• How can you not love cakes?",
    ]
Example #2
0
def test_print(cartridge_cmd, custom_admin_running_instances, connection_type,
               tmpdir):
    project = custom_admin_running_instances['project']

    ITERATIONS_NUM = 3

    cmd = [
        cartridge_cmd,
        'admin',
        'func_print',
        '--num',
        str(ITERATIONS_NUM),
    ]
    cmd.extend(get_admin_connection_params(connection_type, project))

    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    iterations_output = []
    for i in range(1, ITERATIONS_NUM + 1):
        iterations_output.extend([
            '• Iteration %s (printed)' % i,
            '• Iteration %s (pushed)' % i,
        ])

    assert get_log_lines(output) == iterations_output + [
        '• I am some great result',
    ]
Example #3
0
def assert_setup_logs(output,
                      rpl_conf_path,
                      created_rpls=[],
                      updated_rpls=[],
                      ok_rpls=[],
                      vshard_bootstrapped=False):
    log_lines = get_log_lines(output)
    assert log_lines[:1] == [
        "• Set up replicasets described in %s" % rpl_conf_path
    ]

    set_replicasets_logs = log_lines
    if vshard_bootstrapped:
        bootstrap_vshard_logs = log_lines[-1:]
        assert bootstrap_vshard_logs == [
            "• Vshard is bootstrapped successfully",
        ]

        set_replicasets_logs = log_lines[:-1]

    replicasets_list = get_list_from_log_lines(set_replicasets_logs[1:-1])

    exp_replicasets_list = []
    exp_replicasets_list.extend(
        ['%s... CREATED' % rpl_name for rpl_name in created_rpls])
    exp_replicasets_list.extend(
        ['%s... UPDATED' % rpl_name for rpl_name in updated_rpls])
    exp_replicasets_list.extend(
        ['%s... OK' % rpl_name for rpl_name in ok_rpls])
    assert set(replicasets_list) == set(exp_replicasets_list)

    assert set_replicasets_logs[-1:] == [
        "• Replicasets are set up successfully",
    ]
Example #4
0
def test_bootstrap(cartridge_cmd, project_with_vshard_replicasets):
    project = project_with_vshard_replicasets.project
    instances = project_with_vshard_replicasets.instances

    # bootstrap vshard
    cmd = [
        cartridge_cmd, 'replicasets', 'bootstrap-vshard',
    ]

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

    assert get_log_lines(output) == [
        "• Vshard is bootstrapped successfully"
    ]

    router = instances['router']
    admin_api_url = router.get_admin_api_url()
    assert is_vshard_bootstrapped(admin_api_url)

    # bootstrap again
    cmd = [
        cartridge_cmd, 'replicasets', 'bootstrap-vshard',
    ]

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

    assert "already bootstrapped" in output
Example #5
0
def test_help_many_args(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    cmd = [
        cartridge_cmd,
        'admin',
        '--name',
        project.name,
        '--run-dir',
        run_dir,
        'echo_user',
        '--help',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Admin function "echo_user" usage:',
        'echo_user usage',
        'Args:',
        '--age number           age usage',
        '--loves-cakes boolean  loves_cakes usage',
        '--username string      username usage',
    ]
Example #6
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 #7
0
def test_save_file_specified(project_with_vshard_replicasets, cartridge_cmd):
    project = project_with_vshard_replicasets.project
    instances = project_with_vshard_replicasets.instances

    router = instances['router']
    admin_api_url = router.get_admin_api_url()

    rpl_cfg_path = project.get_replicasets_cfg_path('my-replicasets.yml')

    cmd = [
        cartridge_cmd,
        'replicasets',
        'save',
        '--file',
        rpl_cfg_path,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0
    assert get_log_lines(output) == [
        "• Save current replicasets to %s" % rpl_cfg_path,
    ]

    assert os.path.exists(rpl_cfg_path)

    with open(rpl_cfg_path) as f:
        rpl_cfg = yaml.load(f, Loader=yaml.FullLoader)

    assert_replicasets(rpl_cfg, admin_api_url)
Example #8
0
def test_list_roles(cartridge_cmd, project_with_instances):
    project = project_with_instances.project
    instances = project_with_instances.instances

    router = instances['router']
    admin_api_url = router.get_admin_api_url()

    # get list of roles
    cmd = [
        cartridge_cmd,
        'replicasets',
        'list-roles',
    ]

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

    log_lines = get_log_lines(output)
    assert log_lines[:1] == [
        "• Available roles:",
    ]

    known_roles = get_known_roles(admin_api_url)
    exp_roles_list = []
    for known_role in known_roles:
        if not known_role['dependencies']:
            exp_roles_list.append(known_role['name'])
        else:
            exp_roles_list.append(
                "%s (+ %s)" %
                (known_role['name'], ', '.join(known_role['dependencies'])))

    roles_list = get_list_from_log_lines(log_lines[1:])
    assert set(roles_list) == set(exp_roles_list)
Example #9
0
def test_print(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    ITERATIONS_NUM = 3

    cmd = [
        cartridge_cmd, 'admin',
        '--name', project.name,
        '--run-dir', run_dir,
        'func_print',
        '--num', str(ITERATIONS_NUM),
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    iterations_output = []
    for i in range(1, ITERATIONS_NUM+1):
        iterations_output.extend([
            '• Iteration %s (printed)' % i,
            '• Iteration %s (pushed)' % i,
        ])

    assert get_log_lines(output) == iterations_output + [
        '• I am some great result',
    ]
def test_list_groups(cartridge_cmd, project_with_instances):
    project = project_with_instances.project
    instances = project_with_instances.instances

    router = instances['router']
    admin_api_url = router.get_admin_api_url()
    vshard_group_names = get_vshard_group_names(admin_api_url)

    # bootstrap vshard
    cmd = [
        cartridge_cmd,
        'replicasets',
        'list-vshard-groups',
    ]

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

    log_lines = get_log_lines(output)

    assert log_lines[:1] == [
        '• Available vshard groups:',
    ]

    groups_list = get_list_from_log_lines(log_lines[1:])
    assert set(groups_list) == set(vshard_group_names)
Example #11
0
def main(args):
    lines = get_log_lines(args.files)

    # Split into sorted lists for each node.
    nodes = get_nodes(lines)
    node_to_lines = {}
    node_to_runs = {}
    for n in nodes:
        node_to_lines[n] = sorted(filter(lambda l: l.addr == n, lines))
        # Split by Manager lines.
        runs = []
        current_idx = 0
        start_idx = 0
        while current_idx < len(node_to_lines[n]):
            if node_to_lines[n][current_idx].protocol == "Manager":
                runs.append(node_to_lines[n][start_idx:current_idx])
                start_idx = current_idx
            current_idx += 1
        runs.append(node_to_lines[n][start_idx:current_idx])
        node_to_runs[n] = filter(lambda r: len(r) > 100, runs)
    
    # Use 20 as the anchor
    runs = []
    for i, r in enumerate(node_to_runs[20]):
        run = {}
        run[20] = i
        start = r[0].timestamp
        for n in nodes:
            if n == 20:
                continue
            for j, r in enumerate(node_to_runs[n]):
                if abs((start - r[0].timestamp).total_seconds()) < 90:
                    run[n] = j
        runs.append(run)
    rows = []
    for i, r in enumerate(runs):
        row = [i]
        for n in nodes:
            idx = r.get(n)
            timestamp = node_to_runs[n][idx][0].timestamp if idx else None
            row.append("%s, %s" % (idx, timestamp))
        rows.append(row)

    header = ["run"]
    for n in nodes:
        header.append(n)
    print tabulate.tabulate(rows, headers=header)

    # Merge runs.
    if args.o:
        for i in xrange(len(runs)):
            run = []
            for n, idx in runs[i].iteritems():
                run.extend(node_to_runs[n][idx])
            f = open('run-%s.log' % i, 'w')
            for line in sorted(run):
                f.write(line.original)
                f.write("\n")
            f.close()
    return
Example #12
0
def assert_join_instances_logs(output, replicaset_alias, instances):
    format_strings = (
        ', '.join([i.name for i in instances]),
        replicaset_alias,
    )
    assert get_log_lines(output) == [
        '• Join instance(s) %s to replica set %s' % format_strings,
        '• Instance(s) %s have been successfully joined to replica set %s' %
        format_strings,
    ]
Example #13
0
def main(args):
    if args.mode == Mode.STATS:
        return stats_mode(args)
    if args.mode == Mode.CHECK:
        return check_mode(args)
    if args.mode == Mode.SCATTER:
        return scatter_mode(args)
    if args.mode == Mode.FULL:
        for f in args.files:
            lines = utils.get_log_lines([f])
            utils.get_stats(lines)
        return
Example #14
0
def test_help_long_func_name(cartridge_cmd, custom_admin_running_instances,
                             tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    exp_output_lines = [
        '• Admin function "func.long.name" usage:',
        'func_long_name usage',
    ]

    cmd = [
        cartridge_cmd,
        'admin',
        '--name',
        project.name,
        '--run-dir',
        run_dir,
        'func.long.name',
        '--help',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0
    assert get_log_lines(output) == exp_output_lines

    cmd = [
        cartridge_cmd,
        'admin',
        '--name',
        project.name,
        '--run-dir',
        run_dir,
        'func',
        'long',
        'name',
        '--help',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0
    assert get_log_lines(output) == exp_output_lines
Example #15
0
def assert_add_roles_log(output, replicaset_alias, roles_to_add,
                         res_roles_list):
    roles_to_add_str = ', '.join(roles_to_add)

    log_lines = get_log_lines(output)

    assert log_lines[:2] == [
        '• Add role(s) %s to replica set %s' %
        (roles_to_add_str, replicaset_alias),
        '• Replica set %s now has these roles enabled:' % replicaset_alias,
    ]

    roles_list = get_list_from_log_lines(log_lines[2:])
    assert set(roles_list) == set(res_roles_list)
Example #16
0
def test_func_rets_str(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    cmd = [
        cartridge_cmd, 'admin',
        '--name', project.name,
        '--run-dir', run_dir,
        'func_rets_str',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• func_rets_str was called',
    ]
Example #17
0
def test_func_long_arg(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    cmd = [
        cartridge_cmd, 'admin',
        '--name', project.name,
        '--run-dir', run_dir,
        'func_long_arg', '--long-arg', 'some-value',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• func_long_arg was called with "some-value" arg',
    ]
Example #18
0
def test_func_rets_err(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    cmd = [
        cartridge_cmd, 'admin',
        '--name', project.name,
        '--run-dir', run_dir,
        'func_rets_err',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 1

    assert get_log_lines(output) == [
        '⨯ Failed to call "func_rets_err": Some horrible error',
    ]
Example #19
0
def test_func_rets_err(cartridge_cmd, custom_admin_running_instances,
                       connection_type, tmpdir):
    project = custom_admin_running_instances['project']

    cmd = [
        cartridge_cmd,
        'admin',
        'func_rets_err',
    ]
    cmd.extend(get_admin_connection_params(connection_type, project))

    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 1

    assert get_log_lines(output) == [
        '⨯ Failed to call "func_rets_err": Some horrible error',
    ]
Example #20
0
def test_func_rets_non_str(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    cmd = [
        cartridge_cmd, 'admin',
        '--name', project.name,
        '--run-dir', run_dir,
        'func_rets_non_str',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• 666',
        '• Admin function should return string or string array value',
    ]
Example #21
0
def stats_mode(args):
    first_completed = []
    time_to_completion = []
    num_packets_sent = []
    num_adv_sent = []
    num_req_sent = []
    num_data_sent = []

    for f in args.files:
        lines = utils.get_log_lines([f])
        lines = utils.sync_timings(lines)
        nodes = utils.get_nodes(lines)
        version = utils.get_version(lines)
        t_min = utils.get_t_min(lines)
        total_pages = utils.get_total_pages(lines, version)
        start_times = utils.get_start_times(lines, nodes, t_min)
        completion_times = utils.get_completion_times(lines, nodes, total_pages, version)
        final_times = utils.get_final_times(lines, nodes, total_pages, version)
        time_taken = utils.get_time_taken(nodes, start_times, final_times)
        packets_sent = utils.get_packets_sent(lines, nodes, start_times, final_times)

        num_adv_sent.append(sum(v[0] for v in packets_sent.values()))
        num_req_sent.append(sum(v[1] for v in packets_sent.values()))
        num_data_sent.append(sum(v[2] for v in packets_sent.values()))
        num_packets_sent.append(sum(sum(v) for v in packets_sent.values()))
        time_to_completion.append(max(time_taken.values()).total_seconds())
        first_completed.append(min(v.total_seconds() for v in time_taken.values() if v.total_seconds()))
    avg_time_to_completion = sum(time_to_completion) / len(time_to_completion)
    print "Average Time to Completion:", avg_time_to_completion
    avg_first_completed = sum(first_completed) / len(first_completed)
    print "Average Time for first node:", avg_first_completed
    print "Average Delta:", avg_time_to_completion - avg_first_completed

    avg_packets_sent = float(sum(num_packets_sent)) / len(num_packets_sent)
    avg_adv_sent = sum(num_adv_sent) / len(num_adv_sent)
    avg_req_sent = sum(num_req_sent) / len(num_req_sent)
    avg_data_sent = sum(num_data_sent) / len(num_data_sent)

    print "Average Packets Sent:", avg_packets_sent
    print "Total ADV Sent:", avg_adv_sent
    print "Total REQ Sent:", avg_req_sent
    print "Total DATA Sent:", avg_data_sent

    print "Average ADV Sent %:", 100 * avg_adv_sent / avg_packets_sent
    print "Average REQ Sent %:", 100 * avg_req_sent / avg_packets_sent
    print "Average DATA Sent %:", 100 * avg_data_sent / avg_packets_sent
Example #22
0
def test_func_rets_str(cartridge_cmd, custom_admin_running_instances,
                       connection_type, tmpdir):
    project = custom_admin_running_instances['project']

    cmd = [
        cartridge_cmd,
        'admin',
        'func_rets_str',
    ]
    cmd.extend(get_admin_connection_params(connection_type, project))

    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• func_rets_str was called',
    ]
Example #23
0
def test_func_rets_non_str(cartridge_cmd, custom_admin_running_instances,
                           connection_type, tmpdir):
    project = custom_admin_running_instances['project']

    cmd = [
        cartridge_cmd,
        'admin',
        'func_rets_non_str',
    ]
    cmd.extend(get_admin_connection_params(connection_type, project))

    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• 666',
        '• Admin function should return string or string array value',
    ]
Example #24
0
def main(args):
    lines = get_log_lines(args.files)

    if args.s or args.r or args.n:
        # Filter lines.
        filtered_lines = []
        for l in lines:
            if args.s and l.addr in args.s and "Sending" in l.original:
                    filtered_lines.append(l)
            elif args.r and l.addr in args.r and "Received" in l.original:
                    filtered_lines.append(l)
            elif args.n and l.addr in args.n:
                    filtered_lines.append(l)
        lines = filtered_lines

    if args.c:
        lines = sync_timings(lines)

    for line in lines:
        print line.original.strip()
Example #25
0
def check_mode(args):
    for f in args.files:
        lines = utils.get_log_lines([f])
        lines = utils.sync_timings(lines)
        nodes = utils.get_nodes(lines)
        version = utils.get_version(lines)
        t_min = utils.get_t_min(lines)
        total_pages = utils.get_total_pages(lines, version)
        start_times = utils.get_start_times(lines, nodes, t_min)
        completion_times = utils.get_completion_times(lines, nodes, total_pages, version)
        final_times = utils.get_final_times(lines, nodes, total_pages, version)
        time_taken = utils.get_time_taken(nodes, start_times, final_times)
        packets_sent = utils.get_packets_sent(lines, nodes, start_times, final_times)

        # utils.get_stats(lines)
        all_nodes_completed = time_taken.values() and min(time_taken.values()).total_seconds() == 0
        all_nodes_exists = nodes == set([2,3,4,5,6,7,8,9,10,11,20])
        if not all_nodes_completed:
            print "Not all nodes completed:", f.name
        elif not all_nodes_exists:
            print "Not all nodes exist:", f.name, nodes
Example #26
0
def test_help_no_args(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    cmd = [
        cartridge_cmd,
        'admin',
        '--name',
        project.name,
        '--run-dir',
        run_dir,
        'func_no_args',
        '--help',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Admin function "func_no_args" usage:',
        'func_no_args usage',
    ]
Example #27
0
def test_expel(cartridge_cmd, project_with_vshard_replicasets):
    project = project_with_vshard_replicasets.project
    instances = project_with_vshard_replicasets.instances

    router = instances['router']
    hot_replica = instances['hot-replica']
    admin_api_url = router.get_admin_api_url()

    # expel hot sotrage replica
    cmd = [
        cartridge_cmd,
        'replicasets',
        'expel',
        hot_replica.name,
    ]

    rc, output = run_command_and_get_output(cmd, cwd=project.path)
    assert rc == 0
    assert get_log_lines(output) == [
        '• Instance(s) %s have been successfully expelled' % hot_replica.name,
    ]

    assert is_instance_expelled(admin_api_url, hot_replica.name)
Example #28
0
def test_list(cartridge_cmd, custom_admin_running_instances, connection_type,
              tmpdir):
    project = custom_admin_running_instances['project']

    cmd = [cartridge_cmd, 'admin', '--list']
    cmd.extend(get_admin_connection_params(connection_type, project))

    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Available admin functions:',
        'echo_user          echo_user usage',
        'func.long.name     func_long_name usage',
        'func_conflicting   func_conflicting usage',
        'func_long_arg      func_long_arg usage',
        'func_no_args       func_no_args usage',
        'func_print         func_print usage',
        'func_raises_err    func_raises_err usage',
        'func_rets_err      func_rets_err usage',
        'func_rets_non_str  func_rets_non_str usage',
        'func_rets_str      func_rets_str usage',
    ]
Example #29
0
def test_help_many_args(cartridge_cmd, custom_admin_running_instances,
                        connection_type, tmpdir):
    project = custom_admin_running_instances['project']

    cmd = [
        cartridge_cmd,
        'admin',
        'echo_user',
        '--help',
    ]
    cmd.extend(get_admin_connection_params(connection_type, project))

    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Admin function "echo_user" usage:',
        'echo_user usage',
        'Args:',
        '--age number           age usage',
        '--loves-cakes boolean  loves_cakes usage',
        '--username string      username usage',
    ]
Example #30
0
def test_list(cartridge_cmd, custom_admin_running_instances, tmpdir):
    project = custom_admin_running_instances['project']
    run_dir = project.get_run_dir()

    cmd = [
        cartridge_cmd, 'admin', '--name', project.name, '--run-dir', run_dir,
        '--list'
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Available admin functions:',
        'echo_user          echo_user usage',
        'func.long.name     func_long_name usage',
        'func_conflicting   func_conflicting usage',
        'func_long_arg      func_long_arg usage',
        'func_no_args       func_no_args usage',
        'func_print         func_print usage',
        'func_raises_err    func_raises_err usage',
        'func_rets_err      func_rets_err usage',
        'func_rets_non_str  func_rets_non_str usage',
        'func_rets_str      func_rets_str usage',
    ]
Example #31
0
def scatter_mode(args):
    for f in args.files:
        lines = utils.get_log_lines([f])
        lines = utils.sync_timings(lines)
        nodes = utils.get_nodes(lines)
        version = utils.get_version(lines)
        t_min = utils.get_t_min(lines)
        total_pages = utils.get_total_pages(lines, version)
        start_times = utils.get_start_times(lines, nodes, t_min)
        completion_times = utils.get_completion_times(lines, nodes, total_pages, version)
        final_times = utils.get_final_times(lines, nodes, total_pages, version)
        time_taken = utils.get_time_taken(nodes, start_times, final_times)
        packets_sent = utils.get_packets_sent(lines, nodes, start_times, final_times)


        all_nodes_completed = time_taken.values() and min(time_taken.values()).total_seconds() == 0
        all_nodes_exists = nodes == set([2,3,4,5,6,7,8,9,10,11,20])
        if not all_nodes_completed:
            continue
        # elif not all_nodes_exists:
        #     continue
        elif len(nodes) < 7:
            continue

        if args.l:
            for n in nodes:
                if not time_taken.get(n) or time_taken[n].total_seconds() == 0 or packets_sent[n][2] < 100:
                    continue
                print time_taken[n].total_seconds(), 100 * float(packets_sent[n][0] + packets_sent[n][1]) / sum(packets_sent[n]), 1
        else:
            adv_sent = sum(v[0] for v in packets_sent.values())
            req_sent = sum(v[1] for v in packets_sent.values())
            data_sent = sum(v[2] for v in packets_sent.values())
            total_sent = sum(sum(v) for v in packets_sent.values())        
            completion_time = max(time_taken.values()).total_seconds()
            print completion_time, 100 * float(adv_sent + req_sent) / total_sent, 1
Example #32
0
def test_call_many_args(cartridge_cmd, custom_admin_running_instances,
                        connection_type, tmpdir):
    project = custom_admin_running_instances['project']

    base_cmd = [
        cartridge_cmd,
        'admin',
        'echo_user',
    ]
    base_cmd.extend(get_admin_connection_params(connection_type, project))

    # all args
    cmd = base_cmd + [
        '--username',
        'Elizabeth',
        '--age',
        '24',
        '--loves-cakes',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Hi, Elizabeth!',
        '• You are 24 years old',
        '• I know that you like cakes!',
    ]

    # age is float
    cmd = base_cmd + [
        '--username',
        'Elizabeth',
        '--age',
        '23.5',
        '--loves-cakes',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Hi, Elizabeth!',
        '• You are 23.5 years old',
        '• I know that you like cakes!',
    ]

    # age missed
    # check that default number flag value (0) isn't passed
    cmd = base_cmd + [
        '--username',
        'Elizabeth',
        '--loves-cakes',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        "• Hi, Elizabeth!",
        "• I don't know your age",
        "• I know that you like cakes!",
    ]

    # bool flag is false
    cmd = base_cmd + [
        '--username',
        'Elizabeth',
        '--loves-cakes=false',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        "• Hi, Elizabeth!",
        "• I don't know your age",
        "• How can you not love cakes?",
    ]
Example #33
0
def test_default_admin_func(cartridge_cmd, default_admin_running_instances,
                            connection_type, tmpdir):
    project = default_admin_running_instances['project']
    run_dir = project.get_run_dir()

    # list
    cmd = [cartridge_cmd, 'admin', '--list']
    cmd.extend(get_admin_connection_params(connection_type, project))

    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Available admin functions:',
        'probe  Probe instance',
    ]

    # help
    cmd = [
        cartridge_cmd,
        'admin',
        '--name',
        project.name,
        '--run-dir',
        run_dir,
        '--help',
        'probe',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Admin function "probe" usage:',
        'Probe instance',
        'Args:',
        '--uri string  Instance URI',
    ]

    # call w/ --uri localhost:3301 - OK
    cmd = [
        cartridge_cmd,
        'admin',
        '--name',
        project.name,
        '--run-dir',
        run_dir,
        'probe',
        '--uri',
        'localhost:3301',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 0

    assert get_log_lines(output) == [
        '• Probe "localhost:3301": OK',
    ]

    # call w/ --uri localhost:3311 - fail
    cmd = [
        cartridge_cmd,
        'admin',
        '--name',
        project.name,
        '--run-dir',
        run_dir,
        'probe',
        '--uri',
        'localhost:3311',
    ]
    rc, output = run_command_and_get_output(cmd, cwd=tmpdir)
    assert rc == 1

    assert get_log_lines(output) == [
        '⨯ Failed to call "probe": Probe "localhost:3311" failed: no response',
    ]
Example #34
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