Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 85 additions & 1 deletion script/cfg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import os
import re
import requests
from bs4 import BeautifulSoup
from datetime import datetime

header = '''# GENERATED FILE - DO NOT EDIT
set -e
Expand Down Expand Up @@ -306,10 +310,80 @@ def openqa_call_start_meta_variables(meta_variables):
def pre_openqa_call_start(repos):
return ''

# def pre_openqa_call_find_kernel_livepatch_versions():
# return f"($(grep -oP '(?<=kernel-livepatch-)\d+_\d+_\d+-\d+' \"/var/lib/openqa/factory/iso/${{iso}}\" | uniq))"
def _find_latest_livepatches(url):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably make sense to be able to execute this standalone (in the absence of unit tests, so it can at least be tested easily manually).

"""
Scrapes a URL to find all kernel-livepatch-* with the
most recent date.
"""
try:
response = requests.get(url)
response.raise_for_status()
except requests.exceptions.RequestException as e:
print(f"Error fetching URL: {e}")
return []

soup = BeautifulSoup(response.text, 'html.parser')

livepatches_unfiltered = []
latest_date = None
lp_regex = r'kernel-livepatch-((?:\d+_?)+-\d+)'
#pdb.set_trace()
for row in soup.find_all('tr'):
elem = row.find_all('td')
if len(elem) < 2:
continue

link = elem[0].find('a')
if (link and link.text.startswith('kernel-livepatch-')):
#and '-rt' in link.text):
#pdb.set_trace()
date_str = elem[1].text.strip().split()[0]
try:
current_date = datetime.strptime(date_str, '%d-%b-%Y')
livepatches_unfiltered.append({'name': link.text, 'date': current_date})

if latest_date is None or current_date > latest_date:
latest_date = current_date
except ValueError:
continue

if latest_date is None:
return []
# to list only the recent ones
latest_patches_list = []
for patch in livepatches_unfiltered:
if patch['date'] == latest_date:
kernel_version = re.search(lp_regex, patch['name'])
latest_patches_list.append(kernel_version.group(1))

return latest_patches_list

def openqa_fetch_livepatch_list():
kpatches = {}
for arch in ['x86_64','aarch64','s390x','ppc64le']:
totest_url = f"https://download.suse.de/ibs/SUSE:/ALP:/Products:/Marble:/6.0:/ToTest/product/repo/SL-Micro-6.0-{arch}/{arch}/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can append ?jsontable to that URL and parse the JSON (instead of having to parse HTML with BeautifulSoup).


latest_kernel_livepatches = _find_latest_livepatches(totest_url)

if latest_kernel_livepatches:
for livepatch in latest_kernel_livepatches:
kpatches.update({arch: latest_kernel_livepatches})
return kpatches

#openqa_livepatches = lambda arch: ' '.join(openqa_fetch_livepatch_list().get(arch, [])) or 'NONE'
openqa_livepatches = {
f"{arch}:{' '.join(versions)}"
for arch, versions in openqa_fetch_livepatch_list().items()
if versions
};
openqa_call_start = lambda distri, version, archs, staging, news, news_archs, flavor_distri, meta_variables, assets_flavor, repo0folder, openqa_cli: '''
archs=(ARCHITECTURS)
[ ! -f __envsub/files_repo.lst ] || ! grep -q -- "-POOL-" __envsub/files_repo.lst || additional_repo_suffix=-POOL

declare -a livepatches
livepatches=(NONE)
livepatches_all="''' + str(openqa_livepatches) + '''"
for flavor in {FLAVORALIASLIST,}; do
for arch in "${archs[@]}"; do
filter=$flavor
Expand All @@ -326,6 +400,10 @@ def pre_openqa_call_start(repos):
[ -n "$iso" ] || [ "$flavor" != "''' + assets_flavor + r'''" ] || buildex=$(grep -o -E '(Build|Snapshot)[^-]*' __envsub/files_asset.lst | head -n 1)
[ -n "$iso$build" ] || build=$(grep -h -o -E '(Build|Snapshot)[^-]*' __envsub/Media1*.lst 2>/dev/null | head -n 1 | grep -o -E '[0-9]\.?[0-9]+(\.[0-9]+)*')|| :
[ -n "$build" ] || continue
livepatches=($(echo "$livepatches_all" | sed "s/[{}']//g" | sed 's/, /\n/g' | awk -F':' -v arch="$arch" '$1 == arch {print $2}'))
if [ ${#livepatches[@]} -eq 0 ]; then
livepatches=(NONE)
fi
buildex=${buildex/.install.iso/}
buildex=${buildex/.iso/}
buildex=${buildex/.raw.xz/}
Expand All @@ -342,7 +420,12 @@ def pre_openqa_call_start(repos):
}
fi
# test "$destiso" != "" || continue
for livepatch in "${livepatches[@]}"; do
echo "''' + openqa_cli + ''' \\\\\"
if [[ "${livepatch}" != "NONE" ]]; then
echo \" KGRAFT=1 \\\\
KERNEL_VERSION=${livepatch} \\\\\"
fi
(
echo \" DISTRI=$distri \\\\
ARCH=$arch \\\\
Expand Down Expand Up @@ -583,6 +666,7 @@ def openqa_call_end(version):
echo " FLAVOR=${flavor//Tumbleweed-/} \\\\"
) | LANG=C.UTF-8 sort
echo ""
done
done
done
'''
Expand Down
Loading