Skip to content

Commit 1c8a86d

Browse files
committed
after pruning: remove unused code
Signed-off-by: Matthias Büchse <[email protected]>
1 parent ec13af7 commit 1c8a86d

File tree

2 files changed

+15
-92
lines changed

2 files changed

+15
-92
lines changed

Tests/iaas/flavor-naming/flavor-names-openstack.py

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ def main(argv):
4646
fnmck = flavor_names.CompatLayer()
4747
cloud = None
4848
verbose = False
49-
v3mode = False
50-
accept_old_mand = False
51-
scsMandFile = fnmck.mandFlavorFile
5249

5350
try:
5451
cloud = os.environ["OS_CLOUD"]
@@ -67,16 +64,17 @@ def main(argv):
6764
elif opt[0] == "-c" or opt[0] == "--os-cloud":
6865
cloud = opt[1]
6966
elif opt[0] == "-C" or opt[0] == "--mand":
70-
scsMandFile = opt[1]
67+
if opt[1].split('/')[-1] != 'scs-0100-v3-flavors.yaml':
68+
print(f'ignoring obsolete argument: {opt[0]}', file=sys.stderr)
7169
elif opt[0] == "-3" or opt[0] == "--v3":
7270
# fnmck.disallow_old = True
73-
v3mode = True
71+
print(f'ignoring obsolete argument: {opt[0]}', file=sys.stderr)
7472
elif opt[0] == "-2" or opt[0] == "--v2plus":
7573
fnmck.disallow_old = True
7674
elif opt[0] == "-1" or opt[0] == "--v1prefer":
77-
fnmck.prefer_old = True
75+
print(f'ignoring obsolete argument: {opt[0]}', file=sys.stderr)
7876
elif opt[0] == "-o" or opt[0] == "--accept-old-mandatory":
79-
accept_old_mand = True
77+
print(f'ignoring obsolete argument: {opt[0]}', file=sys.stderr)
8078
elif opt[0] == "-v" or opt[0] == "--verbose":
8179
verbose = True
8280
elif opt[0] == "-q" or opt[0] == "--quiet":
@@ -87,17 +85,13 @@ def main(argv):
8785
print(f"CRITICAL: Extra arguments {str(args)}", file=sys.stderr)
8886
usage(1)
8987

90-
scsMandatory, scsRecommended = fnmck.readflavors(scsMandFile, v3mode)
91-
9288
if not cloud:
9389
print("CRITICAL: You need to have OS_CLOUD set or pass --os-cloud=CLOUD.", file=sys.stderr)
9490
sys.exit(1)
9591
conn = openstack.connect(cloud=cloud, timeout=32)
9692
flavors = conn.compute.flavors()
9793

9894
# Lists of flavors: mandatory, good-SCS, bad-SCS, non-SCS, with-warnings
99-
MSCSFlv = []
100-
RSCSFlv = []
10195
SCSFlv = []
10296
wrongFlv = []
10397
nonSCSFlv = []
@@ -171,77 +165,35 @@ def main(argv):
171165
wrongFlv.append(flv.name)
172166
errors += 1
173167
else:
174-
if flv.name in scsMandatory:
175-
scsMandatory.remove(flv.name)
176-
MSCSFlv.append(flv.name)
177-
elif flv.name in scsRecommended:
178-
scsRecommended.remove(flv.name)
179-
RSCSFlv.append(flv.name)
180-
elif accept_old_mand and fnmck.old_to_new(flv.name) in scsMandatory:
181-
scsMandatory.remove(fnmck.old_to_new(flv.name))
182-
MSCSFlv.append(flv.name) # fnmck.old_to_new(flv.name)
183-
elif accept_old_mand and fnmck.old_to_new(flv.name) in scsRecommended:
184-
scsRecommended.remove(fnmck.old_to_new(flv.name))
185-
RSCSFlv.append(flv.name) # fnmck.old_to_new(flv.name)
186-
else:
187-
SCSFlv.append(flv.name)
168+
SCSFlv.append(flv.name)
188169
if warn:
189170
warnFlv.append(flv.name)
190171
# This makes the output more readable
191-
MSCSFlv.sort()
192-
RSCSFlv.sort()
193172
SCSFlv.sort()
194173
nonSCSFlv.sort()
195174
wrongFlv.sort()
196175
warnFlv.sort()
197-
# We have counted errors on the fly, add missing flavors to the final result
198-
for fn in scsMandatory:
199-
errors += 1
200-
print(f"ERROR: Missing mandatory flavor: {fn}", file=sys.stderr)
201176
# Produce dicts for YAML reporting
202177
flvSCSList = {
203-
"MandatoryFlavorsPresent": MSCSFlv,
204-
"MandatoryFlavorsMissing": scsMandatory,
205-
}
206-
if v3mode:
207-
flvSCSList.update({
208-
"RecommendedFlavorsPresent": RSCSFlv,
209-
"RecommendedFlavorsMissing": scsRecommended,
210-
})
211-
flvSCSList.update({
212-
"OptionalFlavorsValid": SCSFlv,
213-
"OptionalFlavorsWrong": wrongFlv,
178+
"SCSFlavorsValid": SCSFlv,
179+
"SCSFlavorsWrong": wrongFlv,
214180
"FlavorsWithWarnings": warnFlv,
215-
})
181+
}
216182
flvOthList = {
217183
"OtherFlavors": nonSCSFlv
218184
}
219185
flvSCSRep = {
220-
"TotalAmount": len(MSCSFlv) + len(SCSFlv) + len(wrongFlv),
221-
}
222-
# skip the following if no mandatory flavors are given (useful for v3.2 onward)
223-
if len(MSCSFlv) + len(scsMandatory):
224-
flvSCSRep.update({
225-
"MandatoryFlavorsPresent": len(MSCSFlv),
226-
"MandatoryFlavorsMissing": len(scsMandatory),
227-
})
228-
# skip the following if no recommended flavors are given (useful for v1, v2, and v3.2 onward)
229-
if len(RSCSFlv) + len(scsRecommended):
230-
flvSCSRep.update({
231-
"RecommendedFlavorsPresent": len(RSCSFlv),
232-
"RecommendedFlavorsMissing": len(scsRecommended),
233-
})
234-
flvSCSRep.update({
235-
"FlavorsValid": len(SCSFlv) + len(MSCSFlv) + len(RSCSFlv),
186+
"TotalAmount": len(SCSFlv) + len(wrongFlv),
187+
"FlavorsValid": len(SCSFlv),
236188
"FlavorsWrong": len(wrongFlv),
237189
"FlavorsWithWarnings": len(warnFlv),
238-
})
190+
}
239191
flvOthRep = {
240192
"TotalAmount": len(nonSCSFlv),
241193
}
242194
totSummary = {
243195
"Errors": errors,
244-
"Warnings": len(warnFlv)+len(scsRecommended),
196+
"Warnings": len(warnFlv),
245197
}
246198
Report = {cloud: {"TotalSummary": totSummary}}
247199
if not fnmck.quiet:

