From 6b939c428fa8df73fe1d08157d922b9560baeb9f Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Aug 28 2023 22:10:27 +0000 Subject: Update Stabilization Phase Detection Signed-off-by: Troy Dawson --- diff --git a/src/centpkg/cli.py b/src/centpkg/cli.py index ad42cda..b571b8d 100755 --- a/src/centpkg/cli.py +++ b/src/centpkg/cli.py @@ -205,6 +205,7 @@ class centpkgClient(cliClient): divergent_branch = centpkg.utils.does_divergent_branch_exist( self.cmd.repo_name, rhel_version, + active_y, rhel_dist_git, pp_api_url, "rpms") diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index e17d0d3..e611fd1 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -286,17 +286,12 @@ def stream_mapping(csname): return "rhel-11" return None -def does_divergent_branch_exist(repo_name, rhel_version, rhel_dist_git, pp_api_url, namespace): +def does_divergent_branch_exist(repo_name, rhel_version, active_y, rhel_dist_git, pp_api_url, namespace): logger = logging.getLogger(__name__) # Determine if the Y-1 branch exists for this repo - # Look up the Y-1 branch name - divergent_branch = determine_divergent_branch( - rhel_version, - pp_api_url, - namespace, - ) + divergent_branch = active_y - 1 logger.debug("Divergent branch: {}".format(divergent_branch)) g = gitpython.cmd.Git() @@ -316,48 +311,6 @@ def does_divergent_branch_exist(repo_name, rhel_version, rhel_dist_git, pp_api_u raise return branch_exists -def determine_divergent_branch(rhel_version, pp_api_url, namespace): - logger = logging.getLogger(__name__) - - # Query the "package pages" API for the current active Y-stream release - # Phase 230 is "Planning / Development / Testing" (AKA DeveTestDoc) - request_params = { - "phase": 230, - "product__shortname": "rhel", - "relgroup__shortname": rhel_version, - "format": "json", - } - - res = requests.get( - os.path.join(pp_api_url, "latest", "releases"), - params=request_params, - timeout=60, - ) - res.raise_for_status() - payload = json.loads(res.text) - logger.debug( - "Response from PP API: {}".format(json.dumps(payload, indent=2)) - ) - if len(payload) < 1: - raise RuntimeError("Received zero potential release matches)") - - active_y_version = -1 - for entry in payload: - shortname = entry["shortname"] - - # The shortname is in the form rhel-9-1.0 - # Extract the active Y-stream version - m = re.search("(?<={}-)\d+(?=\.0)".format(rhel_version), shortname) - if not m: - raise RuntimeError( - "Could not determine active Y-stream version from shortname" - ) - y_version = int(m.group(0)) - if y_version > active_y_version: - active_y_version = y_version - - # The divergent branch is Y-1 - return "{}.{}.0".format(rhel_version, active_y_version - 1) def _datesplit(isodate): date_string_tuple = isodate.split('-') @@ -372,9 +325,10 @@ def determine_active_y_version(rhel_version, pp_api_url): logger = logging.getLogger(__name__) # Query the "package pages" API for the current active Y-stream release - # Phase 230 is "Planning / Development / Testing" (AKA DeveTestDoc) + # Phase 230 is "Planning / Development / Testing" (AKA DevTestDoc) + # Phase 450 is "Stabilization" request_params = { - "phase": 230, + "phase__in": "230,450", "product__shortname": "rhel", "relgroup__shortname": rhel_version, "format": "json", @@ -391,7 +345,7 @@ def determine_active_y_version(rhel_version, pp_api_url): "Response from PP API: {}".format(json.dumps(payload, indent=2)) ) if len(payload) < 1: - raise RuntimeError("Received zero potential release matches)") + raise RuntimeError("Received zero potential release matches") release_id = -1 active_y_version = -1 @@ -410,26 +364,7 @@ def determine_active_y_version(rhel_version, pp_api_url): active_y_version = y_version release_id = entry["id"] - # Now look up whether we are in the Exception Phase for this Y-stream release - request_params = { - "name__regex": "(Excep|Stabiliza)tion Phase", - "format": "json", - } - res = requests.get(os.path.join(pp_api_url, "latest", "releases", str(release_id), "schedule-tasks"), params=request_params) - res.raise_for_status() - payload = json.loads(res.text) - logger.debug( - "Response from phase lookup: {}".format(json.dumps(payload, indent=2)) - ) - - # This lookup *must* return exactly one value or the Product Pages are - # wrong and must be fixed. - assert len(payload) == 1 - - # Determine if this Y-stream release is in the exception phase - today = datetime.now(tz=pytz.utc).date() - exception_start_date = date(*_datesplit(payload[0]["date_start"])) - in_exception_phase = today >= exception_start_date + in_exception_phase = entry["phase"] == 450 logger.debug("Active Y-stream: {}, Enforcing: {}".format(active_y_version, in_exception_phase))