summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/plugin_loader
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/plugin_loader')
-rw-r--r--test/integration/targets/plugin_loader/aliases2
-rw-r--r--test/integration/targets/plugin_loader/normal/action_plugins/self_referential.py29
-rw-r--r--test/integration/targets/plugin_loader/normal/filters.yml13
-rw-r--r--test/integration/targets/plugin_loader/normal/library/_underscore.py13
-rw-r--r--test/integration/targets/plugin_loader/normal/self_referential.yml5
-rw-r--r--test/integration/targets/plugin_loader/normal/underscore.yml15
-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.sh36
-rw-r--r--test/integration/targets/plugin_loader/use_coll_name.yml7
10 files changed, 153 insertions, 0 deletions
diff --git a/test/integration/targets/plugin_loader/aliases b/test/integration/targets/plugin_loader/aliases
new file mode 100644
index 0000000..1d28bdb
--- /dev/null
+++ b/test/integration/targets/plugin_loader/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group5
+context/controller
diff --git a/test/integration/targets/plugin_loader/normal/action_plugins/self_referential.py b/test/integration/targets/plugin_loader/normal/action_plugins/self_referential.py
new file mode 100644
index 0000000..b4c8957
--- /dev/null
+++ b/test/integration/targets/plugin_loader/normal/action_plugins/self_referential.py
@@ -0,0 +1,29 @@
+# Copyright: Contributors to the Ansible project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from ansible.plugins.action import ActionBase
+
+import sys
+
+# reference our own module from sys.modules while it's being loaded to ensure the importer behaves properly
+try:
+ mod = sys.modules[__name__]
+except KeyError:
+ raise Exception(f'module {__name__} is not accessible via sys.modules, likely a pluginloader bug')
+
+
+class ActionModule(ActionBase):
+ TRANSFERS_FILES = False
+
+ def run(self, tmp=None, task_vars=None):
+ if task_vars is None:
+ task_vars = dict()
+
+ result = super(ActionModule, self).run(tmp, task_vars)
+ del tmp # tmp no longer has any effect
+
+ result['changed'] = False
+ result['msg'] = 'self-referential action loaded and ran successfully'
+ return result
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 0000000..f9069be
--- /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/normal/library/_underscore.py b/test/integration/targets/plugin_loader/normal/library/_underscore.py
new file mode 100644
index 0000000..7a416a6
--- /dev/null
+++ b/test/integration/targets/plugin_loader/normal/library/_underscore.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+import json
+
+
+def main():
+ print(json.dumps(dict(changed=False, source='legacy_library_dir')))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/test/integration/targets/plugin_loader/normal/self_referential.yml b/test/integration/targets/plugin_loader/normal/self_referential.yml
new file mode 100644
index 0000000..d3eed21
--- /dev/null
+++ b/test/integration/targets/plugin_loader/normal/self_referential.yml
@@ -0,0 +1,5 @@
+- hosts: testhost
+ gather_facts: false
+ tasks:
+ - name: ensure a self-referential action plugin loads properly
+ self_referential:
diff --git a/test/integration/targets/plugin_loader/normal/underscore.yml b/test/integration/targets/plugin_loader/normal/underscore.yml
new file mode 100644
index 0000000..fb5bbad
--- /dev/null
+++ b/test/integration/targets/plugin_loader/normal/underscore.yml
@@ -0,0 +1,15 @@
+- hosts: testhost
+ gather_facts: false
+ tasks:
+ - name: Load a deprecated module
+ underscore:
+ register: res
+
+ - name: Load a deprecated module that is a symlink
+ symlink:
+ register: sym
+
+ - assert:
+ that:
+ - res.source == 'legacy_library_dir'
+ - sym.source == 'legacy_library_dir'
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 0000000..f283dc3
--- /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 0000000..e51ab4e
--- /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 0000000..e30f624
--- /dev/null
+++ b/test/integration/targets/plugin_loader/runme.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+set -ux
+
+cleanup() {
+ unlink normal/library/_symlink.py
+}
+
+pushd normal/library
+ln -s _underscore.py _symlink.py
+popd
+
+trap 'cleanup' EXIT
+
+# 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
+
+# test config loading
+ansible-playbook use_coll_name.yml -i ../../inventory -e 'ansible_connection=ansible.builtin.ssh' "$@"
diff --git a/test/integration/targets/plugin_loader/use_coll_name.yml b/test/integration/targets/plugin_loader/use_coll_name.yml
new file mode 100644
index 0000000..66507ce
--- /dev/null
+++ b/test/integration/targets/plugin_loader/use_coll_name.yml
@@ -0,0 +1,7 @@
+- name: ensure configuration is loaded when we use FQCN and have already loaded using 'short namne' (which is case will all builtin connection plugins)
+ hosts: all
+ gather_facts: false
+ tasks:
+ - name: relies on extra var being passed in with connection and fqcn
+ ping:
+ ignore_unreachable: True