Skip to content

Commit

Permalink
CI test for flavor-name syntax in scs-0103 yaml file
Browse files Browse the repository at this point in the history
closes #339

Signed-off-by: Matthias Büchse <[email protected]>
  • Loading branch information
mbuechse committed Dec 22, 2023
1 parent b97f9d4 commit 7f2766e
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 2 deletions.
92 changes: 92 additions & 0 deletions Tests/iaas/flavor-naming/check-yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python3
"""Check flavor names in the YAML files used for scs-0103-v1 with respect to scs-0100-vX.
Also check that the flavor properties encoded in the YAML match those encoded in the name.
"""
import importlib
import os
import os.path
import sys

import yaml

fnmck = importlib.import_module("flavor-name-check")
fnmck.disallow_old = True


REQUIRED_FIELDS = ['name-v1', 'name-v2', 'name', 'cpus', 'ram', 'cpu-type']
DEFAULTS = {'disk0-type': 'network'}
CPUTYPE_KEY = {'L': 'crowded-core', 'V': 'shared-core', 'T': 'dedicated-thread', 'C': 'dedicated-core'}
DISKTYPE_KEY = {'n': 'network', 'h': 'hdd', 's': 'ssd', 'p': 'nvme'}


class Checker:
def __init__(self):
self.errors = 0

def emit(self, s):
print(f"ERROR: {s}", file=sys.stderr)
self.errors += 1

def check_spec(self, flavor_spec):
missing = [key for key in REQUIRED_FIELDS if key not in flavor_spec]
if missing:
self.emit(f"flavor spec missing keys {', '.join(missing)}: {flavor_spec}")
return
name = flavor_spec['name']
name_v1 = flavor_spec['name-v1']
name_v2 = flavor_spec['name-v2']
parsed = fnmck.parsename(name_v2)
if not parsed:
self.emit(f"{name}: name-v2 '{name_v2}' could not be parsed")
cpu, disk, hype, hvirt, cpubrand, gpu, ibd = parsed
expected = {
'cpus': cpu.cpus,
'cpu-type': CPUTYPE_KEY[cpu.cputype],
'ram': cpu.ram,
'name-v1': fnmck.new_to_old(name_v2),
}
if disk.parsed:
if disk.nrdisks != 1:
emit(f"flavor '{name}': name-v2 using multiple disks")
expected['disk'] = disk.disksize
expected['disk0-type'] = DISKTYPE_KEY[disk.disktype or 'n']
for key, exp_val in expected.items():
val = flavor_spec.get(key, DEFAULTS.get(key, None))
if val != exp_val:
self.emit(
f"flavor '{name}': field '{key}' contradicting name-v2 '{name_v2}'; "
f"found '{val}', expected '{exp_val}'"
)


def main(argv):
if len(argv) != 2:
raise RuntimeError("must specify exactly one argument, PATH to the yaml file")
yaml_path = argv[1]
yaml_files = sorted([
fn
for fn in os.listdir(yaml_path)
if fn.startswith("scs-0103-") and fn.endswith(".yaml")
])
main_checker = Checker()
if not yaml_files:
main_checker.emit("no yaml files found!")
for fn in yaml_files:
with open(os.path.join(yaml_path, fn), "rb") as fileobj:
flavor_spec_data = yaml.safe_load(fileobj)
checker = Checker()
for group in flavor_spec_data['flavor_groups']:
for flavor_spec in group['list']:
checker.check_spec(flavor_spec)
if checker.errors:
main_checker.emit(f"file '{fn}': found {checker.errors} errors")
return main_checker.errors


