error log: clarify for reserving more resources than available
When trying to reserve more resources than available in the resources.conf,
actually print an intelligible error message: catch the nameless error from
solve() and fill in what was requested for solution.
Change-Id: Iba3707f1aaeb40a58c616c33af52a60c9a2e7e1f
diff --git a/selftest/resource_test.py b/selftest/resource_test.py
index 08f1fbf..c78485e 100755
--- a/selftest/resource_test.py
+++ b/selftest/resource_test.py
@@ -39,7 +39,7 @@
[2],
[0, 2] ])
assert False
-except resource.NoResourceExn as e:
+except resource.NotSolvable as e:
print(e)
print('- test removing a Resources list from itself')
diff --git a/src/osmo_gsm_tester/resource.py b/src/osmo_gsm_tester/resource.py
index 3e8924a..52b23c7 100644
--- a/src/osmo_gsm_tester/resource.py
+++ b/src/osmo_gsm_tester/resource.py
@@ -337,7 +337,13 @@
continue
# figure out who gets what
- solution = solve(all_matches)
+ try:
+ solution = solve(all_matches)
+ except NotSolvable:
+ # instead of a cryptic error message, raise an exception that
+ # conveys meaning to the user.
+ raise NoResourceExn('Could not resolve request to reserve resources: '
+ '%d x %s with requirements: %r' % (len(want_list), key, want_list))
picked = [ my_list[i] for i in solution if i is not None ]
for_origin.dbg('Picked', config.tostr(picked))
matches[key] = picked
@@ -365,6 +371,9 @@
item[RESERVED_KEY] = origin_id
+class NotSolvable(Exception):
+ pass
+
def solve(all_matches):
'''
all_matches shall be a list of index-lists.
@@ -403,8 +412,8 @@
solution = search_in_permutations()
if not solution:
- raise NoResourceExn('The requested resource requirements are not solvable %r'
- % all_matches)
+ raise NotSolvable('The requested resource requirements are not solvable %r'
+ % all_matches)
return solution