コード例 #1
0
def test_start_stop_status_cfg(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    ID2 = get_instance_id(project.name, 'instance-2')
    CFG = 'my-conf.yml'

    write_conf(os.path.join(project.path, CFG), {
        ID1: {},
        ID2: {},
    })

    status = cli.get_status(project, cfg=CFG)
    assert status.get(ID1) == STATUS_NOT_STARTED
    assert status.get(ID2) == STATUS_NOT_STARTED

    cli.start(project, stateboard=True, daemonized=True, cfg=CFG)
    check_instances_running(
        cli, project,
        [ID1, ID2],
        stateboard=True, cfg=CFG,
        daemonized=True,
    )

    status = cli.get_status(project, cfg=CFG)
    assert status.get(ID1) == STATUS_RUNNING
    assert status.get(ID2) == STATUS_RUNNING

    cli.stop(project, stateboard=True, cfg=CFG)
    check_instances_stopped(cli, project, [ID1, ID2])

    status = cli.get_status(project, cfg=CFG)
    assert status.get(ID1) == STATUS_STOPPED
    assert status.get(ID2) == STATUS_STOPPED
コード例 #2
0
def test_start_interactive_stateboard_only(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    # start with stateboard-only flag
    cli.start(project, stateboard_only=True)
    check_instances_running(cli, project, stateboard_only=True)
コード例 #3
0
def test_start_stop_status_run_dir(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    # ID2 = get_instance_id(project.name, 'instance-2')
    RUN_DIR = 'my-run'

    status = cli.get_status(project, [ID1], run_dir=RUN_DIR)
    assert status.get(ID1) == STATUS_NOT_STARTED
    # assert status.get(ID2) == STATUS_NOT_STARTED

    cli.start(project, [ID1], stateboard=True, daemonized=True, run_dir=RUN_DIR)
    check_instances_running(
        cli, project,
        [ID1],
        stateboard=True, run_dir=RUN_DIR,
        daemonized=True
    )

    status = cli.get_status(project, [ID1], run_dir=RUN_DIR)
    assert status.get(ID1) == STATUS_RUNNING
    # assert status.get(ID2) == STATUS_RUNNING

    cli.stop(project, [ID1], stateboard=True, run_dir=RUN_DIR)
    check_instances_stopped(cli, project, [ID1], run_dir=RUN_DIR)

    status = cli.get_status(project, [ID1], run_dir=RUN_DIR)
    assert status.get(ID1) == STATUS_STOPPED
コード例 #4
0
def test_start_interactive_by_id(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')

    # start instance-1
    cli.start(project, [ID1])
    check_instances_running(cli, project, [ID1])
コード例 #5
0
def test_start_stop_stateboard_only(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    # start with stateboard-only flag
    cli.start(project, daemonized=True, stateboard_only=True)
    check_instances_running(cli, project, daemonized=True, stateboard_only=True)

    # stop stateboard
    cli.stop(project, stateboard_only=True)
    check_instances_stopped(cli, project, stateboard_only=True)
コード例 #6
0
def test_start_interactive_run_dir(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    # ID2 = get_instance_id(project.name, 'instance-2')
    RUN_DIR = 'my-run'

    cli.start(project, [ID1], stateboard=True, run_dir=RUN_DIR)
    check_instances_running(
        cli, project,
        [ID1],
        stateboard=True, run_dir=RUN_DIR
    )
コード例 #7
0
def test_start_interactive_from_conf(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    ID2 = get_instance_id(project.name, 'instance-2')

    write_conf(os.path.join(project.path, DEFAULT_CFG), {
        ID1: {},
        ID2: {},
    })

    # start instances
    cli.start(project)
    check_instances_running(cli, project, [ID1, ID2])
コード例 #8
0
def test_start_script(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    # ID2 = get_instance_id(project.name, 'instance-2')

    SCRIPT = 'my-init.lua'
    shutil.copyfile(os.path.join(project.path, DEFAULT_SCRIPT), os.path.join(project.path, SCRIPT))

    cli.start(project, [ID1], stateboard=True, script=SCRIPT)
    check_instances_running(
        cli, project,
        [ID1],
        stateboard=True, script=SCRIPT
    )
コード例 #9
0
def test_start_stop_by_id_with_stateboard(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    ID2 = get_instance_id(project.name, 'instance-2')

    # start instance-1 and stateboard
    cli.start(project, [ID1], daemonized=True, stateboard=True)
    # start instance-2
    cli.start(project, [ID2], daemonized=True)
    check_instances_running(cli, project, [ID1, ID2], daemonized=True, stateboard=True)

    # stop instance-1 and stateboard
    cli.stop(project, [ID1], stateboard=True)
    check_instances_running(cli, project, [ID2], daemonized=True)
    check_instances_stopped(cli, project, [ID1], stateboard=True)
コード例 #10
0
def test_start_interactive_cfg(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    ID2 = get_instance_id(project.name, 'instance-2')
    CFG = 'my-conf.yml'

    write_conf(os.path.join(project.path, CFG), {
        ID1: {},
        ID2: {},
    })

    cli.start(project, stateboard=True, cfg=CFG)
    check_instances_running(
        cli, project,
        [ID1, ID2],
        stateboard=True, cfg=CFG
    )
コード例 #11
0
def test_start_stop_from_conf_stateboard_only(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    ID2 = get_instance_id(project.name, 'instance-2')

    write_conf(os.path.join(project.path, DEFAULT_CFG), {
        ID1: {},
        ID2: {},
    })

    # start instances
    cli.start(project, daemonized=True, stateboard_only=True)
    check_instances_running(cli, project, daemonized=True, stateboard_only=True)

    # stop instances
    cli.stop(project, stateboard=True)
    check_instances_stopped(cli, project, stateboard_only=True)
コード例 #12
0
def test_api(cartridge_cmd, project_getting_started):
    project = project_getting_started
    cli = Cli(cartridge_cmd)

    APP_INSTANCES = [get_instance_id(project.name, 'router')]
    S1_INSTANCES = [get_instance_id(project.name, 's1-master'), get_instance_id(project.name, 's1-replica')]
    S2_INSTANCES = [get_instance_id(project.name, 's2-master'), get_instance_id(project.name, 's2-replica')]

    # build app
    process = subprocess.run([cartridge_cmd, 'build'], cwd=project.path)
    assert process.returncode == 0

    patch_cartridge_proc_titile(project)

    # check config and get instances
    instances_conf = get_instances_from_conf(project)
    instances = list(instances_conf.keys())

    assert all([
        instance in instances
        for instance in APP_INSTANCES + S1_INSTANCES + S2_INSTANCES
    ])

    router_http_port = instances_conf[APP_INSTANCES[0]]['http_port']
    admin_api_url = 'http://localhost:{}/admin/api'.format(router_http_port)

    # start application in interactive mode (to easily check logs on debug)
    cli.start(project)
    check_instances_running(cli, project, instances)

    # create app replicaset
    uris = [instances_conf[instance]['advertise_uri'] for instance in APP_INSTANCES]
    roles = ['api']
    app_replicaset_uuid = create_replicaset(admin_api_url, uris, roles)
    wait_for_replicaset_is_healthy(admin_api_url, app_replicaset_uuid)

    replicaset_roles = get_replicaset_roles(admin_api_url, app_replicaset_uuid)
    # api role should contain vshard-router dependency
    assert set(replicaset_roles) == set(['api', 'vshard-router'])

    # create s1 replicaset
    uris = [instances_conf[instance]['advertise_uri'] for instance in S1_INSTANCES]
    roles = ['storage']
    s1_replicaset_uuid = create_replicaset(admin_api_url, uris, roles)
    wait_for_replicaset_is_healthy(admin_api_url, s1_replicaset_uuid)

    replicaset_roles = get_replicaset_roles(admin_api_url, s1_replicaset_uuid)
    # storage role should contain vshard-storage dependency
    assert set(replicaset_roles) == set(['storage', 'vshard-storage'])

    # create s2 replicaset
    uris = [instances_conf[instance]['advertise_uri'] for instance in S2_INSTANCES]
    roles = ['storage']
    s2_replicaset_uuid = create_replicaset(admin_api_url, uris, roles)
    wait_for_replicaset_is_healthy(admin_api_url, s2_replicaset_uuid)

    replicaset_roles = get_replicaset_roles(admin_api_url, s2_replicaset_uuid)
    # storage role should contain vshard-storage dependency
    assert set(replicaset_roles) == set(['storage', 'vshard-storage'])

    # bootstrap vshard
    bootstrap_vshard(admin_api_url)

    # test HTTP API
    CUSTOMER_ID = 10
    CUSTOMER_NAME = 'Elizabeth'
    customer = {
        'customer_id': CUSTOMER_ID,
        'name': CUSTOMER_NAME
    }

    # create new customer
    url = 'http://localhost:{}/storage/customers/create'.format(router_http_port)
    r = requests.post(url, json=customer)
    assert r.status_code == requests.status_codes.codes.CREATED
    resp = r.json()
    assert 'info' in resp
    assert resp['info'] == 'Successfully created'

    # # create the same customer again
    # r = requests.post(url, json=customer)
    # # XXX: r.status_code is 500 now

    # get customer
    url = 'http://localhost:{}/storage/customers/{}'.format(router_http_port, CUSTOMER_ID)
    r = requests.get(url, json=customer)
    assert r.status_code == requests.status_codes.codes.OK
    resp = r.json()
    assert resp == {
        'customer_id': CUSTOMER_ID,
        'name': CUSTOMER_NAME,
        'accounts': [],
    }

    # get customer by wrong id
    url = 'http://localhost:{}/storage/customers/{}'.format(router_http_port, CUSTOMER_ID+1)
    r = requests.get(url, json=customer)
    assert r.status_code == requests.status_codes.codes.NOT_FOUND
    resp = r.json()
    assert 'info' in resp
    assert resp['info'] == 'Customer not found'
コード例 #13
0
def test_status_from_conf(cartridge_cmd, project_with_patched_init):
    project = project_with_patched_init
    cli = Cli(cartridge_cmd)

    ID1 = get_instance_id(project.name, 'instance-1')
    ID2 = get_instance_id(project.name, 'instance-2')
    STATEBOARD_ID = get_stateboard_name(project.name)

    write_conf(os.path.join(project.path, DEFAULT_CFG), {
        ID1: {},
        ID2: {},
    })

    # get status w/o stateboard
    status = cli.get_status(project)
    assert len(status) == 2
    assert status.get(ID1) == STATUS_NOT_STARTED
    assert status.get(ID2) == STATUS_NOT_STARTED

    # get status w/ stateboard
    status = cli.get_status(project, stateboard=True)
    assert len(status) == 3
    assert status.get(ID1) == STATUS_NOT_STARTED
    assert status.get(ID2) == STATUS_NOT_STARTED
    assert status.get(STATEBOARD_ID) == STATUS_NOT_STARTED

    # get status stateboard-only
    status = cli.get_status(project, stateboard_only=True)
    assert len(status) == 1
    assert status.get(STATEBOARD_ID) == STATUS_NOT_STARTED

    # start instance-1 and stateboard
    cli.start(project, [ID1], stateboard=True, daemonized=True)
    wait_instances(cli, project, [ID1], stateboard=True)

    # get status w/o stateboard
    status = cli.get_status(project)
    assert len(status) == 2
    assert status.get(ID1) == STATUS_RUNNING
    assert status.get(ID2) == STATUS_NOT_STARTED

    # get status w/ stateboard
    status = cli.get_status(project, stateboard=True)
    assert len(status) == 3
    assert status.get(ID1) == STATUS_RUNNING
    assert status.get(ID2) == STATUS_NOT_STARTED
    assert status.get(STATEBOARD_ID) == STATUS_RUNNING

    # get status stateboard-only
    status = cli.get_status(project, stateboard_only=True)
    assert len(status) == 1
    assert status.get(STATEBOARD_ID) == STATUS_RUNNING

    # stop instance-1
    cli.stop(project, [ID1])

    # get status w/o stateboard
    status = cli.get_status(project)
    assert len(status) == 2
    assert status.get(ID1) == STATUS_STOPPED
    assert status.get(ID2) == STATUS_NOT_STARTED

    # get status w/ stateboard
    status = cli.get_status(project, stateboard=True)
    assert len(status) == 3
    assert status.get(ID1) == STATUS_STOPPED
    assert status.get(ID2) == STATUS_NOT_STARTED
    assert status.get(STATEBOARD_ID) == STATUS_RUNNING

    # get status stateboard-only
    status = cli.get_status(project, stateboard_only=True)
    assert len(status) == 1
    assert status.get(STATEBOARD_ID) == STATUS_RUNNING