Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AlanCoding/buffer_ballet
Start on basic python interface test for new remote commands
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |