Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce mechanism to parametrize standards #595

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Standards/scs-0003-v1-sovereign-cloud-standards-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,13 @@ Every list of standards consists of several standards that – altogether – de
| `name` | String | Full name of the particular standard | _Flavor naming_ |
| `url` | String | Valid URL to the latest raw version of the particular standard | _[Flavor naming](https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0100-v2-flavor-naming.md)_ |
| `condition` | String | State of the particular standard, currently either `mandatory` or `optional`, default is `mandatory` | _mandatory_ |
| `parameters` | Map | Maps parameter names to parameter values | |
| `checks` | Array | List of all checks that must pass; each entry being a check descriptor | |

The parameters specified here will be added to the variable assignment for all check tools that belong to this standard, so they will be substituted in the same way.
The advantage is that these parameters may show up in the automatically generated documentation, whereas the check tools themselves probably won't.
See the "Standard images" standard in the larger basic example below for a possible use case.

### Check descriptor

The following fields are valid for every check descriptor:
Expand Down Expand Up @@ -194,7 +199,7 @@ versions:
id: flavor-name-check
lifetime: day
- name: Image metadata
url: https://raw.githubusercontent.com/SovereignCloudStack/Docs/main/Standards/SCS-0004-v1-image-metadata.md
url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0102-v1-image-metadata.md
condition: mandatory
checks:
- executable: image-md-check.py
Expand All @@ -205,6 +210,14 @@ versions:
condition: optional
id: image-md-check-2
lifetime: day
- name: Standard images
url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0104-v1-standard-images.md
parameters:
image_spec: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Tests/iaas/scs-0104-v1-images.yaml
checks:
- executable: ./iaas/standard-images/images-openstack.py
args: -c {os_cloud} -d {image_spec}
id: standard-images-check
- version: v4 # This is the upcoming version with a given target date. No further changes should be done to this set of standards
stabilized_at: 2022-04-01
standards:
Expand Down
9 changes: 9 additions & 0 deletions Tests/iaas/standard-images/images-openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def main(argv):
logger.critical("You need to have OS_CLOUD set or pass --os-cloud=CLOUD.")
return 1

# we only support local files; but we allow specifying the following URLs for the sake of
# better documentation
prefix = next(p for p in (
'https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Tests/',
'https://github.com/SovereignCloudStack/standards/blob/main/Tests/',
'', # sentinel (do not remove!)
) if yaml_path.startswith(p))
if prefix:
yaml_path = yaml_path[len(prefix):]
try:
with open(yaml_path, "rb") as fileobj:
image_data = yaml.safe_load(fileobj)
Expand Down
4 changes: 3 additions & 1 deletion Tests/scs-compatible-iaas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ versions:
id: standard-flavors-check
- name: Standard images
url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0104-v1-standard-images.md
parameters:
image_spec: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Tests/iaas/scs-0104-v1-images.yaml
checks:
- executable: ./iaas/standard-images/images-openstack.py
args: -c {os_cloud} -d ./iaas/scs-0104-v1-images.yaml
args: -c {os_cloud} -d {image_spec}
id: standard-images-check
- version: v3
stabilized_at: 2023-06-15
Expand Down
9 changes: 6 additions & 3 deletions Tests/scs-compliance-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
KEYWORDS = {
'spec': ('uuid', 'name', 'url', 'versions', 'prerequisite', 'variables'),
'version': ('version', 'standards', 'stabilized_at', 'deprecated_at'),
'standard': ('checks', 'url', 'name', 'condition'),
'standard': ('checks', 'url', 'name', 'condition', 'parameters'),
'check': ('executable', 'env', 'args', 'condition', 'lifetime', 'id', 'section'),
}

Expand Down Expand Up @@ -309,8 +309,11 @@ def main(argv):
if config.sections and section not in config.sections:
print(f"skipping check '{id_}': not in selected sections")
continue
args = check.get('args', '').format(**config.assignment)
env = {key: value.format(**config.assignment) for key, value in check.get('env', {}).items()}
assignment = config.assignment
if "parameters" in standard:
assignment = {**assignment, **standard['parameters']}
args = check.get('args', '').format(**assignment)
env = {key: value.format(**assignment) for key, value in check.get('env', {}).items()}
env_str = " ".join(f"{key}={value}" for key, value in env.items())
memo_key = f"{env_str} {check['executable']} {args}".strip()
invokation = memo.get(memo_key)
Expand Down