summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Sprygada <psprygada@ansible.com>2016-09-19 12:06:25 -0400
committerPeter Sprygada <psprygada@ansible.com>2016-09-19 14:14:43 -0400
commit1a8ad2a20f91a9482497176949b170275b5bf8c0 (patch)
treeabb1bf4722e364efd13f62392addc3c85476993c
parentff52e01a11eb431525fb842346615d0981eb23d8 (diff)
downloadansible-1a8ad2a20f91a9482497176949b170275b5bf8c0.tar.gz
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.
-rw-r--r--lib/ansible/module_utils/netcli.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/ansible/module_utils/netcli.py b/lib/ansible/module_utils/netcli.py
index d92e952cb6..10a544f5b4 100644
--- a/lib/ansible/module_utils/netcli.py
+++ b/lib/ansible/module_utils/netcli.py
@@ -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']:
- return self.get_json(result)
+ 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'))