Skip to content

Commit

Permalink
Merge pull request #1 from AlanCoding/buffer_ballet
Browse files Browse the repository at this point in the history
Start on basic python interface test for new remote commands
  • Loading branch information
jbradberry committed Oct 7, 2020
2 parents 65cb34e + 22be6c0 commit 94ac93e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ansible_runner/streaming.py
Expand Up @@ -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')
Expand Down
54 changes: 54 additions & 0 deletions 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()

0 comments on commit 94ac93e

Please sign in to comment.