2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 02:52:07 +00:00

Provide more detail in invalidargument

invalidargument was not particularly helpful by itself
improve things by adding more helpful information in the error strings.
This commit is contained in:
Jarrod Johnson 2014-05-09 17:18:17 -04:00
parent 3443a73558
commit 2d0fde3f42
3 changed files with 37 additions and 20 deletions

View File

@ -206,6 +206,8 @@ currchildren = None
def print_result(res):
if 'errorcode' in res:
return
for key in res.iterkeys():
notes = []
if res[key] is None:

View File

@ -253,7 +253,7 @@ class InputAttributes(ConfluentMessage):
self.nodeattribs = {}
nestedmode = False
if not inputdata:
raise exc.InvalidArgumentException
raise exc.InvalidArgumentException('no request data provided')
if nodes is None:
self.attribs = inputdata
for attrib in self.attribs:
@ -316,22 +316,29 @@ class InputPowerMessage(ConfluentMessage):
def __init__(self, path, nodes, inputdata):
self.powerbynode = {}
if not inputdata:
raise exc.InvalidArgumentException()
raise exc.InvalidArgumentException('missing input data')
if 'state' not in inputdata:
#assume we have nested information
for key in nodes:
if key not in inputdata:
raise exc.InvalidArgumentException()
raise exc.InvalidArgumentException(key + ' not in request')
datum = inputdata[key]
if ('state' not in datum or
datum['state'] not in self.valid_values):
raise exc.InvalidArgumentException()
if 'state' not in datum:
raise exc.InvalidArgumentException(
'missing state argument')
elif datum['state'] not in self.valid_values:
raise exc.InvalidArgumentException(
datum['state'] + ' is not one of ' +
','.join(self.valid_values))
self.powerbynode[key] = datum['state']
else: # we have a state argument not by node
datum = inputdata
if ('state' not in datum or
datum['state'] not in self.valid_values):
raise exc.InvalidArgumentException()
if 'state' not in datum:
raise exc.InvalidArgumentException('missing state argument')
elif datum['state'] not in self.valid_values:
raise exc.InvalidArgumentException(datum['state'] +
' is not one of ' +
','.join(self.valid_values))
for node in nodes:
self.powerbynode[node] = datum['state']
@ -366,17 +373,25 @@ class InputBootDevice(BootDevice):
if 'nextdevice' not in inputdata:
for key in nodes:
if key not in inputdata:
raise exc.InvalidArgumentException()
raise exc.InvalidArgumentException(key + ' not in request')
datum = inputdata[key]
if ('state' not in datum or
datum['state'] not in self.valid_values):
raise exc.InvalidArgumentException()
if 'nextdevice' not in datum:
raise exc.InvalidArgumentException(
'missing nextdevice argument')
elif datum['nextdevice'] not in self.valid_values:
raise exc.InvalidArgumentException(
datum['nextdevice'] + ' is not one of ' +
','.join(self.valid_values))
self.bootdevbynode[key] = datum['nextdevice']
else:
datum = inputdata
if ('nextdevice' not in datum or
datum['nextdevice'] not in self.valid_values):
raise exc.InvalidArgumentException()
if 'nextdevice' not in datum:
raise exc.InvalidArgumentException(
'missing nextdevice argument')
elif datum['nextdevice'] not in self.valid_values:
raise exc.InvalidArgumentException(
datum['nextdevice'] + ' is not one of ' +
','.join(self.valid_values))
for node in nodes:
self.bootdevbynode[node] = datum['nextdevice']

View File

@ -145,8 +145,8 @@ def update_nodegroup(group, element, configmanager, inputdata):
if clearattribs:
configmanager.clear_group_attributes(group, clearattribs)
configmanager.set_group_attributes({group: inputdata.attribs})
except ValueError:
raise exc.InvalidArgumentException()
except ValueError as e:
raise exc.InvalidArgumentException(str(e))
return retrieve_nodegroup(group, element, configmanager, inputdata)
@ -166,6 +166,6 @@ def update_nodes(nodes, element, configmanager, inputdata):
updatedict[node] = updatenode
try:
configmanager.set_node_attributes(updatedict)
except ValueError:
raise exc.InvalidArgumentException()
except ValueError as e:
raise exc.InvalidArgumentException(str(e))
return retrieve(nodes, element, configmanager, inputdata)