if __name__ == "__main__":
try:
sys.exit(main(sys.argv))
except Exception as e:
print(f"CRITICAL: {e!s}", file=sys.stderr)
sys.exit(1)
193 changes: 193 additions & 0 deletions Tests/testing/scs-0103-v1-flavors-wrong.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
meta:
name_key: name-v2
flavor_groups:
- status: mandatory
list:
- name: SCS-1V-4
cpus: 1
cpu-type: crowded-core
ram: 4
name-v1: SCS-1V:4
name-v2: SCS-1V-4
- name: SCS-2V-8
cpus: 2
cpu-type: shared-core
ram: 8
name-v1: SCS-2V-8
name-v2: SCS-2V-8
- name: SCS-4V-16
cpus: 4
cpu-type: shared-core
ram: 12
name-v1: SCS-4V:16
name-v2: SCS-4V-16
- name: SCS-8V-32
cpus: 8
cpu-type: shared-core
ram: 32
name-v1: SCS-8V:32
name-v2: SCS-8V-32
- name: SCS-1V-2
cpus: 2
cpu-type: shared-core
ram: 2
name-v1: SCS-1V:2
name-v2: SCS-1V-2
- name: SCS-2V-4
cpus: 2
cpu-type: shared-core
ram: 4
name-v1: SCS-2V:4
name-v2: SCS-2V-4
- name: SCS-4V-8
cpus: 4
cpu-type: shared-core
ram: 8
name-v1: SCS-4V:8
name-v2: SCS-4V-8
- name: SCS-8V-16
cpus: 8
cpu-type: shared-core
ram: 16
name-v1: SCS-8V:16
name-v2: SCS-8V-16
- name: SCS-16V-32
cpus: 16
cpu-type: shared-core
ram: 32
name-v1: SCS-16V:32
name-v2: SCS-16V-32
- name: SCS-1V-8
cpus: 1
cpu-type: shared-core
ram: 8
name-v1: SCS-1V:8
name-v2: SCS-1V-8
- name: SCS-2V-16
cpus: 2
cpu-type: shared-core
ram: 16
name-v1: SCS-2V:16
name-v2: SCS-2V-16
- name: SCS-4V-32
cpus: 4
cpu-type: shared-core
ram: 32
name-v1: SCS-4V:32
name-v2: SCS-4V-32
- name: SCS-1L-1
cpus: 1
cpu-type: crowded-core
ram: 1
name-v1: SCS-1L:1
name-v2: SCS-1L-1
- status: mandatory
list:
- name: SCS-2V-4-20s
cpus: 2
cpu-type: shared-core
ram: 4
disk: 20
name-v1: SCS-2V:4:20s
name-v2: SCS-2V-4-20s
- name: SCS-4V-16-100s
cpus: 4
cpu-type: shared-core
ram: 16
disk: 10
disk0-type: ssd
name-v1: SCS-4V:16:100s
name-v2: SCS-4V-16-100s
- status: recommended
list:
- name: SCS-1V-4-10
cpus: 1
cpu-type: shared-core
ram: 4
disk: 10
name-v1: SCS-1V:4:10
name-v2: SCS-1V-4-10
- name: SCS-2V-8-20
cpus: 2
cpu-type: shared-core
ram: 8
disk: 20
name-v1: SCS-2V:8:20
name-v2: SCS-2V-8-20
- name: SCS-4V-16-50
cpus: 4
cpu-type: shared-core
ram: 16
disk: 50
name-v1: SCS-4V:16:50
name-v2: SCS-4V-16-50
- name: SCS-8V-32-100
cpus: 8
cpu-type: shared-core
ram: 32
disk: 100
name-v1: SCS-8V:32:100
name-v2: SCS-8V-32-100
- name: SCS-1V-2-5
cpus: 1
cpu-type: shared-core
ram: 2
disk: 5
name-v1: SCS-1V:2:5
name-v2: SCS-1V-2-5
- name: SCS-2V-4-10
cpus: 2
cpu-type: shared-core
ram: 4
disk: 10
name-v1: SCS-2V:4:10
name-v2: SCS-2V-4-10
- name: SCS-4V-8-20
cpus: 4
cpu-type: shared-core
ram: 8
disk: 20
name-v1: SCS-4V:8:20
name-v2: SCS-4V-8-20
- name: SCS-8V-16-50
cpus: 8
cpu-type: shared-core
ram: 16
disk: 50
name-v1: SCS-8V:16:50
name-v2: SCS-8V-16-50
- name: SCS-16V-32-100
cpus: 16
cpu-type: shared-core
ram: 32
disk: 100
name-v1: SCS-16V:32:100
name-v2: SCS-16V-32-100
- name: SCS-1V-8-20
cpus: 1
cpu-type: shared-core
ram: 8
disk: 20
name-v1: SCS-1V:8:20
name-v2: SCS-1V-8-20
- name: SCS-2V-16-50
cpus: 2
cpu-type: shared-core
ram: 16
disk: 50
name-v1: SCS-2V:16:50
name-v2: SCS-2V-16-50
- name: SCS-4V-32-100
cpus: 4
cpu-type: shared-core
ram: 32
disk: 100
name-v1: SCS-4V:32:100
name-v2: SCS-4V-32-100
- name: SCS-1L-1-5
cpus: 1
cpu-type: crowded-core
ram: 1
disk: 5
name-v1: SCS-1L:1:5
name-v2: SCS-1L-1-5
11 changes: 9 additions & 2 deletions playbooks/adr_syntax.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Run ADR syntax check tool
- name: Run ADR syntax check tool and test script consistency check tool
hosts: all
roles:
- role: ensure-pip # https://zuul-ci.org/docs/zuul-jobs/latest/python-roles.html#role-ensure-pip
Expand All @@ -22,12 +22,19 @@
ansible.builtin.pip:
requirements: /home/ubuntu/Tests/requirements.txt

- name: Run check script
- name: Run ADR syntax check script
ansible.builtin.command:
cmd: python3 /home/ubuntu/Tests/chk_adrs.py /home/ubuntu/Standards
register: result
changed_when: true
failed_when: result.rc != 0

- name: Run test script consistency check script
ansible.builtin.command:
cmd: python3 /home/ubuntu/Tests/iaas/flavor-naming/check-yaml.py /home/ubuntu/Tests/iaas
register: result
changed_when: true
failed_when: result.rc != 0

- ansible.builtin.debug:
msg: "{{ result.stdout }} {{ result.stderr }}"

0 comments on commit 7f2766e

Please sign in to comment.