Skip to content

Commit a4784a6

Browse files
committed
Adapt check pertaining to scs-0104-standard-images
Signed-off-by: Matthias Büchse <[email protected]>
1 parent 39742eb commit a4784a6

File tree

4 files changed

+146
-8
lines changed

4 files changed

+146
-8
lines changed

Tests/iaas/openstack_test.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
compute_scs_0102_image_recency
3333
from scs_0103_standard_flavors.standard_flavors import \
3434
SCS_0103_CANONICAL_NAMES, compute_flavor_lookup, compute_scs_0103_flavor
35+
from scs_0104_standard_images.standard_images import \
36+
SCS_0104_IMAGE_SPECS, compute_scs_0104_source, compute_scs_0104_image
3537

3638

3739
logger = logging.getLogger(__name__)
@@ -51,7 +53,8 @@ def make_container(cloud):
5153
# basic support attributes shared by multiple testcases
5254
c.add_function('conn', lambda _: openstack.connect(cloud=cloud, timeout=32))
5355
c.add_function('flavors', lambda c: list(c.conn.list_flavors(get_extra=True)))
54-
c.add_function('images', lambda c: [img for img in c.conn.list_images() if img.visibility in ('public', 'community')])
56+
c.add_function('images', lambda c: [img for img in c.conn.list_images(show_all=True) if img.visibility in ('public', 'community')])
57+
c.add_function('image_lookup', lambda c: {img.name: img for img in c.images})
5558
# scs_0100_flavor_naming
5659
c.add_function('scs_flavors', lambda c: compute_scs_flavors(c.flavors))
5760
c.add_function('scs_0100_syntax_check', lambda c: compute_scs_0100_syntax_check(c.scs_flavors))
@@ -112,6 +115,39 @@ def make_container(cloud):
112115
c.scs_0103_flavor_16v_32, c.scs_0103_flavor_1v_8, c.scs_0103_flavor_2v_16, c.scs_0103_flavor_4v_32,
113116
c.scs_0103_flavor_1l_1, c.scs_0103_flavor_2v_4_20s, c.scs_0103_flavor_4v_16_100s,
114117
)))
118+
# scs_0104_standard_images
119+
c.add_function('scs_0104_source_capi_1', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['ubuntu-capi-image-1']))
120+
c.add_function('scs_0104_source_capi_2', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['ubuntu-capi-image-2']))
121+
c.add_function('scs_0104_source_ubuntu_2404', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['Ubuntu 24.04']))
122+
c.add_function('scs_0104_source_ubuntu_2204', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['Ubuntu 22.04']))
123+
c.add_function('scs_0104_source_ubuntu_2004', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['Ubuntu 20.04']))
124+
c.add_function('scs_0104_source_debian_13', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 13']))
125+
c.add_function('scs_0104_source_debian_12', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 12']))
126+
c.add_function('scs_0104_source_debian_11', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 11']))
127+
c.add_function('scs_0104_source_debian_10', lambda c: compute_scs_0104_source(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 10']))
128+
c.add_function('scs_0104_image_capi_1', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['ubuntu-capi-image-1']))
129+
c.add_function('scs_0104_image_capi_2', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['ubuntu-capi-image-2']))
130+
c.add_function('scs_0104_image_ubuntu_2404', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Ubuntu 24.04']))
131+
c.add_function('scs_0104_image_ubuntu_2204', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Ubuntu 22.04']))
132+
c.add_function('scs_0104_image_ubuntu_2004', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Ubuntu 20.04']))
133+
c.add_function('scs_0104_image_debian_13', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 13']))
134+
c.add_function('scs_0104_image_debian_12', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 12']))
135+
c.add_function('scs_0104_image_debian_11', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 11']))
136+
c.add_function('scs_0104_image_debian_10', lambda c: compute_scs_0104_image(c.image_lookup, SCS_0104_IMAGE_SPECS['Debian 10']))
137+
# NOTE the following variant is correct for SCS-compatible IaaS v4 only
138+
c.add_function('standard_images_check_1', lambda c: all((
139+
c.scs_0104_image_ubuntu_2204,
140+
c.scs_0104_source_capi_1, c.scs_0104_source_capi_2,
141+
c.scs_0104_source_ubuntu_2404, c.scs_0104_source_ubuntu_2204, c.scs_0104_source_ubuntu_2004,
142+
c.scs_0104_source_debian_13, c.scs_0104_source_debian_12, c.scs_0104_source_debian_11, c.scs_0104_source_debian_10,
143+
)))
144+
# NOTE the following variant is correct for SCS-compatible IaaS v5.1 only
145+
c.add_function('standard_images_check_2', lambda c: all((
146+
c.scs_0104_image_ubuntu_2404,
147+
c.scs_0104_source_capi_1, c.scs_0104_source_capi_2,
148+
c.scs_0104_source_ubuntu_2404, c.scs_0104_source_ubuntu_2204, c.scs_0104_source_ubuntu_2004,
149+
c.scs_0104_source_debian_13, c.scs_0104_source_debian_12, c.scs_0104_source_debian_11, c.scs_0104_source_debian_10,
150+
)))
115151
return c
116152

117153

@@ -213,7 +249,14 @@ def main(argv):
213249
else:
214250
usage(2)
215251

216-
testcases = [t for t in args if t.endswith('-check') or t.startswith('scs-')]
252+
# NOTE For historic reasons, there is precisely one testcase id, namely standard-images-check,
253+
# whose meaning depends on the version of the certificate scope in question. We are in the process
254+
# of transitioning away from this anti-feature. For the time being, however, we use the following
255+
# hack to support it: One testcase may be implemented in multiple variants, denoted by suffixing
256+
# a number, as in standard-images-check/1, standard-images-check/2.
257+
# NOTE Also, the historic testcases have terrible naming. We will transition towards names
258+
# that encode the corresponding standard, such as scs-0104-image-ubuntu-2404.
259+
testcases = [t for t in args if t.rsplit('/', 1)[0].endswith('-check') or t.startswith('scs-')]
217260
if len(testcases) != len(args):
218261
unknown = [a for a in args if a not in testcases]
219262
logger.warning(f"ignoring unknown testcases: {','.join(unknown)}")
@@ -224,7 +267,8 @@ def main(argv):
224267

225268
c = make_container(cloud)
226269
for testcase in testcases:
227-
harness(testcase, lambda: getattr(c, testcase.replace('-', '_')))
270+
testcase_name = testcase.rsplit('/', 1)[0] # see the note above
271+
harness(testcase_name, lambda: getattr(c, testcase.replace('-', '_').replace('/', '_')))
228272
return 0
229273

230274

File renamed without changes.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import logging
2+
import re
3+
4+
import yaml
5+
6+
7+
logger = logging.getLogger(__name__)
8+
9+
10+
_specs = yaml.safe_load(r"""
11+
"ubuntu-capi-image-1":
12+
name_scheme: "ubuntu-capi-image v[0-9]\\.[0-9]+(\\.[0-9]+)?"
13+
source: https://swift.services.a.regiocloud.tech/swift/v1/AUTH_b182637428444b9aa302bb8d5a5a418c/openstack-k8s-capi-images/ubuntu-2204-kube
14+
"ubuntu-capi-image-2":
15+
# this name_scheme uses `-` to separate base name "ubuntu-capi-image" from version
16+
# latest openstack-image-manager can be told to use `-` by setting `separator: "-"` on the image
17+
name_scheme: "ubuntu-capi-image-v[0-9]\\.[0-9]+(\\.[0-9]+)?"
18+
source: https://swift.services.a.regiocloud.tech/swift/v1/AUTH_b182637428444b9aa302bb8d5a5a418c/openstack-k8s-capi-images/ubuntu-2204-kube
19+
"Ubuntu 24.04":
20+
source:
21+
- https://cloud-images.ubuntu.com/releases/noble/
22+
- https://cloud-images.ubuntu.com/noble/
23+
"Ubuntu 22.04":
24+
source:
25+
- https://cloud-images.ubuntu.com/releases/jammy/
26+
- https://cloud-images.ubuntu.com/jammy/
27+
"Ubuntu 20.04":
28+
source:
29+
- https://cloud-images.ubuntu.com/releases/focal/
30+
- https://cloud-images.ubuntu.com/focal/
31+
"Debian 13":
32+
source:
33+
- https://cloud.debian.org/images/cloud/trixie/
34+
- https://cdimage.debian.org/cdimage/cloud/trixie/
35+
"Debian 12":
36+
source:
37+
- https://cloud.debian.org/images/cloud/bookworm/
38+
- https://cdimage.debian.org/cdimage/cloud/bookworm/
39+
"Debian 11":
40+
source:
41+
- https://cloud.debian.org/images/cloud/bullseye/
42+
- https://cdimage.debian.org/cdimage/cloud/bullseye/
43+
"Debian 10":
44+
source:
45+
- https://cloud.debian.org/images/cloud/buster/
46+
- https://cdimage.debian.org/cdimage/cloud/buster/
47+
""")
48+
SCS_0104_IMAGE_SPECS = {key: {'name': key, **val} for key, val in _specs.items()}
49+
50+
51+
def _lookup_images(image_lookup, image_spec):
52+
name_scheme = image_spec.get('name_scheme')
53+
if name_scheme:
54+
rex = re.compile(name_scheme)
55+
return [img for name, img in image_lookup.items() if rex.match(name)]
56+
img = image_lookup.get(image_spec['name'])
57+
if img is None:
58+
return []
59+
return [img]
60+
61+
62+
def compute_scs_0104_source(image_lookup, image_spec):
63+
matches = _lookup_images(image_lookup, image_spec)
64+
errors = 0
65+
for image in matches:
66+
img_source = image.properties['image_source']
67+
sources = image_spec['source']
68+
if not isinstance(sources, (tuple, list)):
69+
sources = [sources]
70+
if not any(img_source.startswith(src) for src in sources):
71+
errors += 1
72+
logger.error(f"Image '{image.name}' source mismatch: {img_source} matches none of these prefixes: {', '.join(sources)}")
73+
return not errors
74+
75+
76+
def compute_scs_0104_image(image_lookup, image_spec):
77+
matches = _lookup_images(image_lookup, image_spec)
78+
if not matches:
79+
logger.error(f"Missing image '{image_spec['name']}'")
80+
return False
81+
return True

Tests/scs-compatible-iaas.yaml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,27 @@ modules:
9191
tags: [mandatory]
9292
description: >
9393
Must fulfill all requirements of <https://docs.scs.community/standards/scs-0103-v1-standard-flavors>
94-
- id: scs-0104-v1
94+
- id: scs-0104-v1-1
9595
name: Standard images
9696
url: https://docs.scs.community/standards/scs-0104-v1-standard-images
9797
parameters:
9898
image_spec: address (URL) of an image-spec (YAML) file
9999
run:
100-
- executable: ./iaas/standard-images/images-openstack.py
101-
args: -c {os_cloud} -d {image_spec}
100+
- executable: ./iaas/openstack_test.py
101+
args: -c {os_cloud} standard-images-check/1
102+
testcases:
103+
- id: standard-images-check
104+
tags: [mandatory]
105+
description: >
106+
Must fulfill all requirements of <https://docs.scs.community/standards/scs-0104-v1-standard-images>
107+
- id: scs-0104-v1-2
108+
name: Standard images
109+
url: https://docs.scs.community/standards/scs-0104-v1-standard-images
110+
parameters:
111+
image_spec: address (URL) of an image-spec (YAML) file
112+
run:
113+
- executable: ./iaas/openstack_test.py
114+
args: -c {os_cloud} standard-images-check/2
102115
testcases:
103116
- id: standard-images-check
104117
tags: [mandatory]
@@ -207,7 +220,7 @@ versions:
207220
- scs-0101-v1
208221
- scs-0102-v1
209222
- scs-0103-v1
210-
- ref: scs-0104-v1
223+
- ref: scs-0104-v1-2
211224
parameters:
212225
image_spec: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Tests/iaas/scs-0104-v1-images-v5.yaml
213226
- scs-0114-v1
@@ -228,7 +241,7 @@ versions:
228241
- scs-0101-v1
229242
- scs-0102-v1
230243
- scs-0103-v1
231-
- ref: scs-0104-v1
244+
- ref: scs-0104-v1-1
232245
parameters:
233246
image_spec: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Tests/iaas/scs-0104-v1-images.yaml
234247
targets:

0 commit comments

Comments
 (0)