11import os
2+ import re
3+ import requests
4+ from bs4 import BeautifulSoup
5+ from datetime import datetime
26
37header = '''# GENERATED FILE - DO NOT EDIT
48set -e
@@ -306,10 +310,80 @@ def openqa_call_start_meta_variables(meta_variables):
306310def 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+ };
309381openqa_call_start = lambda distri , version , archs , staging , news , news_archs , flavor_distri , meta_variables , assets_flavor , repo0folder , openqa_cli : '''
310382archs=(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 ) + '''"
313387for 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
587671done
588672'''
0 commit comments