Skip to content

Commit f3db332

Browse files
committed
Schedule product per livepatch kernel_version
Automate the livepatch isos posts. Due to the logic of the script generation this commit contains an injection of a for loop for all the livepatches which will be scrapped from test repository. - the loop always run even if no livepatches found. However it will only append to the isos posts the variable in the case that actually livepatch versions inclue in the array. The approach is just a bit dirty, as any other approach would require further and bigger changes. depends-on: https://gitlab.suse.de/openqa/openqa-trigger-from-ibs-plugin/-/merge_requests/263 issue: https://progress.opensuse.org/issues/190134 Signed-off-by: Ioannis Bonatakis <ybonatakis@suse.com>
1 parent 5ea66e4 commit f3db332

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

script/cfg.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import os
2+
import re
3+
import requests
4+
from bs4 import BeautifulSoup
5+
from datetime import datetime
26

37
header = '''# GENERATED FILE - DO NOT EDIT
48
set -e
@@ -306,10 +310,80 @@ def openqa_call_start_meta_variables(meta_variables):
306310
def pre_openqa_call_start(repos):
307311
return ''
308312

313+
# def pre_openqa_call_find_kernel_livepatch_versions():
314+
# return f"($(grep -oP '(?<=kernel-livepatch-)\d+_\d+_\d+-\d+' \"/var/lib/openqa/factory/iso/${{iso}}\" | uniq))"
315+
def _find_latest_livepatches(url):
316+
"""
317+
Scrapes a URL to find all kernel-livepatch-* with the
318+
most recent date.
319+
"""
320+
try:
321+
response = requests.get(url)
322+
response.raise_for_status()
323+
except requests.exceptions.RequestException as e:
324+
print(f"Error fetching URL: {e}")
325+
return []
326+
327+
soup = BeautifulSoup(response.text, 'html.parser')
328+
329+
livepatches_unfiltered = []
330+
latest_date = None
331+
lp_regex = r'kernel-livepatch-((?:\d+_?)+-\d+)'
332+
#pdb.set_trace()
333+
for row in soup.find_all('tr'):
334+
elem = row.find_all('td')
335+
if len(elem) < 2:
336+
continue
337+
338+
link = elem[0].find('a')
339+
if (link and link.text.startswith('kernel-livepatch-')):
340+
#and '-rt' in link.text):
341+
#pdb.set_trace()
342+
date_str = elem[1].text.strip().split()[0]
343+
try:
344+
current_date = datetime.strptime(date_str, '%d-%b-%Y')
345+
livepatches_unfiltered.append({'name': link.text, 'date': current_date})
346+
347+
if latest_date is None or current_date > latest_date:
348+
latest_date = current_date
349+
except ValueError:
350+
continue
351+
352+
if latest_date is None:
353+
return []
354+
# to list only the recent ones
355+
latest_patches_list = []
356+
for patch in livepatches_unfiltered:
357+
if patch['date'] == latest_date:
358+
kernel_version = re.search(lp_regex, patch['name'])
359+
latest_patches_list.append(kernel_version.group(1))
360+
361+
return latest_patches_list
362+
363+
def openqa_fetch_livepatch_list():
364+
kpatches = {}
365+
for arch in ['x86_64','aarch64','s390x','ppc64le']:
366+
totest_url = f"https://download.suse.de/ibs/SUSE:/ALP:/Products:/Marble:/6.0:/ToTest/product/repo/SL-Micro-6.0-{arch}/{arch}/"
367+
368+
latest_kernel_livepatches = _find_latest_livepatches(totest_url)
369+
370+
if latest_kernel_livepatches:
371+
for livepatch in latest_kernel_livepatches:
372+
kpatches.update({arch: latest_kernel_livepatches})
373+
return kpatches
374+
375+
#openqa_livepatches = lambda arch: ' '.join(openqa_fetch_livepatch_list().get(arch, [])) or 'NONE'
376+
openqa_livepatches = {
377+
f"{arch}:{' '.join(versions)}"
378+
for arch, versions in openqa_fetch_livepatch_list().items()
379+
if versions
380+
};
309381
openqa_call_start = lambda distri, version, archs, staging, news, news_archs, flavor_distri, meta_variables, assets_flavor, repo0folder, openqa_cli: '''
310382
archs=(ARCHITECTURS)
311383
[ ! -f __envsub/files_repo.lst ] || ! grep -q -- "-POOL-" __envsub/files_repo.lst || additional_repo_suffix=-POOL
312-
384+
declare -a livepatches
385+
livepatches=(NONE)
386+
livepatches_all="''' + str(openqa_livepatches) + '''"
313387
for flavor in {FLAVORALIASLIST,}; do
314388
for arch in "${archs[@]}"; do
315389
filter=$flavor
@@ -326,6 +400,10 @@ def pre_openqa_call_start(repos):
326400
[ -n "$iso" ] || [ "$flavor" != "''' + assets_flavor + r'''" ] || buildex=$(grep -o -E '(Build|Snapshot)[^-]*' __envsub/files_asset.lst | head -n 1)
327401
[ -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]+)*')|| :
328402
[ -n "$build" ] || continue
403+
livepatches=($(echo "$livepatches_all" | sed "s/[{}']//g" | sed 's/, /\n/g' | awk -F':' -v arch="$arch" '$1 == arch {print $2}'))
404+
if [ ${#livepatches[@]} -eq 0 ]; then
405+
livepatches=(NONE)
406+
fi
329407
buildex=${buildex/.install.iso/}
330408
buildex=${buildex/.iso/}
331409
buildex=${buildex/.raw.xz/}
@@ -342,7 +420,12 @@ def pre_openqa_call_start(repos):
342420
}
343421
fi
344422
# test "$destiso" != "" || continue
423+
for livepatch in "${livepatches[@]}"; do
345424
echo "''' + openqa_cli + ''' \\\\\"
425+
if [[ "${livepatch}" != "NONE" ]]; then
426+
echo \" KGRAFT=1 \\\\
427+
KERNEL_VERSION=${livepatch} \\\\\"
428+
fi
346429
(
347430
echo \" DISTRI=$distri \\\\
348431
ARCH=$arch \\\\
@@ -583,6 +666,7 @@ def openqa_call_end(version):
583666
echo " FLAVOR=${flavor//Tumbleweed-/} \\\\"
584667
) | LANG=C.UTF-8 sort
585668
echo ""
669+
done
586670
done
587671
done
588672
'''

0 commit comments

Comments
 (0)