Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
def test_osbs_builder_run_brew_user(mocker):
config.cfg['common'] = {'redhat': True}
params = {'user': 'Foo'}
check_output = mocker.patch.object(subprocess, 'check_output', autospec=True, side_effect=[
b'ssh://user:password@something.redhat.com/containers/openjdk', b'c5a0731b558c8a247dd7f85b5f54462cd5b68b23', b'12345'])
builder = create_builder_object(mocker, 'osbs', params)
builder.generator = Map({'image': Map({})})
mocker.patch.object(builder, '_wait_for_osbs_task')
builder.dist_git.branch = "some-branch"
builder.run()
check_output.assert_called_with(['/usr/bin/brew', '--user', 'Foo', 'call', '--python', 'buildContainer', '--kwargs',
"{'src': 'git://something.redhat.com/containers/openjdk#c5a0731b558c8a247dd7f85b5f54462cd5b68b23', 'target': 'some-branch-containers-candidate', 'opts': {'scratch': True, 'git_branch': 'some-branch', 'yum_repourls': []}}"])
def test_osbs_builder_run_koji(mocker):
check_output = mocker.patch.object(subprocess, 'check_output', autospec=True, side_effect=[
b'ssh://user:password@something.redhat.com/containers/openjdk', b'c5a0731b558c8a247dd7f85b5f54462cd5b68b23', b'12345'])
builder = create_builder_object(mocker, 'osbs', {}, {'redhat': False, 'target': 'something'})
builder.generator = Map({'image': Map({})})
mocker.patch.object(builder, '_wait_for_osbs_task')
builder.dist_git.branch = "some-branch"
builder.run()
check_output.assert_has_calls([
call(['git', 'config', '--get', 'remote.origin.url']),
call(['git', 'rev-parse', 'HEAD']),
call(['/usr/bin/koji', 'call', '--python', 'buildContainer', '--kwargs',
"{'src': 'git://something.redhat.com/containers/openjdk#c5a0731b558c8a247dd7f85b5f54462cd5b68b23', 'target': 'some-branch-containers-candidate', 'opts': {'scratch': True, 'git_branch': 'some-branch', 'yum_repourls': []}}"])
])
builder._wait_for_osbs_task.assert_called_once_with('12345')
def test_osbs_builder_run_brew_stage(mocker):
config.cfg['common'] = {'redhat': True}
params = {'stage': True}
check_output = mocker.patch.object(subprocess, 'check_output', autospec=True, side_effect=[
b'ssh://user:password@something.redhat.com/containers/openjdk', b'c5a0731b558c8a247dd7f85b5f54462cd5b68b23', b'12345'])
builder = create_builder_object(mocker, 'osbs', params)
builder.generator = Map({'image': Map({})})
mocker.patch.object(builder, '_wait_for_osbs_task')
builder.dist_git.branch = "some-branch"
builder.run()
check_output.assert_has_calls([
call(['git', 'config', '--get', 'remote.origin.url']),
call(['git', 'rev-parse', 'HEAD']),
call(['/usr/bin/brew-stage', 'call', '--python', 'buildContainer', '--kwargs',
"{'src': 'git://something.redhat.com/containers/openjdk#c5a0731b558c8a247dd7f85b5f54462cd5b68b23', 'target': 'some-branch-containers-candidate', 'opts': {'scratch': True, 'git_branch': 'some-branch', 'yum_repourls': []}}"])
])
builder._wait_for_osbs_task.assert_called_once_with('12345')
def test_docker_client_build(mocker, caplog):
caplog.set_level(logging.DEBUG, logger="cekit")
squash_class = mocker.patch('cekit.builders.docker_builder.Squash')
squash = squash_class.return_value
docker_client_class = mocker.patch('cekit.builders.docker_builder.APIClientClass')
docker_client = docker_client_class.return_value
docker_client_build = mocker.patch.object(
docker_client, 'build', return_value=docker_success_output)
builder = DockerBuilder(Map(merge_two_dicts({'target': 'something'}, {'tags': ['foo', 'bar']})))
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(
decode=True, 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
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)
version: 1.9
"""), 'foo')
module_a = Module(yaml.safe_load("""
name: org.test.module.a
version: 1.0
"""), 'path', 'artifact_path')
module_registry = ModuleRegistry()
module_registry.add_module(module_a)
resulting_install_list = OrderedDict()
to_install_list = [
Map({'name': 'org.test.module.a', 'version': '1.0'}),
Map({'name': 'org.test.module.b'})
]
with pytest.raises(CekitError) as excinfo:
image.process_install_list(image, to_install_list, resulting_install_list, module_registry)
assert "There are no modules with 'org.test.module.b' name available" in str(excinfo.value)
def test_osbs_builder_run_brew_target_defined_in_descriptor(mocker):
config.cfg['common'] = {'redhat': True}
check_output = mocker.patch.object(subprocess, 'check_output', autospec=True, side_effect=[
b'ssh://user:password@something.redhat.com/containers/openjdk', b'c5a0731b558c8a247dd7f85b5f54462cd5b68b23', b'12345'])
builder = create_builder_object(mocker, 'osbs', {})
builder.generator = Map({'image': Map({'osbs': Map({'koji_target': 'some-target'})})})
mocker.patch.object(builder, '_wait_for_osbs_task')
builder.dist_git.branch = "some-branch"
builder.run()
check_output.assert_called_with(['/usr/bin/brew', 'call', '--python', 'buildContainer', '--kwargs',
"{'src': 'git://something.redhat.com/containers/openjdk#c5a0731b558c8a247dd7f85b5f54462cd5b68b23', 'target': 'some-target', 'opts': {'scratch': True, 'git_branch': 'some-branch', 'yum_repourls': []}}"])
"""
Convert provided dictionary, recursively, into a Map object.
This will make it possible to access nested elements
via properties:
res.git.url
instead of:
res.git['url]
"""
if not isinstance(dictionary, dict):
return dictionary
converted = Map()
for key in dictionary:
converted[key] = self.__to_map(dictionary[key])
return converted