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
pull/17861/head
Peter Sprygada 8 years ago committed by GitHub
parent a4e5187661
commit 512ef49c8a

@ -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:

Loading…
Cancel
Save