Merge pull request #5720 from ryanpetrello/callback-plugin-tests

add callback plugin tests to CI
This commit is contained in:
Ryan Petrello
2017-03-15 09:40:33 -04:00
committed by GitHub
2 changed files with 33 additions and 20 deletions

View File

@@ -487,7 +487,7 @@ check: flake8 pep8 # pyflakes pylint
TEST_DIRS ?= awx/main/tests awx/conf/tests awx/sso/tests TEST_DIRS ?= awx/main/tests awx/conf/tests awx/sso/tests
# Run all API unit tests. # Run all API unit tests.
test: test: test_ansible
@if [ "$(VENV_BASE)" ]; then \ @if [ "$(VENV_BASE)" ]; then \
. $(VENV_BASE)/tower/bin/activate; \ . $(VENV_BASE)/tower/bin/activate; \
fi; \ fi; \

View File

@@ -28,7 +28,7 @@ with mock.patch.dict(os.environ, {'ANSIBLE_STDOUT_CALLBACK': CALLBACK,
from ansible.vars import VariableManager from ansible.vars import VariableManager
# Add awx/lib to sys.path so we can use the plugin # Add awx/lib to sys.path so we can use the plugin
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) path = os.path.abspath(os.path.join(PLUGINS, '..', '..'))
if path not in sys.path: if path not in sys.path:
sys.path.insert(0, path) sys.path.insert(0, path)
@@ -37,11 +37,15 @@ with mock.patch.dict(os.environ, {'ANSIBLE_STDOUT_CALLBACK': CALLBACK,
@pytest.fixture() @pytest.fixture()
def local_cache(): def cache(request):
class Cache(OrderedDict): class Cache(OrderedDict):
def set(self, key, value): def set(self, key, value):
self[key] = value self[key] = value
return Cache() local_cache = Cache()
patch = mock.patch.object(event_context, 'cache', local_cache)
patch.start()
request.addfinalizer(patch.stop)
return local_cache
@pytest.fixture() @pytest.fixture()
@@ -84,11 +88,10 @@ def executor(tmpdir_factory, request):
msg: "Hello World!" msg: "Hello World!"
'''} # noqa '''} # noqa
]) ])
def test_callback_plugin_receives_events(executor, local_cache, event, def test_callback_plugin_receives_events(executor, cache, event, playbook):
playbook): executor.run()
with mock.patch.object(event_context, 'cache', local_cache): assert len(cache)
executor.run() assert event in [task['event'] for task in cache.values()]
assert event in [task['event'] for task in local_cache.values()]
@pytest.mark.parametrize('playbook', [ @pytest.mark.parametrize('playbook', [
@@ -132,11 +135,23 @@ def test_callback_plugin_receives_events(executor, local_cache, event,
- name: args should not be logged when play-level no_log set - name: args should not be logged when play-level no_log set
shell: echo "SENSITIVE" shell: echo "SENSITIVE"
'''}, # noqa '''}, # noqa
{'async_no_log.yml': '''
- name: async task args should suppressed with no_log
connection: local
hosts: all
gather_facts: no
no_log: true
tasks:
- async: 10
poll: 1
shell: echo "SENSITIVE"
no_log: true
'''}, # noqa
]) ])
def test_callback_plugin_no_log_filters(executor, local_cache, playbook): def test_callback_plugin_no_log_filters(executor, cache, playbook):
with mock.patch.object(event_context, 'cache', local_cache): executor.run()
executor.run() assert len(cache)
assert 'SENSITIVE' not in json.dumps(local_cache.items()) assert 'SENSITIVE' not in json.dumps(cache.items())
@pytest.mark.parametrize('playbook', [ @pytest.mark.parametrize('playbook', [
@@ -148,10 +163,8 @@ def test_callback_plugin_no_log_filters(executor, local_cache, playbook):
- shell: echo "Hello, World!" - shell: echo "Hello, World!"
'''}, # noqa '''}, # noqa
]) ])
def test_callback_plugin_strips_task_environ_variables(executor, local_cache, def test_callback_plugin_strips_task_environ_variables(executor, cache, playbook):
playbook): executor.run()
with mock.patch.object(event_context, 'cache', local_cache): assert len(cache)
executor.run() for event in cache.values():
for event in local_cache.values(): assert os.environ['VIRTUAL_ENV'] not in json.dumps(event)
if event['event_data'].get('task') == 'setup':
assert os.environ['VIRTUAL_ENV'] not in json.dumps(event)