Exemple #1
0
def assert_tarantool_dependency(filename):
    rpm = rpmfile.open(filename)
    dependency_keys = ['requirename', 'requireversion', 'requireflags']
    for key in dependency_keys:
        assert key in rpm.headers

    assert len(rpm.headers['requirename']) == 2
    assert len(rpm.headers['requireversion']) == 2
    assert len(rpm.headers['requireversion']) == 2

    min_version = re.findall(r'\d+\.\d+\.\d+', tarantool_version())[0]
    max_version = str(int(re.findall(r'\d+', tarantool_version())[0]) + 1)

    assert rpm.headers['requirename'][0].decode('ascii') == 'tarantool'
    assert rpm.headers['requireversion'][0].decode('ascii') == min_version
    assert rpm.headers['requireflags'][0] == 0x08 | 0x04  # >=

    assert rpm.headers['requirename'][1].decode('ascii') == 'tarantool'
    assert rpm.headers['requireversion'][1].decode('ascii') == max_version
    assert rpm.headers['requireflags'][1] == 0x02  # <
def test_pack(docker_image, tmpdir, docker_client):
    project = docker_image.project
    image_name = docker_image.name

    container = docker_client.containers.create(docker_image.name)
    container_distribution_dir = '/usr/share/tarantool/{}'.format(project.name)

    # check if distribution dir was created
    command = '[ -d "{}" ] && echo true || echo false'.format(container_distribution_dir)
    output = run_command_on_image(docker_client, image_name, command)
    assert output == 'true'

    # get distribution dir contents
    arhive_path = os.path.join(tmpdir, 'distribution_dir.tar')
    with open(arhive_path, 'wb') as f:
        bits, _ = container.get_archive(container_distribution_dir)
        for chunk in bits:
            f.write(chunk)

    with tarfile.open(arhive_path) as arch:
        arch.extractall(path=os.path.join(tmpdir, 'usr/share/tarantool'))
    os.remove(arhive_path)

    assert_distribution_dir_contents(
        dir_contents=recursive_listdir(os.path.join(tmpdir, 'usr/share/tarantool/', project.name)),
        project=project,
    )

    assert_filemodes(project, tmpdir)
    container.remove()

    if not tarantool_enterprise_is_used():
        # check if tarantool was installed
        command = 'yum list installed 2>/dev/null | grep tarantool'
        output = run_command_on_image(docker_client, image_name, command)

        packages_list = output.split('\n')
        assert any(['tarantool' in package for package in packages_list])

        # check tarantool version
        command = 'tarantool --version'
        output = run_command_on_image(docker_client, image_name, command)

        m = re.search(r'Tarantool\s+(\d+.\d+)', output)
        assert m is not None
        installed_version = m.group(1)

        m = re.search(r'(\d+.\d+)', tarantool_version())
        assert m is not None
        expected_version = m.group(1)

        assert installed_version == expected_version
