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

Commit

Permalink
Support patch_version defined in assembly config
Browse files Browse the repository at this point in the history
If we have assembly config like this:

```yaml
  art5142:
    assembly:
      type: custom
      basis:
        assembly: 4.12.99
        patch_version: 99
```

The release name will become `4.12.99-assembly.art5142`.

In case patch_version is not defined, let our automation to look at the chain of assembly inheritance to determine one, e.g.

```yaml
  art0000:
    assembly:
      type: custom
      basis:
        assembly: 4.12.88
  art0001:
    assembly:
      type: custom
      basis:
        assembly: art0000
  art0002:
    assembly:
      type: custom
      basis:
        assembly: art0001
```

The patch_version of art0002 will default to 88 because release 4.12.88 is the closest ancestor of type standard.
  • Loading branch information
vfreex committed Nov 9, 2022
1 parent 2200ba5 commit 1213091
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 12 deletions.
17 changes: 9 additions & 8 deletions doozerlib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import dateutil.parser

from dockerfile_parse import DockerfileParser
import doozerlib

from .pushd import Dir
from .distgit import ImageDistGitRepo, RPMDistGitRepo
from . import exectools
from . import logutil
from .brew import BuildStates
from .util import isolate_el_version_in_brew_tag, isolate_git_commit_in_release
from doozerlib.pushd import Dir
from doozerlib.distgit import ImageDistGitRepo, RPMDistGitRepo
from doozerlib import exectools, logutil
from doozerlib.brew import BuildStates
from doozerlib.util import isolate_el_version_in_brew_tag, isolate_git_commit_in_release

from .model import Model, Missing
from doozerlib.model import Model, Missing
from doozerlib.assembly import assembly_metadata_config, assembly_basis_event


Expand Down Expand Up @@ -80,7 +80,7 @@ def rebuild(self):


class Metadata(object):
def __init__(self, meta_type: str, runtime, data_obj: Dict, commitish: Optional[str] = None, prevent_cloning: Optional[bool] = False):
def __init__(self, meta_type: str, runtime: "doozerlib.Runtime", data_obj: Dict, commitish: Optional[str] = None, prevent_cloning: Optional[bool] = False):
"""
:param meta_type - a string. Index to the sub-class <'rpm'|'image'>.
:param runtime - a Runtime object.
Expand Down Expand Up @@ -169,6 +169,7 @@ def __init__(self, meta_type: str, runtime, data_obj: Dict, commitish: Optional[
pass
else:
# Ooof.. it is not defined in the assembly, so we need to find it dynamically.
self.logger.info("A commitish is not explicitly specified for %s. Determining from the latest build...", self.name)
build_obj = self.get_latest_build(default=None, el_target=self.determine_rhel_targets()[0])
if build_obj:
self.commitish = isolate_git_commit_in_release(build_obj['nvr'])
Expand Down
4 changes: 2 additions & 2 deletions doozerlib/rpmcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def _run_modifications(self, specfile: Optional[os.PathLike] = None, cwd: Option
"release_name": "",
}

if self.runtime.assembly_type in [AssemblyTypes.STANDARD, AssemblyTypes.CANDIDATE, AssemblyTypes.PREVIEW]:
context["release_name"] = util.get_release_name(self.runtime.assembly_type, self.runtime.group, self.runtime.assembly, None)
if self.runtime.assembly_type is not AssemblyTypes.STREAM:
context["release_name"] = util.get_release_name_for_assembly(self.runtime.group, self.runtime.get_releases_config(), self.runtime.assembly)

for modification in self.config.content.source.modifications:
if self.source_modifier_factory.supports(modification.action):
Expand Down
4 changes: 2 additions & 2 deletions doozerlib/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ def _get_replace_vars(self, group_config: Model):
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)
if self.assembly_type is not AssemblyTypes.STREAM:
replace_vars['release_name'] = util.get_release_name_for_assembly(self.group, self.get_releases_config(), self.assembly)
return replace_vars

def init_state(self):
Expand Down
24 changes: 24 additions & 0 deletions doozerlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import semver
import yaml

from doozerlib.model import Missing, Model

try:
from reprlib import repr
except ImportError:
Expand Down Expand Up @@ -819,3 +821,25 @@ def get_release_name(assembly_type: assembly.AssemblyTypes, group_name: str, ass
else:
raise ValueError(f"Assembly type {assembly_type} is not supported.")
return release_name


def get_release_name_for_assembly(group_name: str, releases_config: Model, assembly_name: str):
""" Get release name for an assembly.
"""
assembly_type = assembly.assembly_type(releases_config, assembly_name)
patch_version = assembly.assembly_basis(releases_config, assembly_name).get('patch_version')
if assembly_type is assembly.AssemblyTypes.CUSTOM:
patch_version = assembly.assembly_basis(releases_config, assembly_name).get('patch_version')
# If patch_version is not set, go through the chain of assembly inheritance and determine one
current_assembly = assembly_name
while patch_version is None:
parent_assembly = releases_config.releases[current_assembly].assembly.basis.assembly
if parent_assembly is Missing:
break
if assembly.assembly_type(releases_config, parent_assembly) is assembly.AssemblyTypes.STANDARD:
patch_version = int(parent_assembly.rsplit('.', 1)[-1])
break
current_assembly = parent_assembly
if patch_version is None:
raise ValueError("patch_version is not set in assembly definition and can't be auto-determined through the chain of inheritance.")
return get_release_name(assembly_type, group_name, assembly_name, patch_version)
80 changes: 80 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

from doozerlib import util
from doozerlib.model import Model


class TestUtil(unittest.TestCase):
Expand Down Expand Up @@ -163,6 +164,85 @@ def test_isolate_timestamp_in_release(self):
expected = None
self.assertEqual(actual, expected)

def test_get_release_name_for_assembly(self):
releases_config = Model({
"releases": {
"4.12.99": {
"assembly": {
"type": "standard",
"basis": {
"assembly": "4.12.98",
}
}
},
"4.12.98": {
"assembly": {
"type": "standard",
"basis": {
"event": 12345,
}
}
},
"art0000": {
"assembly": {
"type": "custom",
"basis": {
"assembly": "4.12.99",
}
}
},
"art0001": {
"assembly": {
"type": "custom",
"basis": {
"assembly": "art0000",
}
}
},
"art0002": {
"assembly": {
"type": "custom",
"basis": {
"assembly": "art0001",
"patch_version": 23,
}
}
},
"art0003": {
"assembly": {
"type": "custom",
"basis": {
"assembly": "art0002",
}
}
},
}
})

actual = util.get_release_name_for_assembly("openshift-4.12", releases_config, "4.12.99")
expected = "4.12.99"
self.assertEqual(actual, expected)

actual = util.get_release_name_for_assembly("openshift-4.12", releases_config, "4.12.98")
expected = "4.12.98"
self.assertEqual(actual, expected)

actual = util.get_release_name_for_assembly("openshift-4.12", releases_config, "art0000")
expected = "4.12.99-assembly.art0000"
self.assertEqual(actual, expected)

actual = util.get_release_name_for_assembly("openshift-4.12", releases_config, "art0001")
expected = "4.12.99-assembly.art0001"
self.assertEqual(actual, expected)

actual = util.get_release_name_for_assembly("openshift-4.12", releases_config, "art0002")
expected = "4.12.23-assembly.art0002"
self.assertEqual(actual, expected)

actual = util.get_release_name_for_assembly("openshift-4.12", releases_config, "art0003")
expected = "4.12.23-assembly.art0003"
self.assertEqual(actual, expected)


if __name__ == "__main__":
unittest.main()

0 comments on commit 1213091

Please sign in to comment.