diff --git a/ansible_runner/streaming.py b/ansible_runner/streaming.py index ebc3b32d6..48b52f021 100644 --- a/ansible_runner/streaming.py +++ b/ansible_runner/streaming.py @@ -200,10 +200,10 @@ def event_callback(self, event_data): def artifacts_callback(self, artifacts_data): buf = io.BytesIO(self._input.read(artifacts_data['zipfile'])) with zipfile.ZipFile(buf, 'r') as archive: - archive.extractall(path=self.config.artifact_dir) + archive.extractall(path=self.artifact_dir) if self.artifacts_handler is not None: - self.artifacts_handler(self.config.artifact_dir) + self.artifacts_handler(self.artifact_dir) def run(self): job_events_path = os.path.join(self.artifact_dir, 'job_events') diff --git a/test/integration/test_transmit_worker_process.py b/test/integration/test_transmit_worker_process.py new file mode 100644 index 000000000..1d7260a0a --- /dev/null +++ b/test/integration/test_transmit_worker_process.py @@ -0,0 +1,54 @@ +import os +import io + +from ansible_runner.streaming import Transmitter, Worker, Processor + + +def test_remote_job_interface(tmpdir, test_data_dir): + worker_dir = str(tmpdir.mkdir('for_worker')) + process_dir = str(tmpdir.mkdir('for_process')) + + original_dir = os.path.join(test_data_dir, 'debug') + + outgoing_buffer = io.BytesIO() + + # Intended AWX and Tower use case + transmitter = Transmitter( + _output = outgoing_buffer, + private_data_dir = original_dir, + playbook = 'debug.yml' + ) + + print(transmitter.kwargs) + assert transmitter.kwargs.get('playbook', '') == 'debug.yml' + + status, rc = transmitter.run() + assert rc in (None, 0) + assert status == 'unstarted' + + outgoing_buffer.seek(0) # rewind so we can start reading + + sent = outgoing_buffer.getvalue() + assert sent # should not be blank at least + assert b'zipfile' in sent + + incoming_buffer = io.BytesIO() + + worker = Worker( + _input = outgoing_buffer, + _output = incoming_buffer, + private_data_dir = worker_dir + ) + worker.run() + + assert set(os.listdir(worker_dir)) == set(['artifacts', 'inventory', 'project']), outgoing_buffer.getvalue() + + incoming_buffer.seek(0) # again, be kind, rewind + + processor = Processor( + _input = incoming_buffer, + private_data_dir = process_dir + ) + processor.run() + + assert set(os.listdir(process_dir)) == set(['artifacts']), outgoing_buffer.getvalue()