fixes issue where netcli would cause exception with an invalid conditional

The Conditional instance will cause a stack trace if the provided conditional
does not map properly to the response.  This fixes that issue so that the
Conditional instance will now raise a FailedConditionalError with the
conditional that caused the failure.

Modules *_command modules (and any other modules that create an instance
of Conditional) should be updated to catch the FailedConditionalError
exception.
This commit is contained in:
Peter Sprygada 2016-09-19 12:06:25 -04:00
parent ff52e01a11
commit 1a8ad2a20f

View file

@ -47,6 +47,11 @@ class FailedConditionsError(Exception):
super(FailedConditionsError, self).__init__(msg)
self.failed_conditions = failed_conditions
class FailedConditionalError(Exception):
def __init__(self, msg, failed_conditional):
super(FailedConditionalError, self).__init__(msg)
self.failed_conditional = failed_conditional
class AddCommandError(Exception):
def __init__(self, msg, command):
super(AddCommandError, self).__init__(msg)
@ -216,7 +221,12 @@ class Conditional(object):
def get_value(self, result):
if self.encoding in ['json', 'text']:
try:
return self.get_json(result)
except (IndexError, TypeError):
msg = 'unable to apply conditional to result'
raise FailedConditionalError(msg, self.key)
elif self.encoding == 'xml':
return self.get_xml(result.get('result'))