Skip to content
Snippets Groups Projects
Commit 0a4460e2 authored by Ben Morrice's avatar Ben Morrice
Browse files

Add almalinux support

parent 4d696f0b
No related branches found
No related tags found
1 merge request!10Add almalinux support
SCHEDULE="0 8 * * *" SCHEDULE="0 8 * * *"
DB_MOUNTPOINT="/mnt/data2/test/package_alerts" DB_MOUNTPOINT="/mnt/data2/test/package_alerts"
INTERESTING_PACKAGES="dev.packages.yml" INTERESTING_PACKAGES="dev.packages.yml"
FEEDS="rhel-8-for-x86_64-baseos-rpms,rhel-8-for-x86_64-appstream-rpms,rhel-9-for-x86_64-baseos-rpms,rhel-9-for-x86_64-appstream-rpms" FEEDS="rhel-8-for-x86_64-baseos-rpms,rhel-8-for-x86_64-appstream-rpms,rhel-9-for-x86_64-baseos-rpms,rhel-9-for-x86_64-appstream-rpms,almalinux-8-for-x86_64-AppStream-rpms,almalinux-8-for-x86_64-BaseOS-rpms,almalinux-9-for-x86_64-AppStream-rpms,almalinux-9-for-x86_64-BaseOS-rpms"
MATTERMOST_INTEGRATION_URL="https://mattermost.web.cern.ch/hooks/cy45ecb3kpgwbm88smkn4fa43h" MATTERMOST_INTEGRATION_URL="https://mattermost.web.cern.ch/hooks/cy45ecb3kpgwbm88smkn4fa43h"
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
# and no notes will be included in the MM message. # and no notes will be included in the MM message.
--- ---
packages: packages:
almalinux-release:
notes: |-
**MANUAL ACTION REQUIRED**: This is a "dangerous package" and it will need to be [rebuilt by hand](https://linuxops.web.cern.ch/distributions/snapshots/#-release-packages-the-dangerous-rpms). If you don't do it **today**, the daily snapshot will stop tomorrow and you'll have more work to do then.
redhat-release: redhat-release:
notes: |- notes: |-
**MANUAL ACTION REQUIRED**: This is a "dangerous package" and it will need to be [rebuilt by hand](https://linuxops.web.cern.ch/distributions/snapshots/#-release-packages-the-dangerous-rpms). If you don't do it **today**, the daily snapshot will stop tomorrow and you'll have more work to do then. **MANUAL ACTION REQUIRED**: This is a "dangerous package" and it will need to be [rebuilt by hand](https://linuxops.web.cern.ch/distributions/snapshots/#-release-packages-the-dangerous-rpms). If you don't do it **today**, the daily snapshot will stop tomorrow and you'll have more work to do then.
......
...@@ -82,19 +82,23 @@ def do_execute(cmd, tdir="/tmp", return_output=False, return_error=False): ...@@ -82,19 +82,23 @@ def do_execute(cmd, tdir="/tmp", return_output=False, return_error=False):
return True return True
def get_changelog(token, checksum): def get_changelog(token, payload):
"""get the changelog for a rpm, which requires downloading it""" """get the changelog for a rpm, which requires downloading it"""
# Almalinux
if token is None:
url = payload
else:
url = f"https://api.access.redhat.com/management/v1/packages/{payload}/download"
# We don't usually retry stuff from api calls as the script runs # We don't usually retry stuff from api calls as the script runs
# frequently, however - in this case a failure results in a blank # frequently, however - in this case a failure results in a blank
# changelog which is not very useful # changelog which is not very useful
attempts = 0 attempts = 0
max_attempts = 3 max_attempts = 3
rpm_downloaded = False rpm_downloaded = False
temp_file = generate_temp_file("checksum") temp_file = generate_temp_file("payload")
url = f"https://api.access.redhat.com/management/v1/packages/{checksum}/download"
while attempts < max_attempts: while attempts < max_attempts:
attempts += 1 attempts += 1
result = call_api(token, url, stream=True) result = request_url(token, url, stream=True)
if result.status_code == 200: if result.status_code == 200:
# TODO: try and do this with dnf 'add_remote_rpms', although we would need to auth # TODO: try and do this with dnf 'add_remote_rpms', although we would need to auth
with open(temp_file, "wb") as f: with open(temp_file, "wb") as f:
...@@ -143,26 +147,49 @@ def get_token(ot): ...@@ -143,26 +147,49 @@ def get_token(ot):
return token return token
def call_api(token, url, params=None, stream=False): def request_url(token, url, params=None, stream=False):
"""call the api with a token""" """Make a request to a url, with an optional token"""
headers = {"Authorization": f"Bearer {token}"} if token is None:
headers = {}
else:
headers = {"Authorization": f"Bearer {token}"}
result = requests.get(url, headers=headers, params=params, stream=stream) result = requests.get(url, headers=headers, params=params, stream=stream)
return result return result
def get_upstream(token, feed): def get_upstream(token, feed):
"""retrieve full list of packages from a cset""" """retrieve full list of packages from a cset / package url"""
arch = re.match(r"(\w+-[0-9]-\w+-)(\w+)(-\w+-\w+)", feed).group(2) packages = []
matches = re.match(f"(\w+)-([0-9])-\w+-(\w+)-(\w+)", feed)
arch = matches.group(3)
# almalinux is simplier, so we process it earlier
if 'almalinux' in feed:
release = matches.group(2)
repo = matches.group(4)
base = dnf.Base()
conf = base.conf
base.repos.add_new_repo('package_alerts', conf,
baseurl=[f"https://repo.almalinux.org/almalinux/{release}/{repo}/{arch}/os/"])
base.fill_sack(load_system_repo=False)
q = base.sack.query()
i = q.available()
i = i.filter(arch=[arch, 'noarch'])
upstream = list(i)
for pkg in upstream:
# We use the url later in get_changelog
url=f"https://repo.almalinux.org/almalinux/{release}/{repo}/{arch}/os/Packages/{pkg}.rpm"
packages.append(f"{str(pkg).rsplit('.',1)[0]},{url}")
return packages
# From here, we are working solely on RHEL API stuff
url = ( url = (
f"https://api.access.redhat.com/management/v1/packages/cset/{feed}/arch/{arch}" f"https://api.access.redhat.com/management/v1/packages/cset/{feed}/arch/{arch}"
) )
offset = 0 offset = 0
packages = []
while True: while True:
signal.signal(signal.SIGALRM, timeout_handler) signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(30) signal.alarm(30)
try: try:
result = call_api(token, url, params={"limit": 100, "offset": offset}) result = request_url(token, url, params={"limit": 100, "offset": offset})
except TimeoutError: except TimeoutError:
print(f"Timeout occurred whilst trying to process {feed} with offset {offset}") print(f"Timeout occurred whilst trying to process {feed} with offset {offset}")
continue continue
...@@ -176,10 +203,10 @@ def get_upstream(token, feed): ...@@ -176,10 +203,10 @@ def get_upstream(token, feed):
count = j["pagination"]["count"] count = j["pagination"]["count"]
for p in j["body"]: for p in j["body"]:
package = f"{p['name']}-{p['version']}-{p['release']}" package = f"{p['name']}-{p['version']}-{p['release']}"
checksum = p["checksum"] payload = p["checksum"]
package_arch = p["arch"] package_arch = p["arch"]
if package_arch == arch: if package_arch == arch:
packages.append(f"{package},{checksum}") packages.append(f"{package},{payload}")
if count == 100: if count == 100:
offset += count offset += count
print(f"{feed}: incrementing offset to {offset}", flush=True) print(f"{feed}: incrementing offset to {offset}", flush=True)
...@@ -212,7 +239,7 @@ def set_local(packages, feed): ...@@ -212,7 +239,7 @@ def set_local(packages, feed):
def format_release(p, f, token): def format_release(p, f, token):
"""format message and send payload to mattermost""" """format message and send payload to mattermost"""
newpackage = p.split(',')[0] newpackage = p.split(',')[0]
checksum = p.split(',')[1] payload = p.split(',')[1]
logfile.write(f"{newpackage}\n") logfile.write(f"{newpackage}\n")
# check for epoch in name, and if it exists: ignore it # check for epoch in name, and if it exists: ignore it
try: try:
...@@ -240,7 +267,7 @@ def format_release(p, f, token): ...@@ -240,7 +267,7 @@ def format_release(p, f, token):
except (TypeError, KeyError): except (TypeError, KeyError):
notes = None notes = None
cl = get_changelog(token, checksum) cl = get_changelog(token, payload)
values = {} values = {}
# Using Mattermost attachments for prettier messages # Using Mattermost attachments for prettier messages
# https://developers.mattermost.com/integrate/admin-guide/admin-message-attachments/ # https://developers.mattermost.com/integrate/admin-guide/admin-message-attachments/
...@@ -274,7 +301,10 @@ def timeout_handler(num, stack): ...@@ -274,7 +301,10 @@ def timeout_handler(num, stack):
if __name__ == "__main__": if __name__ == "__main__":
"""this is the main class, it's amazing.""" """this is the main class, it's amazing."""
for feed in feeds: for feed in feeds:
token = get_token(offline_token) if 'rhel' in feed:
token = get_token(offline_token)
else:
token = None
print(f"working on feed {feed}", flush=True) print(f"working on feed {feed}", flush=True)
local_packages = get_local(feed) local_packages = get_local(feed)
upstream_packages = get_upstream(token, feed) upstream_packages = get_upstream(token, feed)
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
# and no notes will be included in the MM message. # and no notes will be included in the MM message.
--- ---
packages: packages:
almalinux-release:
notes: |-
**MANUAL ACTION REQUIRED**: This is a "dangerous package" and it will need to be [rebuilt by hand](https://linuxops.web.cern.ch/distributions/snapshots/#-release-packages-the-dangerous-rpms). If you don't do it **today**, the daily snapshot will stop tomorrow and you'll have more work to do then.
redhat-release: redhat-release:
notes: |- notes: |-
**MANUAL ACTION REQUIRED**: This is a "dangerous package" and it will need to be [rebuilt by hand](https://linuxops.web.cern.ch/distributions/snapshots/#-release-packages-the-dangerous-rpms). If you don't do it **today**, the daily snapshot will stop tomorrow and you'll have more work to do then. **MANUAL ACTION REQUIRED**: This is a "dangerous package" and it will need to be [rebuilt by hand](https://linuxops.web.cern.ch/distributions/snapshots/#-release-packages-the-dangerous-rpms). If you don't do it **today**, the daily snapshot will stop tomorrow and you'll have more work to do then.
......
SCHEDULE="*/30 * * * *" SCHEDULE="*/30 * * * *"
DB_MOUNTPOINT="/mnt/data2/package_alerts" DB_MOUNTPOINT="/mnt/data2/package_alerts"
INTERESTING_PACKAGES="prod.packages.yml" INTERESTING_PACKAGES="prod.packages.yml"
FEEDS="rhel-8-for-x86_64-baseos-rpms,rhel-8-for-x86_64-appstream-rpms,rhel-9-for-x86_64-baseos-rpms,rhel-9-for-x86_64-appstream-rpms" FEEDS="rhel-8-for-x86_64-baseos-rpms,rhel-8-for-x86_64-appstream-rpms,rhel-9-for-x86_64-baseos-rpms,rhel-9-for-x86_64-appstream-rpms,almalinux-8-for-x86_64-AppStream-rpms,almalinux-8-for-x86_64-BaseOS-rpms,almalinux-9-for-x86_64-AppStream-rpms,almalinux-9-for-x86_64-BaseOS-rpms"
MATTERMOST_INTEGRATION_URL="https://mattermost.web.cern.ch/hooks/qiodnmzwbjg9zkyxkxoh1h47sh" MATTERMOST_INTEGRATION_URL="https://mattermost.web.cern.ch/hooks/qiodnmzwbjg9zkyxkxoh1h47sh"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment