From 7120c5dfa0526eed95a96722e05a58e527c114b2 Mon Sep 17 00:00:00 2001 From: Kurt Garloff Date: Mon, 2 Sep 2024 21:03:09 +0200 Subject: [PATCH] Only consider image properties of public/community images. (#724) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Only consider image properties of public/community images. We may not have the luxury to test against a pristine project, so there may be prviate images or shared images from others. Only consider provider images with "public" or "community" visibility. https://wiki.openstack.org/wiki/Glance-v2-community-image-visibility-design Signed-off-by: Kurt Garloff * Allows image filtering by visibility. Default is public,community. Passing --image-visibility="" will result in no filtering, same as passing -V "public,community,shared,private". Signed-off-by: Kurt Garloff * fail if no image left after filtering, filter early, make more Pythonic Signed-off-by: Matthias Büchse --------- Signed-off-by: Kurt Garloff Signed-off-by: Matthias Büchse Co-authored-by: Matthias Büchse --- Tests/iaas/entropy/entropy-check.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Tests/iaas/entropy/entropy-check.py b/Tests/iaas/entropy/entropy-check.py index 067606945..b24cfcf34 100755 --- a/Tests/iaas/entropy/entropy-check.py +++ b/Tests/iaas/entropy/entropy-check.py @@ -85,6 +85,8 @@ def print_usage(file=sys.stderr): [-c/--os-cloud OS_CLOUD] sets cloud environment (default from OS_CLOUD env) [-d/--debug] enables DEBUG logging channel [-i/--images IMAGE_LIST] sets images to be tested, separated by comma. + [-V/--image-visibility VIS_LIST] filters images by visibility + (default: 'public,community'; use '*' to disable) """, end='', file=file) @@ -343,9 +345,7 @@ def _deduce_sort_ubuntu(os_version, ubuntu_ver=re.compile(r"\d\d\.\d\d\Z")): def _deduce_sort(img): - # avoid private images here - # (note that with SCS, public images MUST have os_distro and os_version, but we check nonetheless) - if img.visibility != 'public' or not img.os_distro or not img.os_version: + if not img.os_distro or not img.os_version: return 0, 0 deducer = DISTROS.get(img.os_distro.strip().lower()) if deducer is None: @@ -401,7 +401,7 @@ def main(argv): logger.addHandler(counting_handler) try: - opts, args = getopt.gnu_getopt(argv, "c:i:hd", ["os-cloud=", "images=", "help", "debug"]) + opts, args = getopt.gnu_getopt(argv, "c:i:hdV:", ["os-cloud=", "images=", "help", "debug", "image-visibility="]) except getopt.GetoptError as exc: logger.critical(f"{exc}") print_usage() @@ -409,6 +409,7 @@ def main(argv): cloud = os.environ.get("OS_CLOUD") image_names = set() + image_visibility = set() for opt in opts: if opt[0] == "-h" or opt[0] == "--help": print_usage() @@ -419,17 +420,32 @@ def main(argv): cloud = opt[1] if opt[0] == "-d" or opt[0] == "--debug": logging.getLogger().setLevel(logging.DEBUG) + if opt[0] == "-V" or opt[0] == "--image-visibility": + image_visibility.update([v.strip() for v in opt[1].split(',')]) if not cloud: logger.critical("You need to have OS_CLOUD set or pass --os-cloud=CLOUD.") return 1 + if not image_visibility: + image_visibility.update(("public", "community")) + try: logger.debug(f"Connecting to cloud '{cloud}'") with openstack.connect(cloud=cloud, timeout=32) as conn: all_images = conn.list_images() all_flavors = conn.list_flavors(get_extra=True) + if '*' not in image_visibility: + logger.debug(f"Images: filter for visibility {', '.join(image_visibility)}") + all_images = [img for img in all_images if img.visibility in image_visibility] + all_image_names = [f"{img.name} ({img.visibility})" for img in all_images] + logger.debug(f"Images: {', '.join(all_image_names) or '(NONE)'}") + + if not all_images: + logger.critical("Can't run this test without image") + return 1 + if image_names: # find images by the names given, BAIL out if some image is missing images = sorted([img for img in all_images if img.name in image_names], key=lambda img: img.name)