Skip to content

Commit

Permalink
Resolve obvious unit test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Jan 13, 2022
1 parent 261d93e commit 11530a8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ansible_runner/config/_base.py
Expand Up @@ -39,6 +39,8 @@
from ansible_runner.defaults import registry_auth_prefix
from ansible_runner.loader import ArtifactLoader
from ansible_runner.utils import (
get_plugin_dir,
get_callback_dir,
open_fifo_write,
args2cmdline,
sanitize_container_name,
Expand Down Expand Up @@ -256,7 +258,7 @@ def _prepare_env(self, runner_mode='pexpect'):
if not self.containerized:
callback_dir = self.env.get('AWX_LIB_DIRECTORY', os.getenv('AWX_LIB_DIRECTORY'))
if callback_dir is None:
callback_dir = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "..", "display_callback", "callback"))
callback_dir = get_callback_dir()
self.env['ANSIBLE_CALLBACK_PLUGINS'] = ':'.join(filter(None, (self.env.get('ANSIBLE_CALLBACK_PLUGINS'), callback_dir)))

# this is an adhoc command if the module is specified, TODO: combine with logic in RunnerConfig class
Expand Down Expand Up @@ -493,8 +495,7 @@ def wrap_args_for_containerization(self, args, execution_mode, cmdline_args):
self._update_volume_mount_paths(new_args, "{}".format(self.private_data_dir), dst_mount_path="/runner", labels=":Z")

# Mount the stdout callback plugin from the ansible-runner code base
plugin_dir = os.path.abspath(os.path.join(os.path.split(os.path.abspath(__file__))[0], "..", "display_callback"))
self._update_volume_mount_paths(new_args, "{}".format(plugin_dir), dst_mount_path="/home/runner/.ansible/plugins", labels=":Z")
self._update_volume_mount_paths(new_args, "{}".format(get_plugin_dir()), dst_mount_path="/home/runner/.ansible/plugins", labels=":Z")

if self.container_auth_data:
# Pull in the necessary registry auth info, if there is a container cred
Expand Down
8 changes: 8 additions & 0 deletions ansible_runner/utils/__init__.py
Expand Up @@ -46,6 +46,14 @@ def register_for_cleanup(folder):
atexit.register(cleanup_folder, folder)


def get_plugin_dir():
return os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "display_callback"))


def get_callback_dir():
return os.path.join(get_plugin_dir(), 'callback')


class Bunch(object):

'''
Expand Down
2 changes: 2 additions & 0 deletions test/unit/config/test__base.py
Expand Up @@ -13,6 +13,7 @@
from ansible_runner.config._base import BaseConfig, BaseExecutionMode
from ansible_runner.loader import ArtifactLoader
from ansible_runner.exceptions import ConfigurationError
from ansible_runner.utils import get_plugin_dir

try:
Pattern = re._pattern_type
Expand Down Expand Up @@ -316,6 +317,7 @@ def test_containerization_settings(tmp_path, runtime, mocker):
expected_command_start.extend([
'-v', '{}/artifacts/:/runner/artifacts/:Z'.format(rc.private_data_dir),
'-v', '{}/:/runner/:Z'.format(rc.private_data_dir),
'-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
3 changes: 2 additions & 1 deletion test/unit/config/test_ansible_cfg.py
Expand Up @@ -6,7 +6,7 @@
from ansible_runner.config.ansible_cfg import AnsibleCfgConfig
from ansible_runner.config._base import BaseExecutionMode
from ansible_runner.exceptions import ConfigurationError
from ansible_runner.utils import get_executable_path
from ansible_runner.utils import get_executable_path, get_plugin_dir


def test_ansible_cfg_init_defaults(tmp_path, patch_private_data_dir):
Expand Down Expand Up @@ -91,6 +91,7 @@ def test_prepare_config_command_with_containerization(tmp_path, runtime, mocker)
expected_command_start.extend([
'-v', '{}/artifacts/:/runner/artifacts/:Z'.format(rc.private_data_dir),
'-v', '{}/:/runner/:Z'.format(rc.private_data_dir),
'-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
2 changes: 2 additions & 0 deletions test/unit/config/test_command.py
Expand Up @@ -6,6 +6,7 @@
from ansible_runner.config.command import CommandConfig
from ansible_runner.config._base import BaseExecutionMode
from ansible_runner.exceptions import ConfigurationError
from ansible_runner.utils import get_plugin_dir


def test_ansible_config_defaults(tmp_path, patch_private_data_dir):
Expand Down Expand Up @@ -105,6 +106,7 @@ def test_prepare_run_command_with_containerization(tmp_path, runtime, mocker):
expected_command_start.extend([
'-v', '{}/artifacts/:/runner/artifacts/:Z'.format(rc.private_data_dir),
'-v', '{}/:/runner/:Z'.format(rc.private_data_dir),
'-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir()),
'--env-file', '{}/env.list'.format(rc.artifact_dir),
])

Expand Down
2 changes: 2 additions & 0 deletions test/unit/config/test_runner.py
Expand Up @@ -14,6 +14,7 @@
from ansible_runner.interface import init_runner
from ansible_runner.loader import ArtifactLoader
from ansible_runner.exceptions import ConfigurationError
from ansible_runner.utils import get_plugin_dir

try:
Pattern = re._pattern_type
Expand Down Expand Up @@ -731,6 +732,7 @@ def test_containerization_settings(tmp_path, runtime, mocker):

expected_command_start = [runtime, 'run', '--rm', '--tty', '--interactive', '--workdir', '/runner/project'] + \
['-v', '{}/:/runner/:Z'.format(rc.private_data_dir)] + \
['-v', '{}/:/home/runner/.ansible/plugins/:Z'.format(get_plugin_dir())] + \
['-v', '/host1/:/container1/', '-v', '/host2/:/container2/'] + \
['--env-file', '{}/env.list'.format(rc.artifact_dir)] + \
extra_container_args + \
Expand Down

0 comments on commit 11530a8

Please sign in to comment.