Skip to content

Commit 33e329f

Browse files
mbuechsegarloff
andauthored
Harmonize image selection across tests (#766)
Signed-off-by: Matthias Büchse <[email protected]> Co-authored-by: Kurt Garloff <[email protected]>
1 parent d0dce6d commit 33e329f

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

Tests/iaas/entropy/entropy-check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def main(argv):
437437
all_flavors = conn.list_flavors(get_extra=True)
438438

439439
if '*' not in image_visibility:
440-
logger.debug(f"Images: filter for visibility {', '.join(image_visibility)}")
440+
logger.debug(f"Images: filter for visibility {', '.join(sorted(image_visibility))}")
441441
all_images = [img for img in all_images if img.visibility in image_visibility]
442442
all_image_names = [f"{img.name} ({img.visibility})" for img in all_images]
443443
logger.debug(f"Images: {', '.join(all_image_names) or '(NONE)'}")

Tests/iaas/image-metadata/image-md-check.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
SPDX-License-Identifier: CC-BY-SA-4.0
1212
"""
1313

14+
import calendar
15+
from collections import Counter
16+
import getopt
17+
import logging
1418
import os
1519
import sys
1620
import time
17-
import calendar
18-
import getopt
21+
1922
import openstack
20-
from collections import Counter
23+
24+
25+
logger = logging.getLogger(__name__)
2126

2227

2328
def usage(ret):
@@ -31,8 +36,10 @@ def usage(ret):
3136
print(" -v/--verbose : Be more verbose")
3237
print(" -s/--skip-completeness: Don't check whether we have all mandatory images")
3338
print(" -h/--help : Print this usage information")
34-
print("If you pass images, only these will be validated, otherwise all (public unless")
35-
print(" -p is specified) images from the catalog will be processed.")
39+
print(" [-V/--image-visibility VIS_LIST] : filters images by visibility")
40+
print(" (default: 'public,community'; use '*' to disable)")
41+
print("If you pass images, only these will be validated, otherwise all images")
42+
print("(filtered according to -p, -V) from the catalog will be processed.")
3643
sys.exit(ret)
3744

3845

@@ -335,43 +342,59 @@ def miss_replacement_images(by_name, outd_list):
335342

336343
def main(argv):
337344
"Main entry point"
345+
# configure logging, disable verbose library logging
346+
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
347+
openstack.enable_logging(debug=False)
338348
# Option parsing
339349
global verbose
350+
image_visibility = set()
340351
private = False
341352
skip = False
342353
cloud = os.environ.get("OS_CLOUD")
343354
err = 0
344355
try:
345-
opts, args = getopt.gnu_getopt(argv[1:], "phvc:s",
346-
("private", "help", "os-cloud=", "verbose", "skip-completeness"))
356+
opts, args = getopt.gnu_getopt(argv[1:], "phvc:sV:",
357+
("private", "help", "os-cloud=", "verbose", "skip-completeness", "image-visibility="))
347358
except getopt.GetoptError: # as exc:
348359
print("CRITICAL: Command-line syntax error", file=sys.stderr)
349360
usage(1)
350361
for opt in opts:
351362
if opt[0] == "-h" or opt[0] == "--help":
352363
usage(0)
353364
elif opt[0] == "-p" or opt[0] == "--private":
354-
private = True
365+
private = True # only keep this for backwards compatibility (we have -V now)
355366
elif opt[0] == "-v" or opt[0] == "--verbose":
356367
verbose = True
368+
logging.getLogger().setLevel(logging.DEBUG)
357369
elif opt[0] == "-s" or opt[0] == "--skip-completeness":
358370
skip = True
359371
elif opt[0] == "-c" or opt[0] == "--os-cloud":
360372
cloud = opt[1]
373+
if opt[0] == "-V" or opt[0] == "--image-visibility":
374+
image_visibility.update([v.strip() for v in opt[1].split(',')])
361375
images = args
362376
if not cloud:
363377
print("CRITICAL: Need to specify --os-cloud or set OS_CLOUD environment.", file=sys.stderr)
364378
usage(1)
379+
if not image_visibility:
380+
image_visibility.update(("public", "community"))
381+
if private:
382+
image_visibility.add("private")
365383
try:
366384
conn = openstack.connect(cloud=cloud, timeout=24)
367385
all_images = list(conn.image.images())
386+
if '*' not in image_visibility:
387+
logger.debug(f"Images: filter for visibility {', '.join(sorted(image_visibility))}")
388+
all_images = [img for img in all_images if img.visibility in image_visibility]
389+
all_image_names = [f"{img.name} ({img.visibility})" for img in all_images]
390+
logger.debug(f"Images: {', '.join(all_image_names) or '(NONE)'}")
368391
by_name = {img.name: img for img in all_images}
369392
if len(by_name) != len(all_images):
370393
counter = Counter([img.name for img in all_images])
371394
duplicates = [name for name, count in counter.items() if count > 1]
372395
print(f'WARNING: duplicate names detected: {", ".join(duplicates)}', file=sys.stderr)
373396
if not images:
374-
images = [img.name for img in all_images if private or img.visibility == 'public']
397+
images = [img.name for img in all_images]
375398
# Analyse image metadata
376399
outdated_images = []
377400
for imgnm in images:

Tests/iaas/standard-images/images-openstack.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def print_usage(file=sys.stderr):
4040
Options:
4141
[-c/--os-cloud OS_CLOUD] sets cloud environment (default from OS_CLOUD env)
4242
[-d/--debug] enables DEBUG logging channel
43+
[-V/--image-visibility VIS_LIST] filters images by visibility
44+
(default: 'public,community'; use '*' to disable)
4345
""", end='', file=file)
4446

