mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 11:25:08 -02:30
Capture play name and host pattern separately in job event data.
This commit is contained in:
@@ -20,7 +20,9 @@ from awx.main.models import *
|
|||||||
from awx.main.tests.base import BaseLiveServerTest
|
from awx.main.tests.base import BaseLiveServerTest
|
||||||
from awx.main.tasks import RunJob
|
from awx.main.tasks import RunJob
|
||||||
|
|
||||||
TEST_PLAYBOOK = '''- hosts: test-group
|
TEST_PLAYBOOK = '''
|
||||||
|
- name: test success
|
||||||
|
hosts: test-group
|
||||||
gather_facts: False
|
gather_facts: False
|
||||||
tasks:
|
tasks:
|
||||||
- name: should pass
|
- name: should pass
|
||||||
@@ -29,14 +31,17 @@ TEST_PLAYBOOK = '''- hosts: test-group
|
|||||||
command: test 2 = 2
|
command: test 2 = 2
|
||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_PLAYBOOK2 = '''- hosts: test-group
|
TEST_PLAYBOOK2 = '''- name: test failed
|
||||||
|
hosts: test-group
|
||||||
gather_facts: False
|
gather_facts: False
|
||||||
tasks:
|
tasks:
|
||||||
- name: should fail
|
- name: should fail
|
||||||
command: test 1 = 0
|
command: test 1 = 0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_EXTRA_VARS_PLAYBOOK = '''- hosts: test-group
|
TEST_EXTRA_VARS_PLAYBOOK = '''
|
||||||
|
- name: test extra vars
|
||||||
|
hosts: test-group
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- fail: msg="{{item}} is not defined"
|
- fail: msg="{{item}} is not defined"
|
||||||
@@ -50,14 +55,18 @@ TEST_EXTRA_VARS_PLAYBOOK = '''- hosts: test-group
|
|||||||
- tower_user_name
|
- tower_user_name
|
||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_ENV_PLAYBOOK = '''- hosts: test-group
|
TEST_ENV_PLAYBOOK = '''
|
||||||
|
- name: test env vars
|
||||||
|
hosts: test-group
|
||||||
gather_facts: False
|
gather_facts: False
|
||||||
tasks:
|
tasks:
|
||||||
- shell: 'test -n "${%(env_var1)s}"'
|
- shell: 'test -n "${%(env_var1)s}"'
|
||||||
- shell: 'test -n "${%(env_var2)s}"'
|
- shell: 'test -n "${%(env_var2)s}"'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_IGNORE_ERRORS_PLAYBOOK = '''- hosts: test-group
|
TEST_IGNORE_ERRORS_PLAYBOOK = '''
|
||||||
|
- name: test ignore errors
|
||||||
|
hosts: test-group
|
||||||
gather_facts: False
|
gather_facts: False
|
||||||
tasks:
|
tasks:
|
||||||
- name: should fail
|
- name: should fail
|
||||||
@@ -66,7 +75,8 @@ TEST_IGNORE_ERRORS_PLAYBOOK = '''- hosts: test-group
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_ASYNC_OK_PLAYBOOK = '''
|
TEST_ASYNC_OK_PLAYBOOK = '''
|
||||||
- hosts: test-group
|
- name: test async ok
|
||||||
|
hosts: test-group
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- debug: msg="one task before async"
|
- debug: msg="one task before async"
|
||||||
@@ -77,7 +87,8 @@ TEST_ASYNC_OK_PLAYBOOK = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_ASYNC_FAIL_PLAYBOOK = '''
|
TEST_ASYNC_FAIL_PLAYBOOK = '''
|
||||||
- hosts: test-group
|
- name: test async fail
|
||||||
|
hosts: test-group
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- debug: msg="one task before async"
|
- debug: msg="one task before async"
|
||||||
@@ -88,7 +99,8 @@ TEST_ASYNC_FAIL_PLAYBOOK = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_ASYNC_TIMEOUT_PLAYBOOK = '''
|
TEST_ASYNC_TIMEOUT_PLAYBOOK = '''
|
||||||
- hosts: test-group
|
- name: test async timeout
|
||||||
|
hosts: test-group
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- debug: msg="one task before async"
|
- debug: msg="one task before async"
|
||||||
@@ -99,7 +111,8 @@ TEST_ASYNC_TIMEOUT_PLAYBOOK = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_ASYNC_NOWAIT_PLAYBOOK = '''
|
TEST_ASYNC_NOWAIT_PLAYBOOK = '''
|
||||||
- hosts: test-group
|
- name: test async no wait
|
||||||
|
hosts: test-group
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: async task should run in background
|
- name: async task should run in background
|
||||||
@@ -109,7 +122,8 @@ TEST_ASYNC_NOWAIT_PLAYBOOK = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
TEST_PLAYBOOK_WITH_ROLES = '''
|
TEST_PLAYBOOK_WITH_ROLES = '''
|
||||||
- hosts: test-group
|
- name: test with roles
|
||||||
|
hosts: test-group
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
roles:
|
roles:
|
||||||
- some_stuff
|
- some_stuff
|
||||||
@@ -381,6 +395,9 @@ class RunJobTest(BaseCeleryTest):
|
|||||||
self.assertFalse(evt.task, evt)
|
self.assertFalse(evt.task, evt)
|
||||||
self.assertFalse(evt.role, evt)
|
self.assertFalse(evt.role, evt)
|
||||||
self.assertEqual(evt.failed, should_be_failed)
|
self.assertEqual(evt.failed, should_be_failed)
|
||||||
|
self.assertEqual(evt.play, evt.event_data['name'])
|
||||||
|
# All test playbooks have a play name set explicitly.
|
||||||
|
self.assertNotEqual(evt.event_data['name'], evt.event_data['pattern'])
|
||||||
if not async:
|
if not async:
|
||||||
self.assertEqual(evt.changed, should_be_changed)
|
self.assertEqual(evt.changed, should_be_changed)
|
||||||
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
if getattr(settings, 'CAPTURE_JOB_EVENT_HOSTS', False):
|
||||||
|
|||||||
@@ -257,8 +257,10 @@ class CallbackModule(object):
|
|||||||
# missing_file=missing_file)
|
# missing_file=missing_file)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def playbook_on_play_start(self, pattern):
|
def playbook_on_play_start(self, name):
|
||||||
self._log_event('playbook_on_play_start', pattern=pattern)
|
# Only play name is passed via callback, get host pattern from the play.
|
||||||
|
pattern = getattr(getattr(self, 'play', None), 'hosts', name)
|
||||||
|
self._log_event('playbook_on_play_start', name=name, pattern=pattern)
|
||||||
|
|
||||||
def playbook_on_stats(self, stats):
|
def playbook_on_stats(self, stats):
|
||||||
d = {}
|
d = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user