Skip to content

Commit

Permalink
directly call gen-assembly and use new api get latest nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Ximinhan committed Oct 30, 2024
1 parent 2623981 commit c664d96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 55 deletions.
3 changes: 3 additions & 0 deletions pyartcd/pyartcd/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@
}

GITHUB_OWNER = "openshift-eng"
UPGRADE_GRAPH_URL = "https://api.openshift.com/api/upgrades_info/v1/graph"
BUILD_SUGGESTIONS_URL = "https://raw.githubusercontent.com/openshift/cincinnati-graph-data/master/build-suggestions/"
RC_AMD64_URL = "https://amd64.ocp.releases.ci.openshift.org/api/v1/releasestream"
77 changes: 22 additions & 55 deletions pyartcd/pyartcd/pipelines/gen_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from artcommonlib.util import split_git_url, merge_objects, get_inflight, isolate_major_minor_in_group
from artcommonlib import exectools
from doozerlib.cli.get_nightlies import rc_api_url
from doozerlib.cli.release_gen_assembly import GenAssemblyCli
from pyartcd import constants, jenkins
from pyartcd.cli import cli, click_coroutine, pass_runtime
from pyartcd.git import GitRepository
Expand Down Expand Up @@ -107,10 +108,22 @@ async def run(self):
*[self._get_nightlies(), self._get_latest_accepted_nightly()])

self._logger.info("Generating assembly definition...")
assembly_definition = await self._gen_assembly_from_releases(candidate_nightlies)
out = StringIO()
yaml.dump(assembly_definition, out)
self._logger.info("Generated assembly definition:\n%s", out.getvalue())
assembly_definition = await GenAssemblyCli(
runtime=self.runtime,
gen_assembly_name=self.assembly,
nightlies=candidate_nightlies,
standards=[],
custom=self.custom,
pre_ga_mode=self.pre_ga_mode,
in_flight=self.in_flight,
previous_list=self.previous_list,
auto_previous=self.auto_previous,
graph_url=constants.UPGRADE_GRAPH_URL,
graph_content_stable=None,
graph_content_candidate=None,
suggestions_url=constants.BUILD_SUGGESTIONS_URL,
).run()
self._logger.info("Generated assembly definition:\n%s", assembly_definition)

# Create a PR
pr = await self._create_or_update_pull_request(assembly_definition)
Expand All @@ -134,25 +147,12 @@ async def run(self):

async def _get_latest_accepted_nightly(self):
self._logger.info('Retrieving most recent accepted amd64 nightly...')

major, minor = isolate_major_minor_in_group(self.group)
tag_base = f'{major}.{minor}.0-0.nightly'
rc_endpoint = f"{rc_api_url(tag_base, 'amd64', self.private_nightlies)}/tags"

async with aiohttp.ClientSession() as session:
async with session.get(rc_endpoint) as response:
if response.status != 200:
self._logger.warning('Failed retrieving latest accepted nighly from %s', rc_endpoint)
return None

tags = (await response.json()).get('tags', [])
accepted_nightlies = list(filter(lambda tag: tag['phase'] == 'Accepted', tags))

if accepted_nightlies:
return accepted_nightlies[0]['name']
else:
self._logger.warning('No accepted nightly found')
return None
latest_accepted_nightly = requests.get(f"{constants.RC_AMD64_URL}/{major}.{minor}.0-0.nightly/latest")
if latest_accepted_nightly.status_code != 200:
self._logger.warning('Failed retrieving latest accepted nighly from %s', latest_accepted_nightly.url)
return None
return latest_accepted_nightly.json()['name']

async def _get_nightlies(self):
"""
Expand Down Expand Up @@ -183,39 +183,6 @@ async def _get_nightlies(self):
_, out, _ = await exectools.cmd_gather_async(cmd, stderr=None, env=self._doozer_env_vars)
return out.strip().split()

async def _gen_assembly_from_releases(self, candidate_nightlies: Iterable[str]) -> OrderedDict:
""" Run doozer release:gen-assembly from-releases
:return: Assembly definition
"""

cmd = [
"doozer",
"--group", self.group,
"--assembly", "stream",
]
if self.arches:
cmd.append("--arches")
cmd.append(",".join(self.arches))
cmd.append("release:gen-assembly")
cmd.append(f"--name={self.assembly}")
cmd.append("from-releases")
for nightly in candidate_nightlies:
cmd.append(f"--nightly={nightly}")

if self.pre_ga_mode:
cmd.append(f"--pre-ga-mode={self.pre_ga_mode}")

if self.custom:
cmd.append("--custom")
else:
if self.in_flight:
cmd.append(f"--in-flight={self.in_flight}")
for previous in self.previous_list:
cmd.append(f"--previous={previous}")
if self.auto_previous:
cmd.append("--auto-previous")
_, out, _ = await exectools.cmd_gather_async(cmd, stderr=None, env=self._doozer_env_vars)
return yaml.load(out)

async def _create_or_update_pull_request(self, assembly_definition: OrderedDict):
"""
Expand Down

0 comments on commit c664d96

Please sign in to comment.