From 2d0fde3f4206553db80166be3e998d4f460a449a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 9 May 2014 17:18:17 -0400 Subject: [PATCH] Provide more detail in invalidargument invalidargument was not particularly helpful by itself improve things by adding more helpful information in the error strings. --- confluent_client/bin/confetty | 2 + confluent_server/confluent/messages.py | 47 ++++++++++++------- .../plugins/configuration/attributes.py | 8 ++-- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index e733cc08..75a9c279 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -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: diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index 15fd9d6b..c13b520b 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -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'] diff --git a/confluent_server/confluent/plugins/configuration/attributes.py b/confluent_server/confluent/plugins/configuration/attributes.py index 1c979385..91bf9337 100644 --- a/confluent_server/confluent/plugins/configuration/attributes.py +++ b/confluent_server/confluent/plugins/configuration/attributes.py @@ -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)