Skip to content

Commit

Permalink
make in fight not required
Browse files Browse the repository at this point in the history
  • Loading branch information
Ximinhan committed Jan 16, 2024
1 parent 9331f7a commit 587472e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
1 change: 1 addition & 0 deletions artcommon/artcommonlib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
RHCOS_RELEASES_BASE_URL = "https://releases-rhcos-art.apps.ocp-virt.prod.psi.redhat.com/storage/releases"
BREW_HUB = "https://brewhub.engineering.redhat.com/brewhub"
BREW_DOWNLOAD_URL = "https://download.eng.bos.redhat.com/brewroot"
RELEASE_SCHEDULES = "https://pp.engineering.redhat.com/api/v7/releases"
56 changes: 56 additions & 0 deletions artcommon/artcommonlib/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import OrderedDict
from datetime import datetime
from artcommonlib.constants import RELEASE_SCHEDULES
import requests
import re


def remove_prefix(s: str, prefix: str) -> str:
Expand Down Expand Up @@ -82,3 +86,55 @@ def merge_objects(a, b):
# move new entry to the beginning
c.move_to_end(k, last=False)
return c


def is_future_release_date(date_str):
"""
If the input date is in future then return True elase False
"""
try:
target_date = datetime.strptime(date_str, "%Y-%m-%d")
except ValueError:
return False
current_date = datetime.now()
if target_date > current_date:
return True
else:
return False


def get_assembly_release_date(assembly, group):
"""
Get assembly release release date from release schedule API
"""
release_schedules = requests.get(f'{RELEASE_SCHEDULES}/{group}.z/?fields=all_ga_tasks', headers={'Accept': 'application/json'})
for release in release_schedules.json()['all_ga_tasks']:
if assembly in release['name']:
assembly_release_data = release['date_start']
break
return assembly_release_data


def get_infight(assembly, group):
"""
Get infight release name from current assembly release
"""
infight_release = None
assembly_release_date = get_assembly_release_date(assembly, group)
match = re.fullmatch(r"openshift-(\d+).(\d+)", group)
if not match:
raise ValueError(f"Invalid group name: {group}")
previous_release = f"openshift-{int(match[1])}.{int(match[2])-1}"
release_schedules = requests.get(f'{RELEASE_SCHEDULES}/{previous_release}.z/?fields=all_ga_tasks', headers={'Accept': 'application/json'})
for release in release_schedules.json()['all_ga_tasks']:
is_future = is_future_release_date(release['date_start'])
if is_future:
days_diff = abs((datetime.strptime(assembly_release_date, "%Y-%m-%d") - datetime.strptime(release['date_start'], "%Y-%m-%d")).days)
if days_diff <= 5: # if next Y-1 release and assembly release in the same week
match = re.search(r'\d+\.\d+\.\d+', release['name'])
if match:
infight_release = match.group()
break
else:
raise ValueError(f"Didn't find in_fight release in {release['name']}")
return infight_release
4 changes: 2 additions & 2 deletions pyartcd/pyartcd/pipelines/gen_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import click
from ghapi.all import GhApi

from artcommonlib.util import split_git_url, merge_objects
from artcommonlib.util import split_git_url, merge_objects, get_infight
from pyartcd import exectools, constants, jenkins
from pyartcd.cli import cli, click_coroutine, pass_runtime
from pyartcd.git import GitRepository
Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(self, runtime: Runtime, group: str, assembly: str, data_path: str,
self.auto_trigger_build_sync = auto_trigger_build_sync
self.custom = custom
self.arches = arches
self.in_flight = in_flight
self.in_flight = in_flight if in_flight else get_infight(assembly, group)
self.previous_list = previous_list
self.auto_previous = auto_previous
self.prerelease = prerelease
Expand Down
5 changes: 3 additions & 2 deletions pyartcd/pyartcd/pipelines/prepare_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ruamel.yaml import YAML
from tenacity import retry, stop_after_attempt, wait_fixed

from artcommonlib.util import get_assembly_release_date
from doozerlib.assembly import AssemblyTypes
from elliottlib.assembly import assembly_group_config
from elliottlib.errata import set_blocking_advisory, get_blocking_advisories
Expand Down Expand Up @@ -85,7 +86,7 @@ def __init__(
if default_advisories:
raise ValueError("default_advisories cannot be set for a non-stream assembly.")

self.release_date = date
self.release_date = date if date else get_assembly_release_date(assembly, group)
self.package_owner = package_owner or self.runtime.config["advisory"]["package_owner"]
self._slack_client = slack_client
self.working_dir = self.runtime.working_dir.absolute()
Expand Down Expand Up @@ -711,7 +712,7 @@ async def verify_attached_operators(self, *advisories: List[int], gather_depende
help="The name of an assembly to rebase & build for. e.g. 4.9.1")
@click.option("--name", metavar="RELEASE_NAME",
help="release name (e.g. 4.6.42)")
@click.option("--date", metavar="YYYY-MMM-DD", required=True,
@click.option("--date", metavar="YYYY-MMM-DD",
help="Expected release date (e.g. 2020-11-25)")
@click.option("--package-owner", metavar='EMAIL',
help="Advisory package owner; Must be an individual email address; May be anyone who wants random advisory spam")
Expand Down
6 changes: 3 additions & 3 deletions pyartcd/tests/pipelines/test_gen_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_get_nightlies(self, cmd_gather_async: AsyncMock):
runtime = MagicMock()
pipeline = GenAssemblyPipeline(runtime, "openshift-4.12", "4.12.99", "https://example.com/ocp-build-data.git",
nightlies=(), allow_pending=False, allow_rejected=False,
allow_inconsistency=False, custom=False, arches=(), in_flight=None,
allow_inconsistency=False, custom=False, arches=(), in_flight="4.11.88",
previous_list=(), auto_previous=True, auto_trigger_build_sync=False)
actual = asyncio.run(pipeline._get_nightlies())
self.assertEqual(actual, ["a", "b", "c"])
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_create_or_update_pull_request(self, git_repo: MagicMock, yaml: MagicMoc
}})
pipeline = GenAssemblyPipeline(runtime, "openshift-4.12", "4.12.99", "https://example.com/ocp-build-data.git",
nightlies=(), allow_pending=False, allow_rejected=False,
allow_inconsistency=False, custom=False, arches=(), in_flight=None,
allow_inconsistency=False, custom=False, arches=(), in_flight="4.11.88",
previous_list=(), auto_previous=True, auto_trigger_build_sync=False)
pipeline._working_dir = Path("/path/to/working")
yaml.load.return_value = OrderedDict([
Expand Down Expand Up @@ -144,7 +144,7 @@ async def test_run(self, get_nightlies: AsyncMock, _gen_assembly_from_releases:

pipeline = GenAssemblyPipeline(runtime, "openshift-4.12", "4.12.99", "https://example.com/ocp-build-data.git",
nightlies=(), allow_pending=False, allow_rejected=False,
allow_inconsistency=False, custom=False, arches=(), in_flight=None,
allow_inconsistency=False, custom=False, arches=(), in_flight="4.11.88",
previous_list=(), auto_previous=True, auto_trigger_build_sync=False)
pipeline._working_dir = Path("/path/to/working")
get_nightlies.return_value = ["nightly1", "nightly2", "nightly3", "nightly4"]
Expand Down

0 comments on commit 587472e

Please sign in to comment.