Skip to content

Commit

Permalink
Introduce Erratum.blocking_builds attribute
Browse files Browse the repository at this point in the history
Adds and populates Erratum.blocking_builds attribute with
builds from blocking advisories.
  • Loading branch information
kkaarreell committed Aug 26, 2024
1 parent 0e41611 commit b279d32
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 29 additions & 1 deletion newa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess
import time
import urllib
from functools import reduce

try:
from attrs import asdict, define, evolve, field, frozen, validators
Expand Down Expand Up @@ -453,7 +454,14 @@ def fetch_releases(self, erratum_id: str) -> JSON:
krb=True,
response_content=ResponseContentType.JSON)

def get_errata(self, event: Event) -> list[Erratum]:
def fetch_blocking_errata(self, erratum_id: str) -> JSON:
return get_request(
url=f"{self.url}/errata/blocking_errata_for/{Q(erratum_id)}.json",
# not using krb=True due to an authentization error/bug, we did auth already
# krb=True,
response_content=ResponseContentType.JSON)

def get_errata(self, event: Event, process_blocking_errata: bool = True) -> list[Erratum]:
"""
Creates a list of Erratum instances based on given errata ID
Expand Down Expand Up @@ -489,11 +497,16 @@ def get_errata(self, event: Event) -> list[Erratum]:
# ]
# }

blocking_errata = []
if process_blocking_errata:
blocking_errata = self.get_blocking_errata(event.id)

info_json = self.fetch_info(event.id)
releases_json = self.fetch_releases(event.id)
for release in releases_json:
builds = []
builds_json = releases_json[release]
blocking_builds = []
archs = set()
for item in builds_json:
for (build, channels) in item.items():
Expand All @@ -510,6 +523,11 @@ def get_errata(self, event: Event) -> list[Erratum]:
else:
components = [NVRParser(build).name for build in builds]

if blocking_errata:
for e in blocking_errata:
if release == e.release:
blocking_builds.extend(e.builds)

errata.append(
Erratum(
id=event.id,
Expand All @@ -520,6 +538,7 @@ def get_errata(self, event: Event) -> list[Erratum]:
people_assigned_to=info_json["people"]["assigned_to"],
release=release,
builds=builds,
blocking_builds=blocking_builds,
archs=Arch.architectures(list(archs)),
components=components,
url=f"{self.url}/advisory/{event.id}"))
Expand All @@ -528,6 +547,14 @@ def get_errata(self, event: Event) -> list[Erratum]:

return errata

def get_blocking_errata(self, erratum_id: str) -> list[Erratum]:
blockers = list(self.fetch_blocking_errata(erratum_id).keys())
errata = [self.get_errata(Event(type_=EventType.ERRATUM, id=e),
process_blocking_errata=False) for e in blockers]
if errata:
return reduce(lambda l1, l2: l1 + l2, errata)
return []


@define
class InitialErratum(Serializable):
Expand Down Expand Up @@ -580,6 +607,7 @@ class Erratum(Cloneable, Serializable): # type: ignore[no-untyped-def]
url: str = field()
archs: list[Arch] = field(factory=list)
builds: list[str] = field(factory=list)
blocking_builds: list[str] = field(factory=list)
components: list[str] = field(factory=list)


Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@ def mock_et_fetch_releases(self, id: str):
],
}

def mock_et_fetch_blocking_errata(self, id: str):
""" Return empty json for blocking errata """
return {}

# TODO in the future we might want to do more complex patching of the class
# methods, but this will suffice for now
monkeypatch.setenv("NEWA_ET_URL", "https://fake.erratatool.com")
# We want to make sure we don't make requests to errata tool
monkeypatch.setattr(newa, 'get_request', mock_get_request)
monkeypatch.setattr(newa.ErrataTool, 'fetch_info', mock_et_fetch_info)
monkeypatch.setattr(newa.ErrataTool, 'fetch_releases', mock_et_fetch_releases)
monkeypatch.setattr(newa.ErrataTool, 'fetch_blocking_errata', mock_et_fetch_blocking_errata)


# TODO There's still not much logic to test in cli. These test is just a stub to
Expand Down

0 comments on commit b279d32

Please sign in to comment.