Zero sizes qoutas caused incorrect size matching

* this adds a few extras cases for quota size matching
  to avoid/handle zero quotas as they are a valid use case.

Change-Id: I1d7b63b79b60c4c37a3a356e5410b44e0f9b078c
Closes-Bug: 1737118
This commit is contained in:
Adrian Turjak
2017-12-08 21:21:55 +13:00
committed by Amelia Cordwell
parent 1da1930d97
commit c73b56f918
2 changed files with 90 additions and 4 deletions

View File

@@ -52,8 +52,15 @@ class QuotaManager(object):
for service_name, values in setting.items():
for name, value in values.items():
if value != 0:
match_percentages.append(
float(current_quota[service_name][name]) / value)
try:
current = current_quota[service_name][name]
match_percentages.append(float(current) / value)
except KeyError:
pass
elif current_quota[service_name][name] == 0:
match_percentages.append(1.0)
else:
match_percentages.append(0.0)
# Calculate the average of how much it matches the setting
difference = abs(
(sum(match_percentages) / float(len(match_percentages))) - 1)