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_module_processing_fail_when_no_modules_of_specified_name_can_be_found():
image = Image(yaml.safe_load("""
from: foo
name: test/foo
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 = [
def test_module_processing_simple_modules_order_to_install():
image = Image(yaml.safe_load("""
from: foo
name: test/foo
version: 1.9
"""), 'foo')
module_a = Module(yaml.safe_load("""
name: org.test.module.a
version: 1.0
"""), 'path', 'artifact_path')
module_b = Module(yaml.safe_load("""
name: org.test.module.b
version: 1.0
"""), 'path', 'artifact_path')
module_registry = ModuleRegistry()
def test_overide_resource_remove_chksum():
image = Image(yaml.safe_load("""
from: foo
name: test/foo
version: 1.9
artifacts:
- name: abs
path: /tmp/abs
md5: 'foo'
sha1: 'foo'
sha256: 'foo'
sha512: 'foo'
"""), 'foo')
overrides = Overrides(yaml.safe_load("""
artifacts:
- name: abs
path: /tmp/over
"""), 'foo')
def test_remove_none_key():
image = Image(yaml.safe_load("""
from: foo
name: test/foo
version: 1.9
envs:
- name: foo
value: ~
"""), 'foo')
image.remove_none_keys()
assert 'envs' in image
assert 'value' not in image['envs'][0]
def test_image_overrides_with_content_sets_file_none(mocker):
with mocker.mock_module.patch('cekit.descriptor.packages.os.path.exists') as exists_mock:
exists_mock.return_value = True
with mocker.mock_module.patch('cekit.descriptor.packages.open', mocker.mock_open(read_data='{"arch": ["a", "b"]}')):
image = Image(yaml.safe_load("""
from: foo
name: test/foo
version: 1.9
packages:
install:
- abc
def
content_sets_file: cs.yaml
"""), 'foo')
assert image.packages.content_sets == {'arch': ['a', 'b']}
assert 'content_sets_file' not in image.packages
image.apply_image_overrides([Overrides({'packages': {'content_sets_file': None}}, "a/path")])
assert 'content_sets' not in image.packages
def test_image_no_name():
with pytest.raises(CekitError) as excinfo:
Image(yaml.safe_load("""
version: 1.9
labels:
- name: test
value: val1
- name: label2
value: val2
envs:
- name: env1
value: env1val
"""), 'foo')
assert 'Cannot validate schema' in str(excinfo.value)
def test_podman_builder_run_with_generator(mocker):
params = Map({'tags': []})
check_call = mocker.patch.object(subprocess, 'check_call')
builder = create_builder_object(mocker, 'podman', params)
builder.generator = DockerGenerator("", "", {})
builder.generator.image = Image(yaml.safe_load("""
name: foo
version: 1.9
labels:
- name: test
value: val1
- name: label2
value: val2
envs:
- name: env1
value: env1val
"""), 'foo')
builder.run()
check_call.assert_called_once_with(['/usr/bin/podman',
'build',
'--squash',
from cekit.descriptor import Image
from cekit.descriptor.image import get_image_schema
overrides_schema = get_image_schema()
overrides_schema['map']['name'] = {'type': 'str'}
overrides_schema['map']['version'] = {'type': 'text'}
class Overrides(Image):
def __init__(self, descriptor, artifact_dir):
self._artifact_dir = artifact_dir
self.path = artifact_dir
schema = overrides_schema.copy()
self.schema = schema
# calling Descriptor constructor only here (we dont wat Image() to mess with schema)
super(Image, self).__init__(descriptor)
self._prepare()
def __init__(self, descriptor, path, artifact_dir):
self._artifact_dir = artifact_dir
self.path = path
self.schema = get_image_schema().copy()
# calling Descriptor constructor only here (we don't want Image() to mess with schema)
super(Image, self).__init__(descriptor)
self.skip_merging = ['description',
'version',
'name',
'release',
'help']
self._prepare()
self.name = self._descriptor['name']
self._descriptor['execute'] = [Execute(x, self.name)
for x in self._descriptor.get('execute', [])]
shutil.rmtree(self.target, ignore_errors=True)
os.makedirs(os.path.join(self.target, 'image'))
# Read the main image descriptor and create an Image object from it
descriptor = tools.load_descriptor(self._descriptor_path)
if isinstance(descriptor, list):
LOGGER.info("Descriptor contains multiple elements, assuming multi-stage image")
LOGGER.info("Found {} builder image(s) and one target image".format(
len(descriptor[:-1])))
# Iterate over images defined in image descriptor and
# create Image objects out of them
for image_descriptor in descriptor[:-1]:
self.builder_images.append(
Image(image_descriptor, os.path.dirname(os.path.abspath(self._descriptor_path))))
descriptor = descriptor[-1]
self.image = Image(descriptor, os.path.dirname(os.path.abspath(self._descriptor_path)))
# apply overrides to the image definition
self.image.apply_image_overrides(self._overrides)
for builder in self.builder_images:
builder.apply_image_overrides(self._overrides)
# add build labels
self.add_build_labels()
# load the definitions of the modules
self.build_module_registry()
# process included modules