Exemplo n.º 1
0
def test_docker_client_build_with_failure(mocker, caplog):
    caplog.set_level(logging.DEBUG, logger="cekit")

    builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {'tags': ['foo', 'bar']})))

    docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
    squash_class = mocker.patch('cekit.builders.docker_builder.Squash')
    squash = squash_class.return_value
    docker_client = docker_client_class.return_value
    docker_client_build = mocker.patch.object(
        docker_client, 'build', return_value=docker_fail_output)

    builder.generator = Map({'image': {'from': 'FROM'}})

    with pytest.raises(CekitError) as exception:
        builder.run()

    assert "Image build failed, see logs above." in str(exception.value)

    squash_class.assert_not_called()
    squash.run.assert_not_called()
    docker_client_build.assert_called_once_with(
        decode=True, path='something/image', pull=None, rm=True)
    assert "Docker: Step 3/159 : COPY modules /tmp/scripts/" in caplog.text
    assert "You can look inside the failed image by running 'docker run --rm -ti 81a88b63f47f bash'" in caplog.text
Exemplo n.º 2
0
def test_docker_squashing_parameters(mocker):
    builder = DockerBuilder(
        Map(merge_two_dicts({'target': 'something'},
                            {'tags': ['foo', 'bar']})))

    # None is fine here, default values for params are tested in different place
    assert builder.params.no_squash == None

    docker_client_class = mocker.patch(
        'cekit.builders.docker_builder.APIClientClass')
    squash_class = mocker.patch('cekit.builders.docker_builder.Squash')
    squash = squash_class.return_value
    docker_client = docker_client_class.return_value
    mocker.patch.object(builder,
                        '_build_with_docker',
                        return_value="1654234sdf56")

    builder.generator = Map({'image': {'from': 'FROM'}})

    builder.run()

    squash_class.assert_called_once_with(cleanup=True,
                                         docker=docker_client,
                                         from_layer="FROM",
                                         image="1654234sdf56",
                                         log=logging.getLogger('cekit'))
    squash.run.assert_called_once_with()
    builder._build_with_docker.assert_called_once_with(docker_client)
Exemplo n.º 3
0
def test_docker_client_build(mocker, caplog):
    caplog.set_level(logging.DEBUG, logger="cekit")

    builder = DockerBuilder(Map({'target': 'something'}),
                            Map({'tags': ['foo', 'bar']}))

    docker_client_class = mocker.patch(
        'cekit.builders.docker_builder.APIClientClass')
    squash_class = mocker.patch('cekit.builders.docker_builder.Squash')
    squash = squash_class.return_value
    docker_client = docker_client_class.return_value
    docker_client_build = mocker.patch.object(
        docker_client, 'build', return_value=docker_success_output)

    builder.generator = Map({'image': {'from': 'FROM'}})

    builder.run()

    squash_class.assert_called_once_with(cleanup=True,
                                         docker=docker_client,
                                         from_layer="FROM",
                                         image="985573b8bb7b",
                                         log=logging.getLogger('cekit'))
    squash.run.assert_called_once_with()
    docker_client_build.assert_called_once_with(path='something/image',
                                                pull=None,
                                                rm=True)
    assert "Docker: This system is not receiving updates. You can use subscription-manager on the host to register and assign subscriptions." in caplog.text
    assert "Image built and available under following tags: foo, bar" in caplog.text