Fixing bugs in conditional testing with until and some integration runner tweaks

pull/13613/head
James Cammarata 9 years ago
parent e2d9f4e2f2
commit 3ec0104128

@ -35,7 +35,7 @@ from ansible.template import Templar
from ansible.utils.encrypt import key_for_hostname from ansible.utils.encrypt import key_for_hostname
from ansible.utils.listify import listify_lookup_plugin_terms from ansible.utils.listify import listify_lookup_plugin_terms
from ansible.utils.unicode import to_unicode from ansible.utils.unicode import to_unicode
from ansible.vars.unsafe_proxy import UnsafeProxy from ansible.vars.unsafe_proxy import UnsafeProxy, wrap_var
try: try:
from __main__ import display from __main__ import display
@ -406,7 +406,7 @@ class TaskExecutor:
# update the local copy of vars with the registered value, if specified, # update the local copy of vars with the registered value, if specified,
# or any facts which may have been generated by the module execution # or any facts which may have been generated by the module execution
if self._task.register: if self._task.register:
vars_copy[self._task.register] = result vars_copy[self._task.register] = wrap_var(result.copy())
if self._task.async > 0: if self._task.async > 0:
# the async_wrapper module returns dumped JSON via its stdout # the async_wrapper module returns dumped JSON via its stdout
@ -453,7 +453,7 @@ class TaskExecutor:
if attempt < retries - 1: if attempt < retries - 1:
cond = Conditional(loader=self._loader) cond = Conditional(loader=self._loader)
cond.when = self._task.until cond.when = [ self._task.until ]
if cond.evaluate_conditional(templar, vars_copy): if cond.evaluate_conditional(templar, vars_copy):
break break
@ -466,7 +466,7 @@ class TaskExecutor:
# do the final update of the local variables here, for both registered # do the final update of the local variables here, for both registered
# values and any facts which may have been created # values and any facts which may have been created
if self._task.register: if self._task.register:
variables[self._task.register] = result variables[self._task.register] = wrap_var(result)
if 'ansible_facts' in result: if 'ansible_facts' in result:
variables.update(result['ansible_facts']) variables.update(result['ansible_facts'])

@ -22,7 +22,7 @@ __metaclass__ = type
from jinja2.exceptions import UndefinedError from jinja2.exceptions import UndefinedError
from ansible.compat.six import text_type from ansible.compat.six import text_type
from ansible.errors import AnsibleError from ansible.errors import AnsibleError, AnsibleUndefinedVariable
from ansible.playbook.attribute import FieldAttribute from ansible.playbook.attribute import FieldAttribute
from ansible.template import Templar from ansible.template import Templar
@ -89,16 +89,22 @@ class Conditional:
# make sure the templar is using the variables specifed to this method # make sure the templar is using the variables specifed to this method
templar.set_available_variables(variables=all_vars) templar.set_available_variables(variables=all_vars)
try:
conditional = templar.template(conditional) conditional = templar.template(conditional)
if not isinstance(conditional, basestring) or conditional == "": if not isinstance(conditional, text_type) or conditional == "":
return conditional return conditional
# a Jinja2 evaluation that results in something Python can eval! # a Jinja2 evaluation that results in something Python can eval!
presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional
conditional = templar.template(presented, fail_on_undefined=False) conditional = templar.template(presented)
val = conditional.strip() val = conditional.strip()
if val == presented: if val == "True":
return True
elif val == "False":
return False
else:
raise AnsibleError("unable to evaluate conditional: %s" % original)
except (AnsibleUndefinedVariable, UndefinedError) as e:
# the templating failed, meaning most likely a # the templating failed, meaning most likely a
# variable was undefined. If we happened to be # variable was undefined. If we happened to be
# looking for an undefined variable, return True, # looking for an undefined variable, return True,
@ -108,11 +114,5 @@ class Conditional:
elif "is defined" in original: elif "is defined" in original:
return False return False
else: else:
raise AnsibleError("error while evaluating conditional: %s (%s)" % (original, presented)) raise AnsibleError("error while evaluating conditional (%s): %s" % (original, e))
elif val == "True":
return True
elif val == "False":
return False
else:
raise AnsibleError("unable to evaluate conditional: %s" % original)

@ -82,7 +82,7 @@ class Task(Base, Conditional, Taggable, Become):
_poll = FieldAttribute(isa='int') _poll = FieldAttribute(isa='int')
_register = FieldAttribute(isa='string') _register = FieldAttribute(isa='string')
_retries = FieldAttribute(isa='int', default=3) _retries = FieldAttribute(isa='int', default=3)
_until = FieldAttribute(isa='list') _until = FieldAttribute(isa='string')
def __init__(self, block=None, role=None, task_include=None): def __init__(self, block=None, role=None, task_include=None):
''' constructors a task, without the Task.load classmethod, it will be pretty blank ''' ''' constructors a task, without the Task.load classmethod, it will be pretty blank '''

@ -74,4 +74,4 @@
- name: Fail - name: Fail
shell: 'echo "{{ inventory_hostname }}, Failed" && exit 1' shell: 'echo "{{ inventory_hostname }}, Failed" && exit 1'
when: "test_results.rc != 0" when: "'rc' not in test_results or test_results.rc != 0"

@ -59,6 +59,7 @@
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
- name: update ca certificates - name: update ca certificates
sudo: true
yum: name=ca-certificates state=latest yum: name=ca-certificates state=latest
when: ansible_os_family == 'RedHat' when: ansible_os_family == 'RedHat'

@ -6,10 +6,12 @@
- name: Get ansible source dir - name: Get ansible source dir
sudo: false sudo: false
shell: "cd ~ && pwd" shell: "cd ~/ansible && pwd"
register: results register: results
- shell: ". hacking/env-setup && cd test/integration && make {{ run_integration_make_target }}" - shell: "ls -la && . hacking/env-setup && cd test/integration && make {{ run_integration_make_target }}"
args:
chdir: "{{ results.stdout }}"
async: 3600 async: 3600
poll: 0 poll: 0
register: async_test_results register: async_test_results
@ -17,14 +19,13 @@
environment: environment:
TEST_FLAGS: "{{ run_integration_test_flags|default(lookup('env', 'TEST_FLAGS')) }}" TEST_FLAGS: "{{ run_integration_test_flags|default(lookup('env', 'TEST_FLAGS')) }}"
CREDENTIALS_FILE: "{{ run_integration_credentials_file|default(lookup('env', 'CREDENTIALS_FILE')) }}" CREDENTIALS_FILE: "{{ run_integration_credentials_file|default(lookup('env', 'CREDENTIALS_FILE')) }}"
args:
chdir: "{{ results.stdout }}/ansible"
- name: poll for test results - name: poll for test results
async_status: async_status: jid="{{async_test_results.ansible_job_id}}"
jid: "{{async_test_results.ansible_job_id}}"
register: test_results register: test_results
until: test_results.finished until: test_results.finished
retries: 360 retries: 120
delay: 10 delay: 30
ignore_errors: true ignore_errors: true
- debug: var=test_results

Loading…
Cancel
Save