Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ansible-test - Fix TTY and output handling. (#78350)
- Loading branch information
Showing
17 changed files
with
159 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
bugfixes: | ||
- ansible-test - The ``shell`` command no longer requests a TTY when using delegation unless an interactive shell is being used. | ||
An interactive shell is the default behavior when no command is given to pass to the shell. | ||
- ansible-test - The ``shell`` command no longer redirects all output to stdout when running a provided command. | ||
Any command output written to stderr will be mixed with the stderr output from ansible-test. | ||
- ansible-test - Delegation for commands which generate output for programmatic consumption no longer redirect all output to stdout. | ||
The affected commands and options are ``shell``, ``sanity --lint``, ``sanity --list-tests``, ``integration --list-targets``, ``coverage analyze`` |
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,4 @@ | ||
shippable/posix/group1 # runs in the distro test containers | ||
shippable/generic/group1 # runs in the default test container | ||
context/controller | ||
needs/target/collection |
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 @@ | ||
plugins/modules/python-wrong-shebang.py:1:1: expected module shebang "b'#!/usr/bin/python'" but found: b'#!invalid' |
47 changes: 47 additions & 0 deletions
47
test/integration/targets/ansible-test-sanity-lint/runme.sh
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,47 @@ | ||
#!/usr/bin/env bash | ||
# Make sure that `ansible-test sanity --lint` outputs the correct format to stdout, even when delegation is used. | ||
|
||
set -eu | ||
|
||
# Create test scenarios at runtime that do not pass sanity tests. | ||
# This avoids the need to create ignore entries for the tests. | ||
|
||
mkdir -p ansible_collections/ns/col/plugins/modules | ||
|
||
( | ||
cd ansible_collections/ns/col/plugins/modules | ||
|
||
echo '#!invalid' > python-wrong-shebang.py # expected module shebang "b'#!/usr/bin/python'" but found: b'#!invalid' | ||
) | ||
|
||
source ../collection/setup.sh | ||
|
||
set -x | ||
|
||
### | ||
### Run the sanity test with the `--lint` option. | ||
### | ||
|
||
# Use the `--venv` option to verify that delegation preserves the output streams. | ||
ansible-test sanity --test shebang --color --failure-ok --lint --venv "${@}" 1> actual-stdout.txt 2> actual-stderr.txt | ||
diff -u "${TEST_DIR}/expected.txt" actual-stdout.txt | ||
grep -f "${TEST_DIR}/expected.txt" actual-stderr.txt | ||
|
||
# Run without delegation to verify direct output uses the correct streams. | ||
ansible-test sanity --test shebang --color --failure-ok --lint "${@}" 1> actual-stdout.txt 2> actual-stderr.txt | ||
diff -u "${TEST_DIR}/expected.txt" actual-stdout.txt | ||
grep -f "${TEST_DIR}/expected.txt" actual-stderr.txt | ||
|
||
### | ||
### Run the sanity test without the `--lint` option. | ||
### | ||
|
||
# Use the `--venv` option to verify that delegation preserves the output streams. | ||
ansible-test sanity --test shebang --color --failure-ok --venv "${@}" 1> actual-stdout.txt 2> actual-stderr.txt | ||
grep -f "${TEST_DIR}/expected.txt" actual-stdout.txt | ||
[ ! -s actual-stderr.txt ] | ||
|
||
# Run without delegation to verify direct output uses the correct streams. | ||
ansible-test sanity --test shebang --color --failure-ok "${@}" 1> actual-stdout.txt 2> actual-stderr.txt | ||
grep -f "${TEST_DIR}/expected.txt" actual-stdout.txt | ||
[ ! -s actual-stderr.txt ] |
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,4 @@ | ||
shippable/posix/group1 # runs in the distro test containers | ||
shippable/generic/group1 # runs in the default test container | ||
context/controller | ||
needs/target/collection |
Empty file.
1 change: 1 addition & 0 deletions
1
test/integration/targets/ansible-test-shell/expected-stderr.txt
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 @@ | ||
stderr |
1 change: 1 addition & 0 deletions
1
test/integration/targets/ansible-test-shell/expected-stdout.txt
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 @@ | ||
stdout |
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,30 @@ | ||
#!/usr/bin/env bash | ||
# Make sure that `ansible-test shell` outputs to the correct stream. | ||
|
||
set -eu | ||
|
||
source ../collection/setup.sh | ||
|
||
set -x | ||
|
||
# Try `shell` with delegation. | ||
|
||
ansible-test shell --venv -- \ | ||
python -c 'import sys; print("stdout"); print("stderr", file=sys.stderr)' 1> actual-stdout.txt 2> actual-stderr.txt | ||
|
||
cat actual-stdout.txt | ||
cat actual-stderr.txt | ||
|
||
diff -u "${TEST_DIR}/expected-stdout.txt" actual-stdout.txt | ||
grep -f "${TEST_DIR}/expected-stderr.txt" actual-stderr.txt | ||
|
||
# Try `shell` without delegation. | ||
|
||
ansible-test shell -- \ | ||
python -c 'import sys; print("stdout"); print("stderr", file=sys.stderr)' 1> actual-stdout.txt 2> actual-stderr.txt | ||
|
||
cat actual-stdout.txt | ||
cat actual-stderr.txt | ||
|
||
diff -u "${TEST_DIR}/expected-stdout.txt" actual-stdout.txt | ||
grep -f "${TEST_DIR}/expected-stderr.txt" actual-stderr.txt |
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
Oops, something went wrong.