Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Define release_name when initing Runtime
Browse files Browse the repository at this point in the history
This will avoid template key not defined error to allow to rebasing
microshift against nightlies.

This also refactors a little bit to reduce duplicate code.
  • Loading branch information
vfreex committed Nov 7, 2022
1 parent 3e4bbfd commit 4be71ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions doozerlib/rpmcfg.py
Expand Up @@ -113,6 +113,7 @@ def _run_modifications(self, specfile: Optional[os.PathLike] = None, cwd: Option
"content": new_specfile_data,
"set_env": {"PATH": path},
"runtime_assembly": self.runtime.assembly,
"release_name": "",
}

if self.runtime.assembly_type in [AssemblyTypes.STANDARD, AssemblyTypes.CANDIDATE, AssemblyTypes.PREVIEW]:
Expand Down
45 changes: 23 additions & 22 deletions doozerlib/runtime.py
Expand Up @@ -292,19 +292,28 @@ def get_group_config(self) -> Model:
# into the YAML content. If `vars` found, the format will be
# preformed and the YAML model will reloaded from that result
tmp_config = Model(self.gitdata.load_data(key='group').data)
replace_vars = tmp_config.vars or Model()
if self.assembly:
replace_vars['runtime_assembly'] = self.assembly
if replace_vars is not Missing:
try:
group_yml = yaml.safe_dump(tmp_config.primitive(), default_flow_style=False)
self.raw_group_config = yaml.full_load(group_yml.format(**replace_vars))
tmp_config = Model(dict(self.raw_group_config))
except KeyError as e:
raise ValueError('group.yml contains template key `{}` but no value was provided'.format(e.args[0]))
replace_vars = self._get_replace_vars(tmp_config)
try:
group_yml = yaml.safe_dump(tmp_config.primitive(), default_flow_style=False)
raw_group_config = yaml.full_load(group_yml.format(**replace_vars))
tmp_config = Model(dict(raw_group_config))
except KeyError as e:
raise ValueError('group.yml contains template key `{}` but no value was provided'.format(e.args[0]))

return assembly_group_config(self.get_releases_config(), self.assembly, tmp_config)

def _get_replace_vars(self, group_config: Model):
replace_vars = group_config.vars or Model()
# If assembly mode is enabled, `runtime_assembly` will become the assembly name.
replace_vars['runtime_assembly'] = ''
# If running against an assembly for a named release, release_name will become the release name.
replace_vars['release_name'] = ''
if self.assembly:
replace_vars['runtime_assembly'] = self.assembly
if self.assembly_type not in [AssemblyTypes.STREAM, AssemblyTypes.CUSTOM]:
replace_vars['release_name'] = util.get_release_name(self.assembly_type, self.group, self.assembly, release_offset=None)
return replace_vars

def init_state(self):
self.state = dict(state.TEMPLATE_BASE_STATE)
if os.path.isfile(self.state_file):
Expand Down Expand Up @@ -434,7 +443,8 @@ def initialize(self, mode='images', clone_distgits=True,
if self.cache_dir:
self.cache_dir = os.path.abspath(self.cache_dir)

self.get_releases_config() # Init self.releases_config
# get_releases_config also inits self.releases_config
self.assembly_type = assembly_type(self.get_releases_config(), self.assembly)

self.group_dir = self.gitdata.data_dir
self.group_config = self.get_group_config()
Expand All @@ -449,11 +459,7 @@ def initialize(self, mode='images', clone_distgits=True,
# ignore this argument throughout doozer.
self.assembly = None

replace_vars = {}
if self.group_config.vars:
replace_vars = self.group_config.vars.primitive()
if self.assembly:
replace_vars['runtime_assembly'] = self.assembly
replace_vars = self._get_replace_vars(self.group_config).primitive()

# only initialize group and assembly configs and nothing else
if config_only:
Expand All @@ -473,7 +479,6 @@ def initialize(self, mode='images', clone_distgits=True,
self.brew_event = self.assembly_basis_event
self.logger.warning(f'Constraining brew event to assembly basis for {self.assembly}: {self.brew_event}')

self.assembly_type = assembly_type(self.get_releases_config(), self.assembly)
# This flag indicates builds should be tagged with associated hotfix tag for the artifacts branch
self.hotfix = self.assembly_type is not AssemblyTypes.STREAM

Expand Down Expand Up @@ -1044,11 +1049,7 @@ def late_resolve_image(self, distgit_name, add=False):
if distgit_name in self.image_map:
return self.image_map[distgit_name]

replace_vars = {}
if self.group_config.vars:
replace_vars = self.group_config.vars.primitive()
if self.assembly:
replace_vars['runtime_assembly'] = self.assembly
replace_vars = self._get_replace_vars(self.group_config).primitive()
data_obj = self.gitdata.load_data(path='images', key=distgit_name, replace_vars=replace_vars)
if not data_obj:
raise DoozerFatalError('Unable to resolve image metadata for {}'.format(distgit_name))
Expand Down
2 changes: 1 addition & 1 deletion doozerlib/util.py
Expand Up @@ -800,7 +800,7 @@ def isolate_major_minor_in_group(group_name: str) -> Tuple[int, int]:
return int(match[1]), int(match[2])


def get_release_name(assembly_type: str, group_name: str, assembly_name: str, release_offset: Optional[int]):
def get_release_name(assembly_type: assembly.AssemblyTypes, group_name: str, assembly_name: str, release_offset: Optional[int]):
major, minor = isolate_major_minor_in_group(group_name)
if major is None or minor is None:
raise ValueError(f"Invalid group name: {group_name}")
Expand Down

0 comments on commit 4be71ce

Please sign in to comment.