Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ansible/ansible.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2022-09-30 02:06:10 +0300
committerGitHub <noreply@github.com>2022-09-30 02:06:10 +0300
commitba6da65a0f3baefda7a058ebbd0a8dcafb8512f5 (patch)
treea267d7c4dc342c4c450301893c591224ae575890 /test
parentbe4807b712d83370561942aa7c3c7f2141759077 (diff)
Fix connection/become task loop settings (#78565)
* Fix connection/become task loop settings * Remove old code
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/loop-connection/aliases2
-rw-r--r--test/integration/targets/loop-connection/collections/ansible_collections/ns/name/meta/runtime.yml4
-rw-r--r--test/integration/targets/loop-connection/collections/ansible_collections/ns/name/plugins/connection/dummy.py50
-rw-r--r--test/integration/targets/loop-connection/main.yml33
-rwxr-xr-xtest/integration/targets/loop-connection/runme.sh5
-rw-r--r--test/units/executor/test_task_executor.py1
6 files changed, 95 insertions, 0 deletions
diff --git a/test/integration/targets/loop-connection/aliases b/test/integration/targets/loop-connection/aliases
new file mode 100644
index 00000000000..498fedd558e
--- /dev/null
+++ b/test/integration/targets/loop-connection/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group4
+context/controller
diff --git a/test/integration/targets/loop-connection/collections/ansible_collections/ns/name/meta/runtime.yml b/test/integration/targets/loop-connection/collections/ansible_collections/ns/name/meta/runtime.yml
new file mode 100644
index 00000000000..09322a9debc
--- /dev/null
+++ b/test/integration/targets/loop-connection/collections/ansible_collections/ns/name/meta/runtime.yml
@@ -0,0 +1,4 @@
+plugin_routing:
+ connection:
+ redirected_dummy:
+ redirect: ns.name.dummy \ No newline at end of file
diff --git a/test/integration/targets/loop-connection/collections/ansible_collections/ns/name/plugins/connection/dummy.py b/test/integration/targets/loop-connection/collections/ansible_collections/ns/name/plugins/connection/dummy.py
new file mode 100644
index 00000000000..cb14991fc30
--- /dev/null
+++ b/test/integration/targets/loop-connection/collections/ansible_collections/ns/name/plugins/connection/dummy.py
@@ -0,0 +1,50 @@
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+DOCUMENTATION = '''
+name: dummy
+short_description: Used for loop-connection tests
+description:
+- See above
+author: ansible (@core)
+'''
+
+from ansible.errors import AnsibleError
+from ansible.plugins.connection import ConnectionBase
+
+
+class Connection(ConnectionBase):
+
+ transport = 'ns.name.dummy'
+
+ def __init__(self, *args, **kwargs):
+ self._cmds_run = 0
+ super().__init__(*args, **kwargs)
+
+ @property
+ def connected(self):
+ return True
+
+ def _connect(self):
+ return
+
+ def exec_command(self, cmd, in_data=None, sudoable=True):
+ if 'become_test' in cmd:
+ stderr = f"become - {self.become.name if self.become else None}"
+
+ elif 'connected_test' in cmd:
+ self._cmds_run += 1
+ stderr = f"ran - {self._cmds_run}"
+
+ else:
+ raise AnsibleError(f"Unknown test cmd {cmd}")
+
+ return 0, cmd.encode(), stderr.encode()
+
+ def put_file(self, in_path, out_path):
+ return
+
+ def fetch_file(self, in_path, out_path):
+ return
+
+ def close(self):
+ return
diff --git a/test/integration/targets/loop-connection/main.yml b/test/integration/targets/loop-connection/main.yml
new file mode 100644
index 00000000000..fbffe309dd2
--- /dev/null
+++ b/test/integration/targets/loop-connection/main.yml
@@ -0,0 +1,33 @@
+- hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: test changing become activation on the same connection
+ raw: become_test
+ register: become_test
+ become: '{{ item }}'
+ vars:
+ ansible_connection: ns.name.dummy
+ loop:
+ - true
+ - false
+
+ - assert:
+ that:
+ - become_test.results[0].stderr == "become - sudo"
+ - become_test.results[0].stdout.startswith("sudo ")
+ - become_test.results[1].stderr == "become - None"
+ - become_test.results[1].stdout == "become_test"
+
+ - name: test loop reusing connection with redirected plugin name
+ raw: connected_test
+ register: connected_test
+ vars:
+ ansible_connection: ns.name.redirected_dummy
+ loop:
+ - 1
+ - 2
+
+ - assert:
+ that:
+ - connected_test.results[0].stderr == "ran - 1"
+ - connected_test.results[1].stderr == "ran - 2" \ No newline at end of file
diff --git a/test/integration/targets/loop-connection/runme.sh b/test/integration/targets/loop-connection/runme.sh
new file mode 100755
index 00000000000..db4031df3bb
--- /dev/null
+++ b/test/integration/targets/loop-connection/runme.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -eux -o pipefail
+
+ansible-playbook main.yml "$@"
diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py
index f71629781fe..315d26ae3a8 100644
--- a/test/units/executor/test_task_executor.py
+++ b/test/units/executor/test_task_executor.py
@@ -315,6 +315,7 @@ class TestTaskExecutor(unittest.TestCase):
mock_task = MagicMock()
mock_task.action = 'mock.action'
mock_task.args = dict()
+ mock_task.become = False
mock_task.retries = 0
mock_task.delay = -1
mock_task.register = 'foo'