diff --git a/roles/__init__.py b/roles/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/roles/oneagent/__init__.py b/roles/oneagent/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/roles/oneagent/tests/__init__.py b/roles/oneagent/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/roles/oneagent/tests/integration/__init__.py b/roles/oneagent/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/roles/oneagent/tests/integration/scripts/command/unix/unix_command_executor.py b/roles/oneagent/tests/integration/scripts/command/unix/unix_command_executor.py index 16c8217..9c5e8d2 100644 --- a/roles/oneagent/tests/integration/scripts/command/unix/unix_command_executor.py +++ b/roles/oneagent/tests/integration/scripts/command/unix/unix_command_executor.py @@ -1,23 +1,24 @@ import subprocess +from typing import List from util.test_data_types import CommandResult +def _getCommandPrefix(address: str, user: str, password: str) -> List[str]: + if address == "localhost": + return [] + else: + return ["sshpass", "-p", f"{password}", "ssh", "-o", "StrictHostKeyChecking=no", f"{user}@{address}"] + class UnixCommandExecutor: def __init__(self, user: str, password: str): self.user = user self.password = password def execute(self, address: str, command: str, *args: str) -> CommandResult: - cmd = [ - "sshpass", - "-p", - f"{self.password}", - "ssh", - "-o StrictHostKeyChecking=no", - f"{self.user}@{address}", - command, - *args, - ] + prefix = _getCommandPrefix(address, self.user, self.password) + cmd = prefix + [command, *args] out = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, check=False) return CommandResult(out.returncode, out.stdout, out.stderr) + + diff --git a/roles/oneagent/tests/integration/scripts/technology/ansible/config.py b/roles/oneagent/tests/integration/scripts/technology/ansible/config.py index b616526..b58ec46 100644 --- a/roles/oneagent/tests/integration/scripts/technology/ansible/config.py +++ b/roles/oneagent/tests/integration/scripts/technology/ansible/config.py @@ -5,6 +5,7 @@ PLAYBOOK_TEMPLATE_FILE_NAME, HOSTS_TEMPLATE_FILE_NAME, ANSIBLE_USER_KEY, + ANSIBLE_CONNECTION_KEY, ANSIBLE_RESOURCE_DIR, COLLECTION_DIR, COLLECTION_NAME, @@ -32,6 +33,9 @@ def _prepare_inventory_file(user: str, platforms: PlatformCollection) -> None: for platform, hosts in platforms.items(): group_data = data["all"]["children"][platform.family()]["children"][platform.value] group_data["hosts"] = {k: None for k in hosts} + # TODO: Replace so that both local and ssh connections can be used + if "localhost" in hosts: + group_data["vars"][ANSIBLE_CONNECTION_KEY] = "local" group_data["vars"][ANSIBLE_USER_KEY] = user write_yaml_file(INVENTORY_FILE, data) diff --git a/roles/oneagent/tests/integration/scripts/technology/ansible/constants.py b/roles/oneagent/tests/integration/scripts/technology/ansible/constants.py index 85a0ef6..d0afcea 100644 --- a/roles/oneagent/tests/integration/scripts/technology/ansible/constants.py +++ b/roles/oneagent/tests/integration/scripts/technology/ansible/constants.py @@ -16,6 +16,7 @@ ANSIBLE_USER_KEY = "ansible_user" ANSIBLE_PASS_KEY = "ansible_password" +ANSIBLE_CONNECTION_KEY = "ansible_connection" HOSTS_TEMPLATE_FILE_NAME = "hosts.yml" CREDENTIALS_FILE_NAME = "credentials.yml"