From 512ef49c8a5cd18a5685f0206ae56b5d1fa519c3 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 2 Oct 2016 14:47:58 -0400 Subject: [PATCH] adds new exception for adding condition statements to Conditional (#17859) When adding condition statements, the Conditional instance will now generate an AddConditionError if is unable to map the condition to a function in the instance --- lib/ansible/module_utils/netcli.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/netcli.py b/lib/ansible/module_utils/netcli.py index 33b6d2d92bc..a07c5025718 100644 --- a/lib/ansible/module_utils/netcli.py +++ b/lib/ansible/module_utils/netcli.py @@ -31,6 +31,7 @@ import time import shlex from ansible.module_utils.basic import BOOLEANS_TRUE, BOOLEANS_FALSE +from ansible.module_utils.basic import get_exception from ansible.module_utils.six import string_types, text_type from ansible.module_utils.six.moves import zip @@ -58,6 +59,12 @@ class AddCommandError(Exception): super(AddCommandError, self).__init__(msg) self.command = command +class AddConditionError(Exception): + def __init__(self, msg, condition): + super(AddConditionError, self).__init__(msg) + self.condition=condition + + class Cli(object): def __init__(self, connection): @@ -151,7 +158,11 @@ class CommandRunner(object): return [cmd.response for cmd in self.commands] def add_conditional(self, condition): - self.conditionals.add(Conditional(condition)) + try: + self.conditionals.add(Conditional(condition)) + except AttributeError: + exc = get_exception() + raise AddConditionError(msg=str(exc), condition=condition) def run(self): while self.retries > 0: