Skip to content

Commit

Permalink
Merge branch 'skip-process-isolation-check-for-transmit-and-receive' …
Browse files Browse the repository at this point in the history
…into personal-build
  • Loading branch information
TheRealHaoLiu committed Jun 3, 2022
2 parents 39107af + 0e67829 commit 5600f11
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ansible_runner/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ def init_runner(**kwargs):
if logfile:
output.set_logfile(logfile)

if kwargs.get("process_isolation", False):
pi_executable = kwargs.get("process_isolation_executable", "podman")
if not check_isolation_executable_installed(pi_executable):
print(f'Unable to find process isolation executable: {pi_executable}')
sys.exit(1)

event_callback_handler = kwargs.pop('event_handler', None)
status_callback_handler = kwargs.pop('status_handler', None)
artifacts_handler = kwargs.pop('artifacts_handler', None)
Expand Down Expand Up @@ -118,6 +112,12 @@ def init_runner(**kwargs):
**kwargs)
return stream_processor

if kwargs.get("process_isolation", False):
pi_executable = kwargs.get("process_isolation_executable", "podman")
if not check_isolation_executable_installed(pi_executable):
print(f'Unable to find process isolation executable: {pi_executable}')
sys.exit(1)

kwargs.pop('_input', None)
kwargs.pop('_output', None)
rc = RunnerConfig(**kwargs)
Expand Down
48 changes: 48 additions & 0 deletions test/integration/test_transmit_worker_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,54 @@ def process_method(results_sockfile_read):

self.check_artifacts(str(process_dir), job_type)

@pytest.mark.parametrize("process_isolation_executable", ['exist', 'does_not_exist'])
def test_process_isolation_executable_transmit(self, tmp_path, process_isolation_executable, mocker):
"""
Case transmit should not fail if process isolation executable does not exist
"""
def mock_check_isolation_executable_installed(executable):
if executable == "exist":
return True

mocker.patch.object(ansible_runner.interface, 'check_isolation_executable_installed', mock_check_isolation_executable_installed)

job_kwargs = self.get_job_kwargs('run')
job_kwargs['process_isolation'] = True
job_kwargs['process_isolation_executable'] = process_isolation_executable

outgoing_buffer_file = tmp_path / 'buffer_out'
outgoing_buffer_file.touch()
outgoing_buffer = outgoing_buffer_file.open('b+r')

transmitter = ansible_runner.interface.run(
streamer='transmit',
_output=outgoing_buffer,
**job_kwargs,
)

# valide process_isolation kwargs are passed to transmitter
assert transmitter.kwargs['process_isolation'] == job_kwargs['process_isolation']
assert transmitter.kwargs['process_isolation_executable'] == job_kwargs['process_isolation_executable']

# validate that transmit did not fail due to missing process isolation executable
assert transmitter.rc in (None, 0)

# validate that transmit buffer is not empty
outgoing_buffer.seek(0)
sent = outgoing_buffer.read()
assert sent # should not be blank at least

# validate buffer contains kwargs
assert b'kwargs' in sent

# validate kwargs in buffer contain correct process_isolation and process_isolation_executable
for line in sent.decode('utf-8').split('\n'):
if "kwargs" in line:
kwargs = json.loads(line).get("kwargs", {})
assert kwargs['process_isolation'] is True
assert kwargs['process_isolation_executable'] == process_isolation_executable
break


@pytest.fixture
def transmit_stream(project_fixtures, tmp_path):
Expand Down

0 comments on commit 5600f11

Please sign in to comment.