summaryrefslogtreecommitdiff
path: root/test/integration/targets/plugin_loader
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2018-03-22 14:23:10 -0700
committerBrian Coca <bcoca@users.noreply.github.com>2018-03-22 17:23:10 -0400
commit0633f73faf962620e09774a45a65aab968f6fb6d (patch)
tree2d63037fc5326c684588dc355c514caa750927fc /test/integration/targets/plugin_loader
parente5011347551d7dda2c4829a9b77952375c69e007 (diff)
downloadansible-0633f73faf962620e09774a45a65aab968f6fb6d.tar.gz
Fix loader for filters (#37748)
* Fix loading of filter and test plugins Filter and test plugins are different than other plugins in that they can have many plugins in a single file. Therefore they need to operate a little differently. They need to have all of the potential files returned. Then the caller takes care of passing those onto jinja2 in order for jinja2 to make use of them. This problem was (most recently) introduced with f921369445900dcc756821e40c9257d5359087af This commit also restructures how we deduplicate plugins to take paths into account. If we want to start scoping which set of modules are loaded (due to roles, for instance) we'll need to hang on to the path information. * add integration test for override * Fix style checks for bcoca code * Implement jinja2 plugin loader as a subclass Having a subclass allows us to customize the overriding of jinja plugins. We can then move common parts of common code into the Loader.
Diffstat (limited to 'test/integration/targets/plugin_loader')
-rw-r--r--test/integration/targets/plugin_loader/aliases1
-rw-r--r--test/integration/targets/plugin_loader/normal/filters.yml13
-rw-r--r--test/integration/targets/plugin_loader/override/filter_plugins/core.py18
-rw-r--r--test/integration/targets/plugin_loader/override/filters.yml15
-rwxr-xr-xtest/integration/targets/plugin_loader/runme.sh24
5 files changed, 71 insertions, 0 deletions
diff --git a/test/integration/targets/plugin_loader/aliases b/test/integration/targets/plugin_loader/aliases
new file mode 100644
index 0000000000..79d8b9285e
--- /dev/null
+++ b/test/integration/targets/plugin_loader/aliases
@@ -0,0 +1 @@
+posix/ci/group3
diff --git a/test/integration/targets/plugin_loader/normal/filters.yml b/test/integration/targets/plugin_loader/normal/filters.yml
new file mode 100644
index 0000000000..f9069be1a6
--- /dev/null
+++ b/test/integration/targets/plugin_loader/normal/filters.yml
@@ -0,0 +1,13 @@
+- hosts: testhost
+ gather_facts: false
+ tasks:
+ - name: ensure filters work as shipped from core
+ assert:
+ that:
+ - a|flatten == [1, 2, 3, 4, 5]
+ - a|ternary('yes', 'no') == 'yes'
+ vars:
+ a:
+ - 1
+ - 2
+ - [3, 4, 5]
diff --git a/test/integration/targets/plugin_loader/override/filter_plugins/core.py b/test/integration/targets/plugin_loader/override/filter_plugins/core.py
new file mode 100644
index 0000000000..f283dc398b
--- /dev/null
+++ b/test/integration/targets/plugin_loader/override/filter_plugins/core.py
@@ -0,0 +1,18 @@
+# Make coding more python3-ish
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+
+def do_flag(myval):
+ return 'flagged'
+
+
+class FilterModule(object):
+ ''' Ansible core jinja2 filters '''
+
+ def filters(self):
+ return {
+ # jinja2 overrides
+ 'flag': do_flag,
+ 'flatten': do_flag,
+ }
diff --git a/test/integration/targets/plugin_loader/override/filters.yml b/test/integration/targets/plugin_loader/override/filters.yml
new file mode 100644
index 0000000000..e51ab4e95b
--- /dev/null
+++ b/test/integration/targets/plugin_loader/override/filters.yml
@@ -0,0 +1,15 @@
+- hosts: testhost
+ gather_facts: false
+ tasks:
+ - name: ensure local 'flag' filter works, 'flatten' is overriden and 'ternary' is still from core
+ assert:
+ that:
+ - a|flag == 'flagged'
+ - a|flatten != [1, 2, 3, 4, 5]
+ - a|flatten == "flagged"
+ - a|ternary('yes', 'no') == 'yes'
+ vars:
+ a:
+ - 1
+ - 2
+ - [3, 4, 5]
diff --git a/test/integration/targets/plugin_loader/runme.sh b/test/integration/targets/plugin_loader/runme.sh
new file mode 100755
index 0000000000..2a1bdedaca
--- /dev/null
+++ b/test/integration/targets/plugin_loader/runme.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+set -ux
+
+
+# check normal execution
+for myplay in normal/*.yml
+do
+ ansible-playbook "${myplay}" -i ../../inventory -vvv "$@"
+ if test $? != 0 ; then
+ echo "### Failed to run ${myplay} normally"
+ exit 1
+ fi
+done
+
+# check overrides
+for myplay in override/*.yml
+do
+ ansible-playbook "${myplay}" -i ../../inventory -vvv "$@"
+ if test $? != 0 ; then
+ echo "### Failed to run ${myplay} override"
+ exit 1
+ fi
+done