Skip to content

Commit

Permalink
Yet another intermediate revision
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Büchse <[email protected]>
  • Loading branch information
mbuechse committed Jan 23, 2024
1 parent ef57873 commit 88c51ac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 58 deletions.
25 changes: 11 additions & 14 deletions Tests/iaas/flavor-naming/check-yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
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

flavor_name_check = importlib.import_module("flavor-name-check")
flavor_name_check.disallow_old = True
from flavor_name_check import parser_v2, SyntaxV1


REQUIRED_FIELDS = ['name-v1', 'name-v2', 'name', 'cpus', 'ram', 'cpu-type']
Expand Down Expand Up @@ -52,24 +50,23 @@ def check_spec(self, flavor_spec):
return
name = flavor_spec['name']
name_v2 = flavor_spec['name-v2']
parsed = flavor_name_check.parsename(name_v2)
if not parsed:
flavorname = parser_v2(name_v2)
if not flavorname:
self.emit(f"flavor {name}: name-v2 '{name_v2}' could not be parsed")
return
cpu, disk, hype, hvirt, cpubrand, gpu, ibd = parsed
undefined = Undefined()
expected = {
'cpus': cpu.cpus,
'cpu-type': CPUTYPE_KEY[cpu.cputype],
'ram': cpu.ram,
'name-v1': flavor_name_check.new_to_old(name_v2),
'cpus': flavorname.cpuram.cpus,
'cpu-type': CPUTYPE_KEY[flavorname.cpuram.cputype],
'ram': flavorname.cpuram.ram,
'name-v1': SyntaxV1.from_v2(name_v2),
'disk': undefined,
}
if disk.parsed:
if disk.nrdisks != 1:
if flavorname.disk:
if flavorname.disk.nrdisks != 1:
self.emit(f"flavor '{name}': name-v2 using multiple disks")
expected['disk'] = disk.disksize
expected['disk0-type'] = DISKTYPE_KEY[disk.disktype or 'n']
expected['disk'] = flavorname.disk.disksize
expected['disk0-type'] = DISKTYPE_KEY[flavorname.disk.disktype or 'n']
for key, exp_val in expected.items():
val = flavor_spec.get(key, DEFAULTS.get(key, undefined))
if val != exp_val:
Expand Down
22 changes: 3 additions & 19 deletions Tests/iaas/flavor-naming/flavor-name-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
"""Flavor naming checker
https://github.com/SovereignCloudStack/standards/Test/iaas/flavor-naming/
Return codes:
0: Matching
1: No SCS flavor
10-19: Error in CPU:Ram spec
20-29: Error in Disk spec
30-39: Error in Hype spec
40-49: Error in optional -hwv support
50-59: Error in optional specific CPU description
60-69: Error in optional GPU spec
70-79: Unknown extension
When checking a list of flavors for completeness with respect
to mandatory flavors, we disregard non-scs flavors (code 1 above)
and only report the number of missing flavors or -- if none was found --
the sum of parsing errors (>=10) according to above scheme.
(c) Kurt Garloff <[email protected]>, 5/2021
(c) Matthias Büchse <[email protected]>, 1/2024
License: CC-BY-SA 4.0
Expand All @@ -34,7 +18,7 @@
def usage():
"help"
print("Usage: flavor-name-check.py [-d] [-v] [-2] [-1] [-o] [-c] [-C mand.yaml] [-i | NAME [NAME [...]]]")
print("Flavor name checker returns 0 if no error, 1 for non SCS flavors and 10+ for wrong flavor names")
print("Flavor name checker returns 0 if no error, otherwise check stderr for details")
print("-d enables debug mode, -v outputs a verbose description, -i enters interactive input mode")
print("-2 disallows old v1 flavor naming, -1 checks old names for completeness, -o accepts them still")
print("-c checks the SCS names AND checks the list for completeness w.r.t. SCS mandatory flavors.")
Expand Down Expand Up @@ -66,8 +50,8 @@ def input_component(self, targetcls):
tbl = attr.get_tbl(target)
if tbl:
print(f" {fdesc} Options:")
for key in tbl.keys():
print(f" {key}: {tbl[key]}")
for key, v in tbl.items():
print(f" {key}: {v}")
while True:
print(f" {fdesc}: ", end="")
val = input()
Expand Down
8 changes: 3 additions & 5 deletions Tests/iaas/flavor-naming/flavor-names-openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
provided by openstack, such as the number of vCPUs and memory.
(c) Kurt Garloff <[email protected]>, 12/2022
(c) Matthias Büchse <[email protected]>, 1/2024
SPDX-License-Identifier: CC-BY-SA 4.0
"""

Expand All @@ -24,8 +25,6 @@

import flavor_name_check

