summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/loop-connection/collections/ansible_collections/ns/name/plugins/connection/dummy.py
blob: cb14991fc30c100623e7bb391c4fee1ad9051fab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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