def _inject_redhat_defaults(self): envs = [{ 'name': 'JBOSS_IMAGE_NAME', 'value': '%s' % self.image['name'] }, { 'name': 'JBOSS_IMAGE_VERSION', 'value': '%s' % self.image['version'] }] labels = [{ 'name': 'name', 'value': '%s' % self.image['name'] }, { 'name': 'version', 'value': '%s' % self.image['version'] }] # do not override this label if it's already set if self.image.get('ports', []) and \ 'io.openshift.expose-services' not in [ k['name'] for k in self.image['labels'] ]: labels.append({ 'name': 'io.openshift.expose-services', 'value': self._generate_expose_services() }) redhat_override = {'envs': envs, 'labels': labels} descriptor = Overrides(redhat_override, None) descriptor.merge(self.image) self.image = descriptor
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' """), 'foo') overrides = Overrides( yaml.safe_load(""" artifacts: - name: abs path: /tmp/over """), 'foo') overrides.merge(image) assert overrides['from'] == 'foo' assert overrides['artifacts'][0]['path'] == '/tmp/over' assert 'md5' not in overrides['artifacts'][0] assert 'sha1' not in overrides['artifacts'][0] assert 'sha256' not in overrides['artifacts'][0]
def override(self, overrides_path): logger.info("Using overrides file from '%s'." % overrides_path) descriptor = Overrides( tools.load_descriptor(overrides_path), os.path.dirname(os.path.abspath(overrides_path))) descriptor.merge(self.image) return descriptor
def test_merging_description_override(): desc1 = Image({'name': 'foo', 'version': 1}, None) desc2 = Overrides({'name': 'mod1', 'description': 'mod_desc'}, None) merged = _merge_descriptors(desc2, desc1) assert 'description' in merged
def test_image_overrides_with_content_sets(): image = Image( yaml.safe_load(""" from: foo name: test/foo version: 1.9 packages: install: - abc - def content_sets: arch: - namea - nameb """), 'foo') assert image.packages.content_sets == {'arch': ['namea', 'nameb']} assert 'content_sets_file' not in image.packages image.apply_image_overrides([ Overrides({'packages': { 'content_sets': { 'arch': ['new-arch'] } }}, "a/path") ]) assert image.packages.content_sets == {'arch': ['new-arch']} assert 'content_sets_file' not in image.packages
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 assert 'content_sets_file' not in image.packages
def test_image_overrides_packages_repositories_replace(): image = Image( yaml.safe_load(""" from: foo name: test/foo version: 1.9 packages: repositories: - name: scl rpm: centos-release-scl """), 'foo') assert len(image.packages.repositories) == 1 assert image.packages.repositories[0].rpm == 'centos-release-scl' assert image.packages.repositories[0].name == 'scl' image.apply_image_overrides([ Overrides( { 'packages': { 'repositories': [{ "id": "rhel7-extras-rpm", "name": "scl" }] } }, "a/path") ]) assert len(image.packages.repositories) == 1 assert image.packages.repositories[0].name == 'scl' assert image.packages.repositories[0].id == 'rhel7-extras-rpm' assert 'rpm' not in image.packages.repositories[0]
def _inject_redhat_defaults(self): envs = [{'name': 'JBOSS_IMAGE_NAME', 'value': '%s' % self.image['name']}, {'name': 'JBOSS_IMAGE_VERSION', 'value': '%s' % self.image['version']}] labels = [{'name': 'name', 'value': '%s' % self.image['name']}, {'name': 'version', 'value': '%s' % self.image['version']}] redhat_override = {'envs': envs, 'labels': labels} descriptor = Overrides(redhat_override, None) descriptor.merge(self.image) self.image = descriptor
def __init__(self, descriptor_path, target, overrides): self._descriptor_path = descriptor_path self._overrides = [] self.target = target self._fetch_repos = False self._module_registry = ModuleRegistry() self.image = None if overrides: for override in overrides: # TODO: If the overrides is provided as text, why do we try to get path to it? LOGGER.debug("Loading override '%s'" % (override)) self._overrides.append(Overrides(tools.load_descriptor( override), os.path.dirname(os.path.abspath(override)))) LOGGER.info("Initializing image descriptor...")
def __init__(self, descriptor_path, target, overrides): self._descriptor_path = descriptor_path self._overrides = [] self.target = target self._fetch_repos = False self._module_registry = ModuleRegistry() self.image = None self.builder_images = [] self.images = [] if overrides: for override in overrides: LOGGER.debug("Loading override '{}'".format(override)) override_artifact_dir = os.path.dirname(os.path.abspath(override)) if not os.path.exists(override): override_artifact_dir = os.path.dirname(os.path.abspath(descriptor_path)) self._overrides.append(Overrides(tools.load_descriptor( override), override_artifact_dir)) LOGGER.info("Initializing image descriptor...")