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
This commit is contained in:
Neels Hofmeyr 2017-06-06 19:47:40 +02:00
parent 31e83200b2
commit a8a05a2e23
2 changed files with 13 additions and 4 deletions

View File

@ -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')

View File

@ -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