Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ansible FreeIPA
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Ansible FreeIPA
Commits
a4860f7b
Unverified
Commit
a4860f7b
authored
9 months ago
by
Rafael Guterres Jeffman
Committed by
GitHub
9 months ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1270 from t-woerner/truncate_stdout_and_stderr_in_upstream_test_log
Truncate stdout and stderr in upstream test log
parents
16a4eb81
3dfa026e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/utils.py
+31
-2
31 additions, 2 deletions
tests/utils.py
with
31 additions
and
2 deletions
tests/utils.py
+
31
−
2
View file @
a4860f7b
...
...
@@ -162,6 +162,22 @@ def _run_playbook(playbook):
return
process
def
_truncate
(
lines
,
charcount
,
minlines
=
0
):
output
=
""
line_count
=
1
for
i
in
range
(
len
(
lines
)
-
1
,
-
1
,
-
1
):
if
len
(
output
)
+
len
(
lines
[
i
])
+
1
<=
charcount
or
\
line_count
<
minlines
:
output
=
lines
[
i
]
+
"
\n
"
+
output
line_count
+=
1
else
:
remaining
=
charcount
-
len
(
output
)
-
1
-
4
if
remaining
>
60
:
output
=
"
...
"
+
lines
[
i
][
-
(
remaining
):]
+
"
\n
"
+
output
break
return
output
def
run_playbook
(
playbook
,
allow_failures
=
False
):
"""
Run an Ansible playbook and assert the return code.
...
...
@@ -183,13 +199,26 @@ def run_playbook(playbook, allow_failures=False):
status_code_msg
=
"
ansible-playbook return code: {0}
"
.
format
(
result
.
returncode
)
_stdout
=
result
.
stdout
.
decode
(
"
utf8
"
)
_stderr
=
result
.
stderr
.
decode
(
"
utf8
"
)
# Truncate stdout and stderr in the way that it hopefully
# shows all important information. At least 15 lines of stdout
# (Ansible tasks) and remaining from stderr to fill up to
# maxlen size.
maxlen
=
2000
factor
=
maxlen
/
(
len
(
_stdout
)
+
len
(
_stderr
))
stdout
=
_truncate
(
_stdout
.
splitlines
(),
int
(
factor
*
len
(
_stdout
)),
minlines
=
15
)
stderr
=
_truncate
(
_stderr
.
splitlines
(),
maxlen
-
len
(
stdout
))
assert_msg
=
"
\n
"
.
join
(
[
""
,
"
-
"
*
30
+
"
Captured stdout
"
+
"
-
"
*
30
,
result
.
stdout
.
decode
(
"
utf8
"
)
,
stdout
,
"
-
"
*
30
+
"
Captured stderr
"
+
"
-
"
*
30
,
result
.
stderr
.
decode
(
"
utf8
"
)
,
stderr
,
"
-
"
*
30
+
"
Playbook Return Code
"
+
"
-
"
*
30
,
status_code_msg
,
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment