def process_install_list(self, source, to_install_list, install_list, module_registry): module_overrides = self._image_overrides['modules'] artifact_overrides = self._image_overrides['artifacts'] for to_install in to_install_list: logger.debug("Preparing module '{}' required by '{}'.".format( to_install.name, source.name)) override = module_overrides.get(to_install.name, None) if override: if override.version != to_install.version: logger.debug("Module '{}:{}' being overridden with '{}:{}'.".format (to_install.name, to_install.version, override.name, override.version)) # apply module override to_install = override existing = install_list.get(to_install.name, None) # see if we've already processed this if existing: # check for a version conflict if existing.version != to_install.version: logger.warning("Module version inconsistency for {}: {} requested, but {} will be used.".format( to_install.name, to_install.version, existing.version)) continue module = module_registry.get_module(to_install.name, to_install.version) if not module: raise CekitError("Could not locate module %s version %s. Please verify that it is included in one of the " "specified module repositories." % (to_install.name, to_install.version)) # collect artifacts and apply overrides module_artifacts = Image._to_dict(module.artifacts) for artifact in module.artifacts: name = artifact.name if name in artifact_overrides: override = artifact_overrides[name] self._all_artifacts[name] = override module_artifacts[name] = override else: self._all_artifacts[name] = artifact module._descriptor['artifacts'] = list(module_artifacts.values()) # collect package repositories for repo in module.packages.repositories: name = repo.name if not name in self._package_repositories: self._package_repositories[name] = repo # incorporate run specification contributed by module if module.run: # we're looping in order of install, so we want the current module to override whatever we have self._module_run = module.run.merge(self._module_run) # prevent circular dependencies. we'll move it to the end after processing install_list[to_install.name] = to_install # process this modules dependencies self.process_install_list(module, module.modules.install, install_list, module_registry) # move this module to the end of the list. install_list.pop(to_install.name) install_list[to_install.name] = to_install
def apply_image_overrides(self, overrides): """ Applies overrides to the image descriptor. """ if not overrides: return for override in overrides: if override.name: self.name = override.name if override.version: self.version = override.version if override.base: self.base = override.base if override.description: self.description = override.description labels = Image._to_dict(self.labels) for label in override.labels: name = label.name if name in labels: labels[name] = label.merge(labels[name]) else: labels[name] = label self._descriptor['labels'] = list(labels.values()) envs = Image._to_dict(self.envs) for env in override.envs: name = env.name if name in envs: envs[name] = env.merge(envs[name]) else: envs[name] = env self._descriptor['envs'] = list(envs.values()) ports = Image._to_dict(self.ports) for port in override.ports: name = port.value if name in ports: ports[name] = port.merge(ports[name]) else: ports[name] = port self._descriptor['ports'] = list(ports.values()) module_repositories = Image._to_dict(self.modules.repositories) for repository in override.modules.repositories: name = repository.name if name in module_repositories: module_repositories[name] = repository.merge( module_repositories[name]) else: module_repositories[name] = repository self.modules._descriptor['repositories'] = list( module_repositories.values()) self.packages._descriptor = override.packages.merge(self.packages) # In case content sets are provided as null values # Remove the key entirely. # TODO: This should be handled probably at general level, for every key for flag in ['content_sets', 'content_sets_file']: if flag in override.packages and override.packages[ flag] is None: self.packages._descriptor.pop('content_sets', None) self.packages._descriptor.pop('content_sets_file', None) if override.osbs is not None: self.osbs = override.osbs.merge(self.osbs) for package in override.packages.install: if package not in self.packages.install: self.packages.install.append(package) artifact_overrides = self._image_overrides['artifacts'] image_artifacts = Image._to_dict(self.artifacts) for i, artifact in enumerate(override.artifacts): name = artifact.name # logger.debug("### Looking to apply override '{}' to artifact '{}'".format(artifact, artifact_overrides.get(name))) # override.artifact contains override values WITH defaults. # override.original_descriptor contains override value WITHOUT defaults. # artifact_overrides contains original dictionary # # Iterating over dest / target / ... # If we have _not_ supplied a target (check original_descriptor), # then check artifact_overrides, # otherwise use default from override.artifact override_without_defaults = override.original_descriptor.get( 'artifacts')[i] for key in ['dest', 'target', 'description']: if override_without_defaults.get(key): logger.debug("Key ({}) found in override as {}".format( key, override_without_defaults.get(key))) artifact[key] = override_without_defaults.get(key) elif artifact_overrides.get( name) and artifact_overrides.get(name).get(key): new_value = artifact_overrides.get(name).get(key) logger.debug( "Key ({}) found in original artifact as {}".format( key, new_value)) artifact[key] = new_value # collect override so we can apply it to modules artifact_overrides[name] = artifact # add it to the list of everything self._all_artifacts[name] = artifact # Apply override to image descriptor image_artifacts[name] = artifact # Sort the output as it makes it easier to view and test. logger.debug("Final (with override) artifact is {}".format( sorted(artifact.items()))) self._descriptor['artifacts'] = list(image_artifacts.values()) module_overrides = self._image_overrides['modules'] image_modules = Image._to_dict(self.modules.install) for module in override.modules.install: name = module.name # collect override so we can apply it to modules. # this allows us to override module versions without affecting ordering. module_overrides[name] = module # Apply override to image descriptor # If the module does not exists in the original descriptor, add it there image_modules[name] = module self.modules._descriptor['install'] = list(image_modules.values()) if override.run != None: if self.run: self.run = override.run.merge(self.run) else: self.run = override.run