4547

@@ -61,7 +63,7 @@ def main(argv):
6163
logger.addHandler(counting_handler)
6264

6365
try:
64-
opts, args = getopt.gnu_getopt(argv, "c:hd", ["os-cloud=", "help", "debug"])
66+
opts, args = getopt.gnu_getopt(argv, "c:hdV:", ["os-cloud=", "help", "debug", "image-visibility="])
6567
except getopt.GetoptError as exc:
6668
logger.critical(f"{exc}")
6769
print_usage()
@@ -74,6 +76,7 @@ def main(argv):
7476

7577
yaml_path = args[0]
7678
cloud = os.environ.get("OS_CLOUD")
79+
image_visibility = set()
7780
for opt in opts:
7881
if opt[0] == "-h" or opt[0] == "--help":
7982
print_usage()
@@ -82,11 +85,16 @@ def main(argv):
8285
cloud = opt[1]
8386
if opt[0] == "-d" or opt[0] == "--debug":
8487
logging.getLogger().setLevel(logging.DEBUG)
88+
if opt[0] == "-V" or opt[0] == "--image-visibility":
89+
image_visibility.update([v.strip() for v in opt[1].split(',')])
8590

8691
if not cloud:
8792
logger.critical("You need to have OS_CLOUD set or pass --os-cloud=CLOUD.")
8893
return 1
8994

95+
if not image_visibility:
96+
image_visibility.update(("public", "community"))
97+
9098
# we only support local files; but we allow specifying the following URLs for the sake of
9199
# better documentation
92100
prefix = next(p for p in (
@@ -113,11 +121,15 @@ def main(argv):
113121
logger.debug(f"Fetching image list from cloud '{cloud}'")
114122
with openstack.connect(cloud=cloud, timeout=32) as conn:
115123
present_images = conn.list_images(show_all=True)
116-
by_name = {
117-
image.name: image
118-
for image in present_images
119-
}
120-
logger.debug(f"Images present: {', '.join(sorted(by_name))}")
124+
if '*' not in image_visibility:
125+
logger.debug(f"Images: filter for visibility {', '.join(sorted(image_visibility))}")
126+
present_images = [img for img in present_images if img.visibility in image_visibility]
127+
all_image_names = [f"{img.name} ({img.visibility})" for img in present_images]
128+
logger.debug(f"Images: {', '.join(all_image_names) or '(NONE)'}")
129+
by_name = {
130+
image.name: image
131+
for image in present_images
132+
}
121133

122134
logger.debug(f"Checking {len(image_specs)} image specs against {len(present_images)} images")
123135
for image_spec in image_specs:

0 commit comments

Comments
 (0)