Repository navigation
Extract scripted output from the logs #6
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
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,61 @@ | ||
| """`logs --script`: replay the commands a test run executed, as a shell | ||
| transcript (``[host]# cmd`` followed by its output) from the console log.""" | ||
| import ast | ||
| import re | ||
| import shlex | ||
|
|
||
| _CMD = re.compile(r'^\[ipatests\.\S*?Host\.(?P<host>[\w-]+)\.cmd\d+\] ' | ||
| r'(?P<msg>.*)$') | ||
| _HEADER = re.compile(r'^(?P<id>\S+\.py::\S+)') | ||
| _NOISE = re.compile(r'^(Exit code: \d+$|Warning: Permanently added |' | ||
| r'bash: line \d+: (cd: |/root/ipatests/env\.sh))') | ||
|
|
||
|
|
||
| def _command(msg): | ||
| """The command text of a `RUN ...` message: argv lists become a quoted | ||
| shell line, a plain string (shell=True) is kept as is.""" | ||
| cmd = msg[4:] | ||
| if cmd.startswith('['): | ||
| try: | ||
| return shlex.join(ast.literal_eval(cmd)) | ||
| except (ValueError, SyntaxError): | ||
| pass | ||
| return cmd | ||
|
|
||
|
|
||
| def transcript(lines, test=None, host=None): | ||
| """Yield transcript lines for the tests whose node id contains `test` | ||
| (all when None) and, when `host` is given, only that host.""" | ||
| wanted = test is None | ||
| cur = None | ||
| for line in lines: | ||
| line = line.rstrip('\n') | ||
| h = _HEADER.match(line) | ||
| if h: | ||
| wanted = test is None or test in h['id'] | ||
| if wanted: | ||
| yield f'# == {h["id"]}' | ||
| m = _CMD.match(line) | ||
| if not (wanted and m) or (host and m['host'] != host): | ||
| continue | ||
| msg = m['msg'] | ||
| if msg.startswith('RUN '): | ||
| cmd = _command(msg) | ||
| if cmd.startswith('-o ') or cmd == 'true' or '/root/ipatests' in cmd: | ||
| cur = None # ssh keepalive / framework bookkeeping, not a test step | ||
| continue | ||
| cur = m['host'] | ||
| yield f'[{cur}]# {cmd}' | ||
| elif cur and not _NOISE.match(msg): | ||
| yield msg | ||
|
|
||
|
|
||
| def per_test(lines): | ||
| """{node id: transcript lines} for every test in the console log.""" | ||
| out, cur = {}, None | ||
| for line in transcript(lines): | ||
| if line.startswith('# == '): | ||
| cur = out.setdefault(line[5:], []) | ||
| elif cur is not None: | ||
| cur.append(line) | ||
| return out | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.