コード例 #1
0
def assert_session_push_commands(project, cmd, exp_connect):
    commands = [
        Command("box.session.push('666')",
                exp_output=get_push_tag_yaml_output('666')),
    ]

    if tarantool_short_version().startswith('2'):
        commands.extend([
            Command("\\set output lua", lua_output='true'),
            Command("box.session.push('777')",
                    exp_output=get_push_tag_lua_output('777')),
            Command("\\set output yaml", yaml_output='true'),
        ])

    rc, output = run_commands_in_pipe(project, cmd, commands)
    assert rc == 0

    out_lines = output.split('\n', maxsplit=1)
    connected_line, commands_output = out_lines

    assert connected_line == 'connected to %s' % exp_connect

    # now I have no idea how to read commands prompt using subprocess
    exp_output = '\n'.join(c.exp_output for c in commands) + '\n'
    assert commands_output == exp_output
コード例 #2
0
def get_successful_commands():
    common_commands = [
        # YAML output

        # valid commands
        Command('return 666', yaml_output='666'),
        Command('777', yaml_output='777'),
        # multiline statement
        Command('if\ntrue\nthen\nreturn 999\nend', yaml_output='999'),
        # undefined variable
        Command('kek', yaml_output='error: \'[string "return kek "]:1: variable \'\'kek\'\' is not declared\''),
        # syntax error
        Command('if+1', yaml_output='error: \'[string "if+1 "]:1: unexpected symbol near \'\'+\'\'\''),
    ]

    set_output_error_commands = [
        Command(
            '\\set output lua',
            yaml_output='error: \'[string "\\set output lua "]:1: unexpected symbol near \'\'\\\'\'\''
        ),
        Command('return 666', yaml_output='666'),

        Command(
            '\\set output yaml',
            yaml_output='error: \'[string "\\set output yaml "]:1: unexpected symbol near \'\'\\\'\'\''
        ),
        Command('return 666', yaml_output='666'),
    ]

    set_output_commands = [
        # Lua output
        Command('\\set output lua', lua_output='true'),

        # valid commands
        Command('return 666', lua_output='666'),
        Command('777', lua_output='777'),
        # multiline statement
        Command('if\ntrue\nthen\nreturn 999\nend', lua_output='999'),

        # YAML output again
        Command('\\set output yaml', yaml_output='true'),
        Command('return 666', yaml_output='666'),
    ]

    commands = common_commands

    if tarantool_short_version().startswith('1.10'):
        commands.extend(set_output_error_commands)
    else:
        commands.extend(set_output_commands)

    return commands
コード例 #3
0
def container_with_installed_deb(docker_client, deb_archive_with_cartridge,
                                 request, tmpdir):
    project = deb_archive_with_cartridge.project

    # build image with installed DEB
    build_path = os.path.join(tmpdir, 'build_image')
    os.makedirs(build_path)

    shutil.copy(deb_archive_with_cartridge.filepath, build_path)

    dockerfile_layers = ["FROM jrei/systemd-ubuntu"]
    if not tarantool_enterprise_is_used():
        dockerfile_layers.append(
            '''RUN apt-get update && apt-get install -y curl \
            && DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata \
            && curl -L https://tarantool.io/installer.sh | VER={} bash
        '''.format(tarantool_short_version()))

    dockerfile_layers.append('''
        COPY {deb_filename} /opt
        RUN apt-get install -y /opt/{deb_filename}
    '''.format(
        deb_filename=os.path.basename(deb_archive_with_cartridge.filepath)))

    with open(os.path.join(build_path, 'Dockerfile'), 'w') as f:
        f.write('\n'.join(dockerfile_layers))

    image_name = '%s-test-deb' % project.name
    build_image(build_path, image_name)

    request.addfinalizer(lambda: delete_image(docker_client, image_name))

    # create container
    http_port = '8183'

    container = docker_client.containers.create(
        image_name,
        command='/lib/systemd/systemd',
        ports={http_port: http_port},
        name='%s-test-deb' % project.name,
        detach=True,
        privileged=True,
        volumes=['/sys/fs/cgroup:/sys/fs/cgroup:ro'],
    )

    request.addfinalizer(lambda: container.remove(force=True))

    return ProjectContainer(project=project,
                            container=container,
                            http_port=http_port)
コード例 #4
0
def container_with_installed_rpm(docker_client, rpm_archive_with_cartridge,
                                 request, tmpdir):
    project = rpm_archive_with_cartridge.project

    # build image with installed RPM
    build_path = os.path.join(tmpdir, 'build_image')
    os.makedirs(build_path)

    shutil.copy(rpm_archive_with_cartridge.filepath, build_path)

    dockerfile_layers = ["FROM centos:7"]
    if not tarantool_enterprise_is_used():
        dockerfile_layers.append('''RUN curl -L \
            https://tarantool.io/installer.sh | VER={} bash
        '''.format(tarantool_short_version()))

    dockerfile_layers.append('''
        COPY {rpm_filename} /opt
        RUN yum install -y /opt/{rpm_filename}
    '''.format(
        rpm_filename=os.path.basename(rpm_archive_with_cartridge.filepath)))

    with open(os.path.join(build_path, 'Dockerfile'), 'w') as f:
        f.write('\n'.join(dockerfile_layers))

    image_name = '%s-test-rpm' % project.name
    build_image(build_path, image_name)

    request.addfinalizer(lambda: delete_image(docker_client, image_name))

    # create container
    http_port = '8183'

    container = docker_client.containers.create(
        image_name,
        command='/sbin/init',
        ports={http_port: http_port},
        name='%s-test-rpm' % project.name,
        detach=True,
        privileged=True,
        volumes=['/sys/fs/cgroup:/sys/fs/cgroup:ro'],
    )

    request.addfinalizer(lambda: container.remove(force=True))

    return ProjectContainer(project=project,
                            container=container,
                            http_port=http_port)
