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

Commit

Permalink
ART-6621 Try to reuse advisories for candidate assembly (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegreyd authored Apr 18, 2023
1 parent 0ec0a0f commit f4e5a90
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
40 changes: 31 additions & 9 deletions doozerlib/cli/release_gen_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,36 @@ def _calculate_previous_list(self):
final_previous_list |= set(map(VersionInfo.parse, previous_list))
self.final_previous_list = sorted(final_previous_list)

def _get_advisories_release_jira(self) -> Tuple[Dict[str, int], str]:
# Add placeholder advisory numbers and JIRA key.
# Those values will be replaced with real values by pyartcd when preparing a release.
advisories = {
'image': -1,
'rpm': -1,
'extras': -1,
'metadata': -1,
}
release_jira = "ART-0"

if self.assembly_type == AssemblyTypes.CANDIDATE:
# if this assembly is rc.X, then check if there is a previously defined rc.X-1
# pick advisories and release ticket from there
split = re.split(r'(\d+)', self.gen_assembly_name)
# ['rc.', '2', '']
current_v = int(split[1])
if current_v != 0:
previous_assembly = f"{split[0]}{current_v - 1}"
releases_config = self.runtime.get_releases_config()
if previous_assembly in releases_config.releases:
previous_group = releases_config.releases[previous_assembly].assembly.group
advisories = previous_group.advisories
release_jira = previous_group.release_jira
self.logger.info(f"Reusing advisories and release ticket from previous candidate assembly {previous_assembly}, {previous_group.advisories}, {previous_group.release_jira}")
else:
self.logger.info("No matching previous candidate assembly found")

return advisories, release_jira

def _generate_assembly_definition(self) -> dict:
image_member_overrides, rpm_member_overrides = self._get_member_overrides()

Expand All @@ -480,15 +510,7 @@ def _generate_assembly_definition(self) -> dict:
}

if self.assembly_type not in [AssemblyTypes.CUSTOM, AssemblyTypes.PREVIEW]:
# Add placeholder advisory numbers and JIRA key.
# Those values will be replaced with real values by pyartcd when preparing a release.
group_info['advisories'] = {
'image': -1,
'rpm': -1,
'extras': -1,
'metadata': -1,
}
group_info["release_jira"] = "ART-0"
group_info['advisories'], group_info["release_jira"] = self._get_advisories_release_jira()

if self.final_previous_list:
group_info['upgrades'] = ','.join(map(str, self.final_previous_list))
Expand Down
26 changes: 26 additions & 0 deletions tests/cli/test_gen_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from doozerlib.assembly import AssemblyTypes
from doozerlib.cli.release_gen_assembly import GenAssemblyCli
from doozerlib.model import Model


class TestGenPayloadCli(TestCase):
Expand Down Expand Up @@ -268,3 +269,28 @@ def test_multi_standard_arch(self):
)
with self.assertRaises(ValueError):
gacli._get_release_pullspecs()

def test_get_advisories_release_jira_default(self):
runtime = MagicMock()
gacli = GenAssemblyCli(runtime=runtime, gen_assembly_name='4.11.2')
advisories, release_jira = gacli._get_advisories_release_jira()
self.assertEqual(advisories, {
'image': -1,
'rpm': -1,
'extras': -1,
'metadata': -1,
})
self.assertEqual(release_jira, "ART-0")

def test_get_advisories_release_jira_candidate_reuse(self):
runtime = MagicMock()
advisories = {'image': 123, 'rpm': 456, 'extras': 789, 'metadata': 654}
release_jira = "ART-123"
runtime.get_releases_config.return_value = Model({'releases': {'rc.0': {'assembly': {'group': {
'advisories': advisories,
'release_jira': release_jira
}}}}})
gacli = GenAssemblyCli(runtime=runtime, gen_assembly_name='rc.1')
actual = gacli._get_advisories_release_jira()
self.assertEqual(advisories, actual[0])
self.assertEqual(release_jira, actual[1])

0 comments on commit f4e5a90

Please sign in to comment.