Skip to content

Commit

Permalink
find recent Debian image even if only codenames are given (#697)
Browse files Browse the repository at this point in the history
resolves #696

Signed-off-by: Matthias Büchse <[email protected]>
  • Loading branch information
mbuechse authored Aug 15, 2024
1 parent e011683 commit 7de627d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Tests/iaas/entropy/entropy-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from collections import Counter
import getopt
import logging
from operator import attrgetter
import os
import re
import sys
Expand Down Expand Up @@ -403,6 +402,25 @@ def handle(self, record):
self.bylevel[record.levelno] += 1


def _deduce_version(name, ubuntu_ver=re.compile(r"\d\d\.\d\d\Z"), debian_ver=re.compile(r"\d+\Z")):
"""helper for `select_deb_image` to deduce a version even if its only given via codename"""
canonicalized = [part.strip() for part in name.lower().split()]
if "debian" in canonicalized:
# don't even consider "stretch" (9) here
codenames = ("buster", "bullseye", "bookworm")
for idx, name in enumerate(codenames):
if name in canonicalized:
return idx + 10
for part in canonicalized:
if debian_ver.match(part):
return int(part)
elif "ubuntu" in canonicalized:
for part in canonicalized:
if ubuntu_ver.match(part):
return int(part[:2] + part[3:])
return -1


def select_deb_image(images):
"""From a list of OpenStack image objects, select a recent Debian derivative.
Expand All @@ -411,7 +429,7 @@ def select_deb_image(images):
for prefix in ("Debian ", "Ubuntu "):
imgs = sorted(
[img for img in images if img.name.startswith(prefix)],
key=attrgetter("name"),
key=lambda img: _deduce_version(img.name),
)
if imgs:
return imgs[-1]
Expand Down

0 comments on commit 7de627d

Please sign in to comment.