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 22, 2024
1 parent 20a37d2 commit af662fd
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 165 deletions.
11 changes: 0 additions & 11 deletions Tests/iaas/flavor-naming/flavor-name-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,17 +626,6 @@ def old_to_new(nm):
return nm


def is_ssd_flavor(name):
"""Look at the disk object of a parsed flavor name and return true
if it has an SSD root disk.
This can be used to filter out the new v3 SSD flavors"""
try:
disk = parsename(name)[1]
return disk and disk.parsed and disk.disktype == "s"
except NameError:
return False


def findflvfile(fnm):
"Search for flavor file and return found path"
searchpath = (".", "..", *_bindir, _bindir[0] + "/..", '/opt/share/SCS')
Expand Down
74 changes: 36 additions & 38 deletions Tests/iaas/flavor-naming/flavor-name-describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

import sys

import flavor_name_check

fnmck = flavor_name_check.CompatLayer()


def collectattrs(alist, new):
"collect list of attitbutes"
Expand All @@ -23,73 +27,67 @@ def collectattrs(alist, new):
return alist


def tbl_out(item, kind, check = False):
"Look up table value (attach space), skip if entry is 0 or empty string and check is set"
val = item.__getattribute__(kind)
def tbl_out(item, kind, check=False):
"""Look up table value (attach space), skip if entry is 0 or empty string and check is set"""
val = getattr(item, kind)
if check and not val:
return ""
try:
return item.__getattribute__("tbl_"+kind)[val] + " "
return getattr(item.__class__, kind).get_tbl(item)[val] + " "
except KeyError:
return str(val) + " "


def prettyname(item_list, prefix=""):
"Output a human-readable flavor description"
cpu, disk, hype, hvirt, cpubrand, gpu, ibd = item_list
def prettyname(flavorname, prefix=""):
"""Output a human-readable flavor description"""
# CPU (number, type, attributes)
stg = f"{prefix}SCS flavor with {cpu.cpus} "
if cpubrand.parsed:
stg += tbl_out(cpubrand, "perf", True)
stg += tbl_out(cpubrand, "cpuvendor")
stg += tbl_out(cpubrand, "cpugen", True)
stg = f"{prefix}SCS flavor with {flavorname.cpuram.cpus} "
if flavorname.cpubrand:
stg += tbl_out(flavorname.cpubrand, "perf", True)
stg += tbl_out(flavorname.cpubrand, "cpuvendor")
stg += tbl_out(flavorname.cpubrand, "cpugen", True)
else:
stg += "generic x86-64 "
stg += tbl_out(cpu, "cputype")
if cpu.cpuinsecure:
stg += tbl_out(flavorname.cpuram, "cputype")
if flavorname.cpuram.cpuinsecure:
stg += "(insecure) "
# RAM (amount, attributes)
stg += f"with {cpu.ram} GiB RAM "
stg += f"with {flavorname.cpuram.ram} GiB RAM "
alist = ""
if cpu.raminsecure:
if flavorname.cpuram.raminsecure:
alist = collectattrs(alist, "noECC")
if cpu.ramoversubscribed:
if flavorname.cpuram.ramoversubscribed:
alist = collectattrs(alist, "oversubscribed")
if alist:
stg += f"({alist}) "
# Hypervisor, HVirt
if hype.parsed:
stg += f'on {tbl_out(hype, "hype")}'
if hvirt.parsed:
if flavorname.hype:
stg += f'on {tbl_out(flavorname.hype, "hype")}'
if flavorname.hwvirt:
stg += 'with HW virt '
# Disk
if disk.parsed:
if flavorname.disk:
stg += "and "
stg += tbl_out(disk, "disktype", True)
if disk.nrdisks != 1:
stg += f'{disk.nrdisks}x'
stg += f'{disk.disksize}GB root volume '
stg += tbl_out(flavorname.disk, "disktype", True)
if flavorname.disk.nrdisks != 1:
stg += f'{flavorname.disk.nrdisks}x'
stg += f'{flavorname.disk.disksize}GB root volume '
# GPU
if gpu.parsed:
stg += "and " + tbl_out(gpu, "gputype")
stg += tbl_out(gpu, "brand")
stg += tbl_out(gpu, "perf", True)
try:
stg += gpu.__getattribute__(f"tbl_brand_{gpu.brand}_gen")[gpu.gen] + " "
except KeyError:
pass
if hasattr(gpu, "cu") and gpu.cu:
stg += f"(w/ {gpu.cu} CU/EU/SM) "
if flavorname.gpu:
stg += "and " + tbl_out(flavorname.gpu, "gputype")
stg += tbl_out(flavorname.gpu, "brand")
stg += tbl_out(flavorname.gpu, "perf", True)
stg += tbl_out(flavorname.gpu, "gen", True)
if flavorname.gpu.cu is not None:
stg += f"(w/ {flavorname.gpu.cu} CU/EU/SM) "
# IB
if ibd.parsed:
if flavorname.ib:
stg += "and Infiniband "
return stg[:-1]


