Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_cekit(cwd, parameters=None, message=None, env=None):
if parameters is None:
parameters = ['build', '--dry-run', 'podman']
if env is None:
env = {}
with Chdir(cwd):
result = CliRunner(env=env).invoke(cli, parameters, catch_exceptions=False)
assert result.exit_code == 0
if message:
assert message in result.output
return result
def run_cekit(image_dir, args=None, descriptor=None):
if args is None:
args = ['build', '--dry-run', 'docker']
if descriptor is None:
descriptor = image_descriptor
with Chdir(image_dir):
with open('image.yaml', 'w') as fd:
yaml.dump(descriptor, fd, default_flow_style=False)
result = CliRunner().invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0
return result
def run_cekit(image_dir, args=None, env=None):
if args is None:
args = ['build', '--dry-run', 'docker']
if env is None:
env = {}
with Chdir(image_dir):
result = CliRunner(env=env).invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0
return result
def run_cekit(cwd,
parameters=['build', '--dry-run', 'docker'],
message=None, return_code=0):
with Chdir(cwd):
result = CliRunner().invoke(cli, parameters, catch_exceptions=False)
assert result.exit_code == return_code
if message:
assert message in result.output
return result
def run_cekit(cwd, args=['build', '--dry-run', 'docker']):
with Chdir(cwd):
return CliRunner().invoke(cli, args, catch_exceptions=False)
def run_cekit(image_dir, args=None, descriptor=None):
if args is None:
args = ['build', '--dry-run', 'docker']
if descriptor is None:
descriptor = image_descriptor
with Chdir(image_dir):
with open('image.yaml', 'w') as fd:
yaml.dump(descriptor, fd, default_flow_style=False)
result = CliRunner().invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0
return result
def run_cekit(image_dir, args=None, env=None):
if args is None:
args = ['build', '--dry-run', 'docker']
if env is None:
env = {}
with Chdir(image_dir):
result = CliRunner(env=env).invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0
return result
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'))
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': []}}"])