New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to disable streaming to stdout file #937
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -4,11 +4,14 @@ | |
import os | ||
|
||
import json | ||
from pathlib import Path | ||
import pexpect | ||
import pytest | ||
import six | ||
import sys | ||
|
||
from test.utils.common import iterate_timeout | ||
|
||
from ansible_runner import Runner | ||
from ansible_runner.exceptions import CallbackError, AnsibleRunnerException | ||
from ansible_runner.config.runner import RunnerConfig | ||
|
@@ -31,16 +34,6 @@ def rc(request, tmp_path): | |
return rc | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_sleep(request, mocker): | ||
# the handle_termination process teardown mechanism uses `time.sleep` to | ||
# wait on processes to respond to SIGTERM; these are tests and don't care | ||
# about being nice | ||
m = mocker.patch('time.sleep') | ||
m.start() | ||
request.addfinalizer(m.stop) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the timing, and the whole module takes about 3.6 seconds. Maybe this was reducing it to 3.5 or 3.4, but the difference also could have been indistinguishable. I'm using |
||
|
||
|
||
def test_simple_spawn(rc): | ||
rc.command = ['ls', '-la'] | ||
status, exitcode = Runner(config=rc).run() | ||
|
@@ -152,3 +145,30 @@ def test_status_callback_interface(rc, mocker): | |
assert runner.status_handler.call_count == 1 | ||
runner.status_handler.assert_called_with(dict(status='running', runner_ident=str(rc.ident)), runner_config=runner.config) | ||
assert runner.status == 'running' | ||
|
||
|
||
@pytest.mark.parametrize('runner_mode', ['pexpect', 'subprocess']) | ||
def test_stdout_file_write(rc, runner_mode): | ||
if runner_mode == 'pexpect': | ||
pytest.skip('Writing to stdout can be flaky, probably due to some pexpect bug') | ||
rc.command = ['echo', 'hello_world_marker'] | ||
rc.runner_mode = runner_mode | ||
status, exitcode = Runner(config=rc).run() | ||
assert status == 'successful' | ||
stdout_path = Path(rc.artifact_dir) / 'stdout' | ||
# this can be subject to a race condition so we will be patient with the check | ||
for _ in iterate_timeout(30.0, 'stdout file to be written', interval=0.2): | ||
if 'hello_world_marker' in stdout_path.read_text(): | ||
break | ||
|
||
|
||
@pytest.mark.parametrize('runner_mode', ['pexpect', 'subprocess']) | ||
def test_stdout_file_no_write(rc, runner_mode): | ||
rc.command = ['echo', 'hello_world_marker'] | ||
rc.runner_mode = runner_mode | ||
rc.suppress_output_file = True | ||
status, exitcode = Runner(config=rc).run() | ||
assert status == 'successful' | ||
for filename in ('stdout', 'stderr'): | ||
stdout_path = Path(rc.artifact_dir) / filename | ||
assert not stdout_path.exists() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a check to make these mutually exclusive? If they are both set ansible would "just run" with no output, maybe we don't care?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWX will set them both to
False
by design. The output is processed by the callback receiver. If someone really wanted the standard out file (which is normally deleted at the end of the run anyway) then we can introduce a setting for them to get it back.There's a feature in AWX to download the standard out file from a job run. It is illustrative that this works by a completely unrelated method. In the request-response cycle, it is written to disk from the database data and then delivered to the client. Then deleted.