def main(argv):
"Entry point for testing"
import importlib
fnmck = importlib.import_module("flavor-name-check")
for nm in argv:
ret = fnmck.parsename(nm)
if ret:
Expand Down
156 changes: 79 additions & 77 deletions Tests/iaas/flavor-naming/flavor-names-openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import os
import sys
import getopt
import importlib
import yaml
import openstack
fnmck = importlib.import_module("flavor-name-check")

import flavor_name_check

fnmck = flavor_name_check.CompatLayer()


def usage(rcode=1):
Expand All @@ -47,6 +49,7 @@ def main(argv):
verbose = False
quiet = False
v3mode = False
accept_old_mand = False
scsMandFile = fnmck.mandFlavorFile

try:
Expand Down Expand Up @@ -75,7 +78,7 @@ def main(argv):
elif opt[0] == "-1" or opt[0] == "--v1prefer":
fnmck.prefer_old = True
elif opt[0] == "-o" or opt[0] == "--accept-old-mandatory":
fnmck.accept_old_mand = True
accept_old_mand = True
elif opt[0] == "-v" or opt[0] == "--verbose":
verbose = True
# fnmck.verbose = True
Expand All @@ -88,7 +91,7 @@ def main(argv):
print(f"CRITICAL: Extra arguments {str(args)}", file=sys.stderr)
usage(1)

scsMandatory, scsRecommended = fnmck.readflavors(scsMandFile, v3mode, fnmck.prefer_old)
scsMandatory, scsRecommended = fnmck.readflavors(scsMandFile, v3mode)