fnmck = flavor_name_check.CompatLayer()


def usage(rcode=1):
"help output"
Expand All @@ -44,10 +43,9 @@ def usage(rcode=1):


def main(argv):
"Entry point -- main loop going over flavors"
"""Entry point -- main loop going over flavors"""
fnmck = flavor_name_check.CompatLayer()
cloud = None
verbose = False
quiet = False
v3mode = False
accept_old_mand = False
scsMandFile = fnmck.mandFlavorFile
Expand Down
45 changes: 25 additions & 20 deletions Tests/iaas/flavor-naming/flavor_name_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class GPU:
"""Class repesenting GPU support"""
type = "GPU"
gputype = TblAttr(".Type", {"g": "vGPU", "G": "Pass-Through GPU"})
brand = TblAttr(".Brand", {'': '', "N": "nVidia", "A": "AMD", "I": "Intel"})
brand = TblAttr("Brand", {"N": "nVidia", "A": "AMD", "I": "Intel"})
gen = DepTblAttr(".Gen", brand, {
'': {'': ''},
"N": {'': '', "f": "Fermi", "k": "Kepler", "m": "Maxwell", "p": "Pascal",
Expand Down Expand Up @@ -285,6 +285,9 @@ def __call__(self, flavorname):


class SyntaxV1:
"""
This class bundles the regular expressions that comprise the syntax for v1 of the standard.
"""
prefix = "SCS-"
cpuram = re.compile(r"([0-9]*)([LVTC])(i|):([0-9\.]*)(u|)(o|)")
disk = re.compile(r":(?:([0-9]*)x|)([0-9]*)([nhsp]|)")
Expand All @@ -295,8 +298,21 @@ class SyntaxV1:
gpu = re.compile(r"\-([gG])([NAI])([^:-h]*)(?::([0-9]+)|)(h*)")
ib = re.compile(r"\-(ib)")

@classmethod
def from_v2(nm):
"""v2 to v1 flavor name transformation"""
return nm.replace('-', ':').replace('_', '-').replace('SCS:', 'SCS-')


class SyntaxV2:
"""
This class bundles the regular expressions that comprise the syntax for v2 of the standard.
The change vs. v1 concerns the delimiters only and is best understood by looking at
the classmethods `SyntaxV2.from_v1` and `SyntaxV1.from_v2`.
Note that the syntax hasn't changed since v2, so this class is still valid.
"""
prefix = "SCS-"
cpuram = re.compile(r"([0-9]*)([LVTC])(i|)\-([0-9\.]*)(u|)(o|)")
disk = re.compile(r"\-(?:([0-9]*)x|)([0-9]*)([nhsp]|)")
Expand All @@ -307,6 +323,11 @@ class SyntaxV2:
gpu = re.compile(r"_([gG])([NAI])([^-h]*)(?:\-([0-9]+)|)(h*)")
ib = re.compile(r"_(ib)")

@classmethod
def from_v1(nm):
"""v1 to v2 flavor name transformation"""
return nm.replace('-', '_').replace(':', '-').replace('SCS_', 'SCS-')


class ComponentParser:
def __init__(self, parsestr, targetcls):
Expand Down Expand Up @@ -367,22 +388,6 @@ def __call__(self, s, pos=0):
outputter = Outputter()


def new_to_old(nm):
"v2 to v1 flavor name transformation"
nm = nm.replace('-', ':')
nm = nm.replace('_', '-')
nm = nm.replace('SCS:', 'SCS-')
return nm


def old_to_new(nm):
"v1 to v2 flavor name transformation"
nm = nm.replace('-', '_')
nm = nm.replace(':', '-')
nm = nm.replace('SCS_', 'SCS-')
return nm


class CompatLayer:
"""
This class provides the functionality that was previously imported via
Expand Down Expand Up @@ -435,10 +440,10 @@ def outname(self, flavorname):
return outputter(flavorname)

def old_to_new(self, nm):
return old_to_new(nm)
return SyntaxV2.from_v1(nm)

def new_to_old(self, nm):
return new_to_old(nm)
return SyntaxV1.from_v2(nm)

def findflvfile(self, fnm):
"""Search for flavor file and return found path"""
Expand All @@ -463,7 +468,7 @@ def readflavors(self, fnm, v3mode):
if self.prefer_old:
for name_type in yamldict["SCS-Spec"].values():
for i, name in enumerate(name_type):
name_type[i] = new_to_old(name)
name_type[i] = self.new_to_old(name)
mand = yamldict["SCS-Spec"]["MandatoryFlavors"]
recd = yamldict["SCS-Spec"]["RecommendedFlavors"]
if v3mode:
Expand Down

0 comments on commit 88c51ac

Please sign in to comment.