aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-06-06 19:47:40 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-06-07 19:53:28 +0200
commita8a05a2e23770615a5ad96ff1cb33c373f306928 (patch)
tree502fd20f36bb1f0f0fe2d53a067daaccc6c22d46
parent31e83200b21ab0c09112cb2815438e6259f1c874 (diff)
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
-rwxr-xr-xselftest/resource_test.py2
-rw-r--r--src/osmo_gsm_tester/resource.py15
2 files changed, 13 insertions, 4 deletions
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 @@ try:
[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 @@ class Resources(dict):
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 @@ class Resources(dict):
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 @@ def solve(all_matches):
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