if not cloud:
print("CRITICAL: You need to have OS_CLOUD set or pass --os-cloud=CLOUD.", file=sys.stderr)
Expand All @@ -112,83 +115,82 @@ def main(argv):
try:
ret = fnmck.parsename(flv.name)
assert ret
# We have a successfully parsed SCS- name now
# See if the OpenStack provided data fulfills what we
# expect from the flavor based on its name
err = 0
warn = 0
# Split list for readability
cpuram = ret[0]
disk = ret[1]
# next qwould be hype, hwvirt, cpubrand, gpu, ib
# see flavor-name-check.py: parsename()
# vCPUS
if flv.vcpus < cpuram.cpus:
print(f"ERROR: Flavor {flv.name} has only {flv.vcpus} vCPUs, "
f"should have >= {cpuram.cpus}", file=sys.stderr)
err += 1
elif flv.vcpus > cpuram.cpus:
print(f"WARNING: Flavor {flv.name} has {flv.vcpus} vCPUs, "
f"only needs {cpuram.cpus}", file=sys.stderr)
warn += 1
# RAM
flvram = int((flv.ram + 51) / 102.4) / 10
# Warn for strange sizes (want integer numbers, half allowed for < 10GiB)
if flvram >= 10 and flvram != int(flvram) or flvram * 2 != int(flvram * 2):
print(f"WARNING: Flavor {flv.name} uses discouraged uneven size "
f"of memory {flvram:%.1f} GiB", file=sys.stderr)
if flvram < cpuram.ram:
print(f"ERROR: Flavor {flv.name} has only {flvram:.1f} GiB RAM, "
f"should have >= {cpuram.ram:.1f} GiB", file=sys.stderr)
err += 1
elif flvram > cpuram.ram:
print(f"WARNING: Flavor {flv.name} has {flvram:.1f} GiB RAM, "
f"only needs {cpuram.ram:.1f} GiB", file=sys.stderr)
warn += 1
# DISK
accdisk = (0, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
# Disk could have been omitted
if not disk.parsed:
disk.disksize = 0
# We have a recommendation for disk size steps
if disk.disksize not in accdisk:
print(f"WARNING: Flavor {flv.name} advertizes disk size {disk.disksize}, "
f"should have (5, 10, 20, 50, 100, 200, ...)", file=sys.stderr)
warn += 1
if flv.disk < disk.disksize:
print(f"ERROR: Flavor {flv.name} has only {flv.disk} GB root disk, "
f"should have >= {disk.disksize} GB", file=sys.stderr)
err += 1
elif flv.disk > disk.disksize:
print(f"WARNING: Flavor {flv.name} has {flv.disk} GB root disk, "
f"only needs {disk.disksize} GB", file=sys.stderr)
warn += 1
# Ev'thing checked, react to errors by putting the bad flavors in the bad bucket
if err:
wrongFlv.append(flv.name)
errors += 1
else:
if flv.name in scsMandatory:
scsMandatory.remove(flv.name)
MSCSFlv.append(flv.name)
elif flv.name in scsRecommended:
scsRecommended.remove(flv.name)
RSCSFlv.append(flv.name)
elif fnmck.accept_old_mand and fnmck.old_to_new(flv.name) in scsMandatory:
scsMandatory.remove(fnmck.old_to_new(flv.name))
MSCSFlv.append(flv.name) # fnmck.old_to_new(flv.name)
elif fnmck.accept_old_mand and fnmck.old_to_new(flv.name) in scsRecommended:
scsRecommended.remove(fnmck.old_to_new(flv.name))
RSCSFlv.append(flv.name) # fnmck.old_to_new(flv.name)
else:
SCSFlv.append(flv.name)
if warn:
warnFlv.append(flv.name)
# Parser error
except NameError as exc:
except ValueError as exc:
errors += 1
wrongFlv.append(flv.name)
print(f"ERROR: Wrong flavor \"{flv.name}\": {exc}", file=sys.stderr)
continue
# We have a successfully parsed SCS- name now
# See if the OpenStack provided data fulfills what we
# expect from the flavor based on its name
err = 0
warn = 0
# Split list for readability
cpuram = ret.cpuram
# next qwould be hype, hwvirt, cpubrand, gpu, ib
# see flavor-name-check.py: parsename()
# vCPUS
if flv.vcpus < cpuram.cpus:
print(f"ERROR: Flavor {flv.name} has only {flv.vcpus} vCPUs, "
f"should have >= {cpuram.cpus}", file=sys.stderr)
err += 1
elif flv.vcpus > cpuram.cpus:
print(f"WARNING: Flavor {flv.name} has {flv.vcpus} vCPUs, "
f"only needs {cpuram.cpus}", file=sys.stderr)
warn += 1
# RAM
flvram = int((flv.ram + 51) / 102.4) / 10
# Warn for strange sizes (want integer numbers, half allowed for < 10GiB)
if flvram >= 10 and flvram != int(flvram) or flvram * 2 != int(flvram * 2):
print(f"WARNING: Flavor {flv.name} uses discouraged uneven size "
f"of memory {flvram:%.1f} GiB", file=sys.stderr)
if flvram < cpuram.ram:
print(f"ERROR: Flavor {flv.name} has only {flvram:.1f} GiB RAM, "
f"should have >= {cpuram.ram:.1f} GiB", file=sys.stderr)
err += 1
elif flvram > cpuram.ram:
print(f"WARNING: Flavor {flv.name} has {flvram:.1f} GiB RAM, "
f"only needs {cpuram.ram:.1f} GiB", file=sys.stderr)
warn += 1
# DISK
accdisk = (0, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
# Disk could have been omitted
disksize = ret.disk.disksize if ret.disk else 0
# We have a recommendation for disk size steps
if disksize not in accdisk:
print(f"WARNING: Flavor {flv.name} advertizes disk size {disksize}, "
f"should have (5, 10, 20, 50, 100, 200, ...)", file=sys.stderr)
warn += 1
if flv.disk < disksize:
print(f"ERROR: Flavor {flv.name} has only {flv.disk} GB root disk, "
f"should have >= {disksize} GB", file=sys.stderr)
err += 1
elif flv.disk > disksize:
print(f"WARNING: Flavor {flv.name} has {flv.disk} GB root disk, "
f"only needs {disksize} GB", file=sys.stderr)
warn += 1
# Ev'thing checked, react to errors by putting the bad flavors in the bad bucket
if err:
wrongFlv.append(flv.name)
errors += 1
else:
if flv.name in scsMandatory:
scsMandatory.remove(flv.name)
MSCSFlv.append(flv.name)
elif flv.name in scsRecommended:
scsRecommended.remove(flv.name)
RSCSFlv.append(flv.name)
elif accept_old_mand and fnmck.old_to_new(flv.name) in scsMandatory:
scsMandatory.remove(fnmck.old_to_new(flv.name))
MSCSFlv.append(flv.name) # fnmck.old_to_new(flv.name)
elif accept_old_mand and fnmck.old_to_new(flv.name) in scsRecommended:
scsRecommended.remove(fnmck.old_to_new(flv.name))
RSCSFlv.append(flv.name) # fnmck.old_to_new(flv.name)
else:
SCSFlv.append(flv.name)
if warn:
warnFlv.append(flv.name)
# This makes the output more readable
MSCSFlv.sort()
RSCSFlv.sort()
Expand Down
Loading

0 comments on commit af662fd

Please sign in to comment.