Tests/iaas/flavor-naming/flavor_names.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,7 @@ def __init__(self):
757757
self.debug = False
758758
self.quiet = False
759759
self.disallow_old = False
760-
self.prefer_old = False
761760
self.v3_flv = False
762-
self.mandFlavorFile = str(Path(HERE.parent, "SCS-Spec.MandatoryFlavors.yaml"))
763761
bindir = os.path.basename(sys.argv[0])
764762
self.searchpath = (bindir, ) if bindir else os.environ['PATH'].split(':')
765763

@@ -783,8 +781,8 @@ def parsename(self, namestr: str) -> Optional[Flavorname]:
783781
is_old = True
784782
if not is_old:
785783
raise
786-
if not self.quiet and flavorname is not None and self.prefer_old != is_old:
787-
print(f"WARNING: flavor name not v{2 - self.prefer_old}: {namestr}")
784+
if not self.quiet and flavorname is not None and is_old:
785+
print(f"WARNING: flavor name not v2: {namestr}")
788786
return flavorname
789787

790788
def outname(self, flavorname):
@@ -796,33 +794,6 @@ def old_to_new(self, nm):
796794
def new_to_old(self, nm):
797795
return SyntaxV1.from_v2(nm)
798796

799-
def findflvfile(self, fnm):
800-
"""Search for flavor file and return found path"""
801-
if os.path.isfile(fnm):
802-
return fnm
803-
raise RuntimeError(f"Flavor yaml file not found: {fnm}")
804-
805-
def readflavors(self, fnm, v3mode):
806-
"""Read mandatory and recommended flavors from passed YAML file"""
807-
fnm = self.findflvfile(fnm)
808-
if self.debug:
809-
print(f"DEBUG: Reading flavors from {fnm}")
810-
with open(fnm, "r", encoding="UTF-8)") as fobj:
811-
yamldict = yaml.safe_load(fobj)
812-
# Translate to old names in-place
813-
if self.prefer_old:
814-
for name_type in yamldict["SCS-Spec"].values():
815-
for i, name in enumerate(name_type):
816-
name_type[i] = self.new_to_old(name)
817-
mand = yamldict["SCS-Spec"]["MandatoryFlavors"]
818-
recd = yamldict["SCS-Spec"]["RecommendedFlavors"]
819-
if v3mode:
820-
mand.extend(yamldict["SCS-Spec"].get("MandatoryFlavorsV3", ()))
821-
recd.extend(yamldict["SCS-Spec"].get("RecommendedFlavorsV3", ()))
822-
return mand, recd
823-
else:
824-
return [*mand, *recd], []
825-
826797

827798
if __name__ == "__main__":
828799
namestr = "SCS-16T-64-3x10s_bms_hwv_i3h_GNa-64_ib"

0 commit comments

Comments
 (0)