-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support get a product's release' all tasks from Product Pages
Created an client to connect to PP for release api Updated README on some command and links Updated Docker and CI files with krb5 install to avoid ci failure Rename customize logging class, otherwise it confused with internal logging class Adding Tests to test coverage 100% JIRA: RHELWF-10975
- Loading branch information
1 parent
21303e6
commit 9f402d5
Showing
14 changed files
with
742 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/.mypy_cache | ||
/.ruff_cache | ||
/.tox | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
""" | ||
Production Pages API | ||
""" | ||
|
||
from functools import cache | ||
from retasc import requests_session | ||
|
||
class ProductPagesApi: | ||
""" | ||
Product Pages API Client | ||
""" | ||
def __init__(self, api_url: str): | ||
self.api_url = api_url | ||
self.session = requests_session.requests_session() | ||
|
||
def api_url_releases(self, id: int | None = None) -> str: | ||
return f"{self.api_url.rstrip('/')}/releases/{id or ''}" | ||
|
||
@cache | ||
def releases_by_product_phase( | ||
self, | ||
product_shortname: str, | ||
active_only: bool = True, | ||
fields: str = "shortname,product_shortname,ga_date,phase_display", | ||
) -> list[dict]: | ||
""" | ||
https://{pp_release_url}?product__shortname={product_shortname}&phase__lt=Unsupported&fields=a,b,c | ||
The response have the following fields:shortname,product_shortname,ga_date,phase_display | ||
phase__lt=Unsupported means "any supported phase" (these are less than Unsupported). | ||
""" | ||
Unsupported_phase_id = 1000 | ||
|
||
opt = { | ||
"product__shortname": product_shortname, | ||
"fields": fields, | ||
} | ||
if active_only is True: | ||
opt.update({"phase__lt": Unsupported_phase_id}) | ||
res = self.session.get(self.api_url_releases(), params=opt) | ||
res.raise_for_status() | ||
return res.json() | ||
|
||
@cache | ||
def release_schedules( | ||
self, | ||
release_short_name: str, | ||
fields: str = "name,date_start,date_finish,flags", | ||
) -> list[dict]: | ||
""" | ||
https://{pp_release_url}{release_short_name}/schedule-tasks?fields=a,b,c | ||
The response have the following fields:name,,date_start,date_finish,flags | ||
""" | ||
|
||
res = self.session.get( | ||
f"{self.api_url_releases()}{release_short_name}/schedule-tasks", | ||
params={ | ||
"fields": fields, | ||
}, | ||
) | ||
res.raise_for_status() | ||
return res.json() | ||
|
||
@cache | ||
def release_schedules_by_flags( | ||
self, | ||
release_short_name: str, | ||
flag_cond: str = "flags_or__in", | ||
flags: str = "rcm,releng,exd,sp", | ||
fields: str = "release_shortname,name,date_start,date_finish", | ||
) -> list[dict]: | ||
""" | ||
https://{pp_release_url}{release_short_name}/schedule-tasks/?{flag_cond}={flags}&fields=a,b,c | ||
Only one flag in condition use `flags_in=sp` | ||
Multiple flags in OR condition use `flags_or__in=sp,rcm,releng` | ||
Multiple flags in AND condition use `flags_and__in=sp,ga` | ||
The response have the following fields:release_shortname,name,slug,date_start,date_finish | ||
""" | ||
|
||
res = self.session.get( | ||
f"{self.api_url_releases()}{release_short_name}/schedule-tasks", | ||
params={ | ||
flag_cond: flags, | ||
"fields": fields, | ||
}, | ||
) | ||
res.raise_for_status() | ||
return res.json() | ||
|
||
@cache | ||
def release_schedules_by_name_search( | ||
self, | ||
release_short_name: str, | ||
condition: str, | ||
fields: str = "release_shortname,name,slug,date_start,date_finish", | ||
) -> list[dict]: | ||
""" | ||
https://{pp_release_url}{release_short_name}/schedule-tasks?name__regex={condition}&fields=a,b,c | ||
The response have the following fields:release_shortname,name,slug,date_start,date_finish | ||
""" | ||
|
||
res = self.session.get( | ||
f"{self.api_url_releases()}{release_short_name}/schedule-tasks", | ||
params={ | ||
"name__regex": condition, | ||
"fields": fields, | ||
}, | ||
) | ||
res.raise_for_status() | ||
return res.json() | ||
|
||
@cache | ||
def get_all_active_releases_tasks_for_product(self, product_shortname: str) -> dict: | ||
""" | ||
Get all release names that are still supported by rest api: | ||
https://{pp_release_url}?product__shortname={product_shortname}&phase__lt=Unsupported&fields=shortname | ||
Loop through the releases and get the tasks of it by rest api | ||
https://{pp_release_url}{release_short_name}/schedule-tasks/fields=name,slug,date_start,date_finish | ||
""" | ||
|
||
releases_list = self.releases_by_product_phase(product_shortname) | ||
all_tasks: dict = {} | ||
all_tasks[product_shortname] = {} | ||
for r in releases_list: | ||
r_name = r["shortname"] | ||
r_tasks = self.release_schedules(r_name) | ||
all_tasks[product_shortname][r_name] = r_tasks | ||
return all_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
""" | ||
Http Request client with retry and kerberos capabilities | ||
""" | ||
|
||
import requests | ||
from requests.adapters import HTTPAdapter | ||
from urllib3.util.retry import Retry | ||
|
||
|
||
def requests_session(): | ||
"""Returns https session for request processing.""" | ||
|
||
session = requests.Session() | ||
retry = Retry( | ||
total=3, | ||
read=3, | ||
connect=3, | ||
backoff_factor=1, | ||
status_forcelist=(500, 502, 503, 504), | ||
allowed_methods=Retry.DEFAULT_ALLOWED_METHODS.union(("POST",)), | ||
) | ||
adapter = HTTPAdapter(max_retries=retry) | ||
session.mount("https://", adapter) | ||
session.headers["User-Agent"] = "sp-retasc-agent" | ||
session.headers["Content-type"] = "application/json" | ||
return session |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.