Skip to content

Commit

Permalink
Allow image specs with regex (name_scheme), allow multiple source URL…
Browse files Browse the repository at this point in the history
… prefixes

Signed-off-by: Matthias Büchse <[email protected]>
  • Loading branch information
mbuechse committed Sep 4, 2023
1 parent 0457af2 commit 3c3d5b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
25 changes: 18 additions & 7 deletions Tests/iaas/scs-0104-v1-images.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
images:
- name: "Ubuntu 22.04"
source: https://cloud-images.ubuntu.com/releases/jammy/
source:
- https://cloud-images.ubuntu.com/releases/jammy/
- https://cloud-images.ubuntu.com/jammy/
status: mandatory
- name: "Kubernetes CAPI 1.27.3"
source: https://minio.services.osism.tech/openstack-k8s-capi-images/ubuntu-2204-kube-v1.27/ubuntu-2204-kube-v1.27.3.qcow2
- name: "ubuntu-2204-kube"
name_scheme: "ubuntu-2204-kube-v[0-9].[0-9]+(.[0-9]+)?"
source: https://swift.services.a.regiocloud.tech/swift/v1/AUTH_b182637428444b9aa302bb8d5a5a418c/openstack-k8s-capi-images/ubuntu-2204-kube
status: recommended
- name: "Ubuntu 20.04"
source: https://cloud-images.ubuntu.com/releases/focal/
source:
- https://cloud-images.ubuntu.com/releases/focal/
- https://cloud-images.ubuntu.com/focal/
- name: "Debian 12"
source: https://cloud.debian.org/images/cloud/bookworm/
source:
- https://cloud.debian.org/images/cloud/bookworm/
- https://cdimage.debian.org/cdimage/cloud/bookworm/
- name: "Debian 11"
source: https://cloud.debian.org/images/cloud/bullseye/
source:
- https://cloud.debian.org/images/cloud/bullseye/
- https://cdimage.debian.org/cdimage/cloud/bullseye/
- name: "Debian 10"
source: https://cloud.debian.org/images/cloud/buster/
source:
- https://cloud.debian.org/images/cloud/buster/
- https://cdimage.debian.org/cdimage/cloud/buster/
21 changes: 16 additions & 5 deletions Tests/iaas/standard-images/images-openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import getopt
import logging
import os
import re
import sys

import openstack
Expand Down Expand Up @@ -107,18 +108,28 @@ def main(argv):
image.name: image
for image in present_images
}
logger.debug(f"Images present: {', '.join(sorted(by_name))}")

logger.debug(f"Checking {len(image_specs)} image specs against {len(present_images)} images")
for image_spec in image_specs:
image = by_name.get(image_spec['name'])
if not image:
name_scheme = image_spec.get('name_scheme')
if name_scheme:
rex = re.compile(name_scheme)
matches = [img for name, img in by_name.items() if rex.match(name)]
else:
matches = [img for img in (by_name.get(image_spec['name']), ) if img is not None]
if not matches:
status = image_spec.get('status', 'optional')
level = {"mandatory": logging.ERROR, "recommended": logging.INFO}.get(status, logging.DEBUG)
logger.log(level, f"Missing {status} image '{image_spec['name']}'")
continue
img_source = image.properties['image_source']
if not img_source.startswith(image_spec['source']):
logger.error(f"Image '{image_spec['name']}' source mismatch: {image_spec['source']} != {img_source} {image.properties}")
for image in matches:
img_source = image.properties['image_source']
sources = image_spec['source']
if not isinstance(sources, (tuple, list)):
sources = [sources]
if not any(img_source.startswith(src) for src in sources):
logger.error(f"Image '{image.name}' source mismatch: {img_source} matches none of these prefixes: {', '.join(sources)}")
except BaseException as e:
logger.critical(f"{e!r}")
logger.debug("Exception info", exc_info=True)
Expand Down

0 comments on commit 3c3d5b0

Please sign in to comment.