コード例 #5
0
def instance_container_with_unpacked_tgz(docker_client, tmpdir, tgz_archive_with_cartridge, request):
    project = tgz_archive_with_cartridge.project

    # build image with installed Tarantool
    build_path = os.path.join(tmpdir, 'build_image')
    os.makedirs(build_path)

    dockerfile_layers = ["FROM centos:7"]
    if not tarantool_enterprise_is_used():
        dockerfile_layers.append('''RUN curl -L \
            https://tarantool.io/installer.sh | VER={} bash
        '''.format(tarantool_short_version()))

    with open(os.path.join(build_path, 'Dockerfile'), 'w') as f:
        f.write('\n'.join(dockerfile_layers))

    image_name = '%s-test-rpm' % project.name
    build_image(build_path, image_name)

    request.addfinalizer(lambda: delete_image(docker_client, image_name))

    # create container
    instance_name = 'instance-1'
    http_port = '8183'
    advertise_port = '3302'

    environment = [
        'TARANTOOL_APP_NAME=%s' % project.name,
        'TARANTOOL_INSTANCE_NAME=%s' % instance_name,
        'TARANTOOL_ADVERTISE_URI=%s' % advertise_port,
        'TARANTOOL_HTTP_PORT=%s' % http_port,
    ]

    container_proj_path = os.path.join('/opt', project.name)
    init_script_path = os.path.join(container_proj_path, 'init.lua')
    tarantool_executable = \
        os.path.join(container_proj_path, 'tarantool') \
        if tarantool_enterprise_is_used() \
        else 'tarantool'

    cmd = [tarantool_executable, init_script_path]

    container = docker_client.containers.create(
        image_name,
        cmd,
        environment=environment,
        ports={http_port: http_port},
        name='{}-{}'.format(project.name, instance_name),
        detach=True,
    )

    with gzip.open(tgz_archive_with_cartridge.filepath, 'rb') as f:
        container.put_archive('/opt', f.read())

    request.addfinalizer(lambda: container.remove(force=True))

    return InstanceContainer(
        container=container,
        instance_name=instance_name,
        http_port=http_port,
        advertise_port=advertise_port
    )
コード例 #6
0
def get_successful_commands(remote_control):
    common_commands = [
        # YAML output

        # valid commands
        Command('return 666', yaml_output='666'),
        Command('777', yaml_output='777'),
        # multiline statement
        Command('if\ntrue\nthen\nreturn 999\nend', yaml_output='999'),
        # undefined variable
        Command(
            'kek',
            yaml_output=
            'error: \'[string "return kek "]:1: variable \'\'kek\'\' is not declared\''
        ),
        # syntax error
        Command(
            'if+1',
            yaml_output=
            'error: \'[string "if+1 "]:1: unexpected symbol near \'\'+\'\'\''),
    ]

    set_output_error_commands = [
        Command(
            '\\set output lua',
            yaml_output=
            'error: \'[string "\\set output lua "]:1: unexpected symbol near \'\'\\\'\'\''
        ),
        Command('return 666', yaml_output='666'),
        Command(
            '\\set output yaml',
            yaml_output=
            'error: \'[string "\\set output yaml "]:1: unexpected symbol near \'\'\\\'\'\''
        ),
        Command('return 666', yaml_output='666'),
    ]

    set_output_commands = [
        # Lua output
        Command('\\set output lua', lua_output='true'),

        # valid commands
        Command('return 666', lua_output='666'),
        Command('777', lua_output='777'),
        # multiline statement
        Command('if\ntrue\nthen\nreturn 999\nend', lua_output='999'),

        # YAML output again
        Command('\\set output yaml', yaml_output='true'),
        Command('return 666', yaml_output='666'),
    ]

    # Since cartridge 2.7.0, cartridge process remote control requests
    # in separate fibers, so setting output is reset after each request.
    # https://github.com/tarantool/cartridge/commit/a66754967f99593039fabca4f31f9ca8f6340df1
    set_output_remote_commands = [
        # valid commands
        Command('return 666', yaml_output='666'),
        Command('777', yaml_output='777'),
        # multiline statement
        Command('if\ntrue\nthen\nreturn 999\nend', yaml_output='999'),
    ]

    commands = common_commands

    if tarantool_short_version().startswith('1.10'):
        commands.extend(set_output_error_commands)
    else:
        if remote_control:
            commands.extend(set_output_remote_commands)
        else:
            commands.extend(set_output_commands)

    return commands