From c752af84a95eda399195bc4e15fcdcc85b602bf4 Mon Sep 17 00:00:00 2001 From: Kurt Garloff Date: Fri, 8 Dec 2023 11:31:33 +0100 Subject: [PATCH] Fix handling empty (optional) fields. Add short nm output. Signed-off-by: Kurt Garloff --- Tests/iaas/flavor-naming/flavor-form.py | 40 +++++++++++++++---- Tests/iaas/flavor-naming/flavor-name-check.py | 12 +++--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Tests/iaas/flavor-naming/flavor-form.py b/Tests/iaas/flavor-naming/flavor-form.py index 2324439e8..3061b4b6e 100755 --- a/Tests/iaas/flavor-naming/flavor-form.py +++ b/Tests/iaas/flavor-naming/flavor-form.py @@ -91,8 +91,9 @@ def generate_name(form): if idx2 < 0: ERROR = f"Can not find attribute {keypair[1]} in {keypair[1]}" return None - FLAVOR_SPEC[idx].parsed += 1 fdesc = FLAVOR_SPEC[idx].pnames[idx2] + if val and val != "" and val != "NN" and val != "0" and not (val == "1" and fdesc[0:2] == "#:"): + FLAVOR_SPEC[idx].parsed += 1 # Now parse fdesc to get the right value if fdesc[0:2] == '##': setattr(FLAVOR_SPEC[idx], keypair[1], float(val)) @@ -108,7 +109,12 @@ def generate_name(form): if val == "NN": val = "" setattr(FLAVOR_SPEC[idx], keypair[1], val) + # Eliminate empty features + for spec in FLAVOR_SPEC: + if spec.pnames[0][0] == '.' and not getattr(spec, spec.pattrs[0]): + spec.parsed = 0 FLAVOR_NAME = fnmck.outname(*FLAVOR_SPEC) + print(*FLAVOR_SPEC, file=sys.stderr, sep='\n') return FLAVOR_SPEC @@ -178,7 +184,14 @@ def is_checked(flag): return "" -def form_attr(attr, tblopt = True): +def keystr(key): + if key == "": + return "NN" + else: + return key + + +def form_attr(attr): """This mirrors flavor-name-check.py input(), but instead generates a web form. Defaults come from attr, the form is constructed from the attr's class attributes (like the mentioned input function). tblopt indicates whether @@ -206,19 +219,24 @@ def form_attr(attr, tblopt = True): if hasattr(spec, f"tbl_{fname}"): tbl = getattr(attr, f"tbl_{fname}") if tbl: - print(f'\t
') + tblopt = False + if fdesc[0] == '.': + tblopt = True + fdesc = fdesc[1:] + # print(f'\t
') + print(f'\t
') value_set = False for key in tbl.keys(): ischk = value == key value_set = value_set or ischk - print(f'\t ') + print(f'\t ') print(f'\t
') if tblopt: print(f'\t ') print(f'\t
') elif fdesc[0:2] == "##": # Float number => NUMBER - print(f'\t
') + print(f'\t
') print(f'\t ') elif fdesc[0] == "#": # Float number => NUMBER @@ -229,12 +247,18 @@ def form_attr(attr, tblopt = True): fdesc = fdesc[1:] elif fdesc[1] == '.': fdesc = fdesc[1:] - print(f'\t
') + print(f'\t
') print(f'\t ') elif fdesc[0] == "?": # Bool => Checkbox print(f'\t ') print(f'\t ') + else: + # FIXME: Handle dependent tables + if fdesc[0] == '.': + fdesc = fdesc[1:] + print(f'\t
') + print(f'\t ') if fdesc[0] != "?" or i == len(spec.pnames)-1 or spec.pnames[i+1][0] != "?": print('\t ') else: @@ -252,7 +276,7 @@ def output_generate(): print(f'\tERROR: {html.escape(ERROR, quote=True)}') return print('\t
\n\t
') - form_attr(cpu, False) + form_attr(cpu) print('\t
The following settings are all optional and (except for disk) meant for highly specialized / differentiated offerings.
') print('\t') form_attr(disk) @@ -267,6 +291,8 @@ def output_generate(): print('\t') if FLAVOR_NAME: print(f"\t
Flavor {html.escape(FLAVOR_NAME, quote=True)}") + altname = fnmck.outname(cpu, disk, None, None, None, gpu, ibd) + print(f"\t
Short Flavor name {html.escape(altname, quote=True)}") else: print(f'\tERROR: {html.escape(ERROR, quote=True)}') diff --git a/Tests/iaas/flavor-naming/flavor-name-check.py b/Tests/iaas/flavor-naming/flavor-name-check.py index f0fd63b54..de16d33b7 100755 --- a/Tests/iaas/flavor-naming/flavor-name-check.py +++ b/Tests/iaas/flavor-naming/flavor-name-check.py @@ -492,17 +492,17 @@ def outname(cpuram, disk, hype, hvirt, cpubrand, gpu, ibd): "Return name constructed from tuple" # TODO SCSx: Differentiate b/w SCS- and SCSx- out = "SCS-" + cpuram.out() - if disk.parsed: + if disk and disk.parsed: out += "-" + disk.out() - if hype.parsed: + if hype and hype.parsed: out += "_" + hype.out() - if hvirt.parsed: + if hvirt and hvirt.parsed: out += "_" + hvirt.out() - if cpubrand.parsed: + if cpubrand and cpubrand.parsed: out += "_" + cpubrand.out() - if gpu.parsed: + if gpu and gpu.parsed: out += "_" + gpu.out() - if ibd.parsed: + if ibd and ibd.parsed: out += "_" + ibd.out() return out