Skip to content

Commit

Permalink
Merge pull request #1139 from vfreex/refactor-batch-handling
Browse files Browse the repository at this point in the history
[ART-10837] Refactor batch handling and exclude microshift from batches
  • Loading branch information
vfreex authored Nov 22, 2024
2 parents b5adb9c + b79830a commit 8aeea02
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 101 deletions.
16 changes: 6 additions & 10 deletions artcommon/artcommonlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,19 @@ def is_future_release_date(date_str):

def get_assembly_release_date(assembly, group):
"""
Get assembly release release date from release schedule API
Get assembly release release date from release schedule API.
:raises ValueError: If the assembly release date is not found
"""
assembly_release_date = None
release_schedules = requests.get(f'{RELEASE_SCHEDULES}/{group}.z/?fields=all_ga_tasks', headers={'Accept': 'application/json'})

try:
for release in release_schedules.json()['all_ga_tasks']:
if assembly in release['name']:
# convert date format for advisory usage, 2024-02-13 -> 2024-Feb-13
assembly_release_date = datetime.strptime(release['date_start'], "%Y-%m-%d").strftime("%Y-%b-%d")
break
return assembly_release_date

return datetime.strptime(release['date_start'], "%Y-%m-%d").strftime("%Y-%b-%d")
except KeyError:
return None
pass
raise ValueError(f'Assembly release date not found for {assembly}')


def is_release_next_week(group):
Expand All @@ -162,8 +160,6 @@ def get_inflight(assembly, group):
"""
inflight_release = None
assembly_release_date = get_assembly_release_date(assembly, group)
if not assembly_release_date:
raise ValueError(f'Assembly release date not found for {assembly}')
major, minor = get_ocp_version_from_group(group)
release_schedules = requests.get(f'{RELEASE_SCHEDULES}/openshift-{major}.{minor-1}.z/?fields=all_ga_tasks', headers={'Accept': 'application/json'})
for release in release_schedules.json()['all_ga_tasks']:
Expand Down
8 changes: 4 additions & 4 deletions elliott/elliottlib/errata_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def create_batch(self, name: str, release_name: str, release_date: str, de
"is_active": is_active,
"is_locked": is_locked,
}
return await self._make_request(aiohttp.hdrs.METH_POST, path, json=data)
return cast(Dict, await self._make_request(aiohttp.hdrs.METH_POST, path, json=data)).get("data", {})

async def update_batch(self,
batch_id: int,
Expand All @@ -190,7 +190,7 @@ async def update_batch(self,
is_active: Optional[bool] = None,
is_locked: Optional[bool] = None):
""" Update an existing batch.
https://errata.devel.redhat.com/documentation/developer-guide/api-http-api.html
https://errata.devel.redhat.com/documentation/developer-guide/api-http-api.html#batches
:param batch_id: Batch ID
:param name: The batch name to update if not None
Expand All @@ -214,7 +214,7 @@ async def update_batch(self,
data["is_active"] = is_active
if is_locked is not None:
data["is_locked"] = is_locked
return await self._make_request(aiohttp.hdrs.METH_PUT, path, json=data)
return cast(Dict, await self._make_request(aiohttp.hdrs.METH_PUT, path, json=data)).get("data", {})

async def change_batch_for_advisory(self, advisory: int, batch_id: Optional[int] = None):
""" Change the batch association for an advisory.
Expand All @@ -228,7 +228,7 @@ async def change_batch_for_advisory(self, advisory: int, batch_id: Optional[int]
data["batch_id"] = batch_id
else:
data["clear_batch"] = True
return await self._make_request(aiohttp.hdrs.METH_POST, path, json=data)
return cast(Dict, await self._make_request(aiohttp.hdrs.METH_POST, path, json=data))

async def create_advisory(self, product: str, release: str, errata_type: str,
advisory_synopsis: str, advisory_topic: str, advisory_description: str, advisory_solution: str,
Expand Down
Loading

0 comments on commit 8aeea02

Please sign in to comment.