Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Büchse <matthias.buechse@cloudandheat.com>
  • Loading branch information
mbuechse committed Jan 26, 2024
1 parent fdc8e76 commit 763d480
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Tests/iaas/flavor-naming/flavor-form.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def output_generate(namestr, flavorname, error):
if not namestr:
return
print(f"\t<br/><font size=+1 color=blue><b>SCS flavor name: <tt>{html.escape(namestr, quote=True)}</tt></b>")
altname = outname(Flavorname(cpuram=flavorname.cpuram, disk=flavorname.disk, gpu=flavorname.gpu, ib=flavorname.ib))
altname = outname(flavorname.shorten())
print(f"\t<br/><b>Short SCS flavor name: <tt>{html.escape(altname, quote=True)}</tt></b></font>")


Expand Down
23 changes: 9 additions & 14 deletions Tests/iaas/flavor-naming/flavor_name_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ def __init__(
self.gpu = gpu
self.ib = ib

def shorten(self):
"""return canonically shortened name as recommended in the standard"""
if self.hype is None and self.hwvirt is None and self.cpubrand is None:
return self
return Flavorname(cpuram=self.cpuram, disk=self.disk, gpu=self.gpu, ib=self.ib)


class Outputter:
"""
Expand Down Expand Up @@ -402,7 +408,6 @@ def __call__(self, s: str, pos=0) -> Flavorname:
flavorname.gpu = self.gpu.parse(ctx)
flavorname.ib = self.ib.parse(ctx)
if ctx.pos != len(s):
print(outputter(flavorname))
raise ValueError(f"Failed to parse name {s} to completion; remainder: {s[ctx.pos:]}")
return flavorname

Expand All @@ -414,16 +419,7 @@ def __call__(self, s: str, pos=0) -> Flavorname:

class CompatLayer:
"""
This class provides the functionality that was previously imported via
fnmck = importlib.import_module("flavor-name-check")
Instead, you now do
fnmck = CompatLayer()
A few adaptation are necessary though because this package uses `Flavorname`
instead of the old `tuple` of `Prop`s.
This class provides convenience functions previously found in `flavor-name-check.py`.
"""
def __init__(self):
self.verbose = False
Expand Down Expand Up @@ -504,7 +500,6 @@ def readflavors(self, fnm, v3mode):


if __name__ == "__main__":
namestr = "SCS-16T-64-3x10_GNa-64_ib"
print(namestr)
print(outputter(parser_v1("SCS-16T:64:3x10s-GNa:64-ib")))
namestr = "SCS-16T-64-3x10s_bms_hwv_i3h_GNa-64_ib"
print(outputter(parser_v1("SCS-16T:64:3x10s-GNa:64-ib")) == outputter(parser_v2(namestr).shorten()))
print(namestr == outputter(parser_v2(namestr)))

0 comments on commit 763d480

Please sign in to comment.