def test_pack(docker_image, tmpdir, docker_client):
    project = docker_image.project
    image_name = docker_image.name

    container = docker_client.containers.create(docker_image.name)
    container_distribution_dir = '/usr/share/tarantool/{}'.format(project.name)

    # check if distribution dir was created
    command = '[ -d "{}" ] && echo true || echo false'.format(
        container_distribution_dir)
    output = run_command_on_image(docker_client, image_name, command)
    assert output == 'true'

    # get distribution dir contents
    arhive_path = os.path.join(tmpdir, 'distribution_dir.tar')
    with open(arhive_path, 'wb') as f:
        bits, _ = container.get_archive(container_distribution_dir)
        for chunk in bits:
            f.write(chunk)

    with tarfile.open(arhive_path) as arch:
        arch.extractall(path=os.path.join(tmpdir, 'usr/share/tarantool'))
    os.remove(arhive_path)

    distribution_dir_contents = recursive_listdir(
        os.path.join(tmpdir, 'usr/share/tarantool/', project.name))

    # The runtime image is built using Dockerfile.<random-string> in the
    #   distribution directory
    # This dockerfile name should be added to project distribution files set
    #   to correctly check distribution directory contents
    for f in distribution_dir_contents:
        if f.startswith('Dockerfile') and f not in [
                'Dockerfile.build.cartridge', 'Dockerfile.cartridge'
        ]:
            project.distribution_files.add(f)
            break

    assert_distribution_dir_contents(
        dir_contents=recursive_listdir(
            os.path.join(tmpdir, 'usr/share/tarantool/', project.name)),
        project=project,
    )

    assert_filemodes(project, tmpdir)
    container.remove()

    if project.image_runtime_requirements_filepath is not None:
        command = 'ls {}'.format(project.image_runtime_requirements_filepath)
        output = run_command_on_image(docker_client, image_name, command)
        assert output == project.image_runtime_requirements_filepath

    if not tarantool_enterprise_is_used():
        # check if tarantool was installed
        command = 'yum list installed 2>/dev/null | grep tarantool'
        output = run_command_on_image(docker_client, image_name, command)

        packages_list = output.split('\n')
        assert any(['tarantool' in package for package in packages_list])

        # check tarantool version
        command = 'tarantool --version'
        output = run_command_on_image(docker_client, image_name, command)

        m = re.search(r'Tarantool\s+(\d+.\d+)', output)
        assert m is not None
        installed_version = m.group(1)

        m = re.search(r'(\d+.\d+)', tarantool_version())
        assert m is not None
        expected_version = m.group(1)

        assert installed_version == expected_version
Exemple #4
0
def test_docker_pack(project, docker_image, tmpdir, docker_client):
    image_name = docker_image['name']
    container = docker_client.containers.create(image_name)

    container_distribution_dir = '/usr/share/tarantool/{}'.format(project['name'])

    # check if distribution dir was created
    command = '[ -d "{}" ] && echo true || echo false'.format(container_distribution_dir)
    output = run_command_on_image(docker_client, image_name, command)
    assert output == 'true'

    # get distribution dir contents
    arhive_path = os.path.join(tmpdir, 'distribution_dir.tar')
    with open(arhive_path, 'wb') as f:
        bits, _ = container.get_archive(container_distribution_dir)
        for chunk in bits:
            f.write(chunk)

    with tarfile.open(arhive_path) as arch:
        arch.extractall(path=os.path.join(tmpdir, 'usr/share/tarantool'))
    os.remove(arhive_path)

    assert_dir_contents(
        files_list=recursive_listdir(os.path.join(tmpdir, 'usr/share/tarantool/', project['name'])),
        exp_files_list=project['distribution_files_list'],
        exp_rocks_content=project['rocks_content'],
        skip_tarantool_binaries=True
    )

    assert_filemodes(project, tmpdir)
    container.remove()

    if tarantool_enterprise_is_used():
        # check tarantool and tarantoolctl binaries
        command = '[ -d "/usr/share/tarantool/tarantool-enterprise/" ] && echo true || echo false'
        output = run_command_on_image(docker_client, image_name, command)
        assert output == 'true'

        command = 'cd /usr/share/tarantool/tarantool-enterprise/ && find .'
        output = run_command_on_image(docker_client, image_name, command)

        files_list = output.split('\n')
        files_list.remove('.')

        dir_contents = [
            os.path.normpath(filename)
            for filename in files_list
        ]

        assert 'tarantool' in dir_contents
        assert 'tarantoolctl' in dir_contents
    else:
        # check if tarantool was installed
        command = 'yum list installed 2>/dev/null | grep tarantool'
        output = run_command_on_image(docker_client, image_name, command)

        packages_list = output.split('\n')
        assert any(['tarantool' in package for package in packages_list])

        # check tarantool version
        command = 'yum info tarantool'
        output = run_command_on_image(docker_client, image_name, command)

        m = re.search(r'Version\s+:\s+(\d+)\.(\d+).', output)
        assert m is not None
        installed_version = m.groups()

        m = re.search(r'(\d+)\.(\d+)\.\d+', tarantool_version())
        assert m is not None
        expected_version = m.groups()

        assert installed_version == expected_version