Skip to content

Use ATEX file upload appending for line-by-line log streaming#633

Open
matusmarhefka wants to merge 1 commit into
RHSecurityCompliance:mainfrom
matusmarhefka:issue_521
Open

Use ATEX file upload appending for line-by-line log streaming#633
matusmarhefka wants to merge 1 commit into
RHSecurityCompliance:mainfrom
matusmarhefka:issue_521

Conversation

@matusmarhefka

Copy link
Copy Markdown
Contributor

Add atex_upload_log_data() to lib/results.py, which streams raw data to a named ATEX log file using partial result appending (same filename in multiple partial=True calls causes ATEX to append to the file).

This allows ansible-playbook, oscap and virt-install output to be uploaded to ATEX incrementally as it is produced, providing crash-safety (if the test dies mid-execution, ATEX already has all output up to that point) and keeping output.txt smaller.

The ATEX protocol is consolidated into shared helpers: _atex_write_all() retries partial writes and EINTR, and _atex_send() sends the JSON header then either inline data (per-line streaming) or log files read in 64 KiB chunks. The control fd is cached at module level to avoid repeated env var lookups.

Changes to library modules:

  • lib/results.py: add _atex_write_all(), _atex_send(), _get_atex_fd() cache, and atex_upload_log_data(); modify add_log() and report_atex() to skip re-uploading logs already streamed via _streamed_atex_logs
  • lib/ansible.py: report_from_output() now streams to ATEX when to_file is set, using the file's basename as the ATEX log name
  • lib/oscap.py: add to_file parameter to report_from_verbose(), writing all oscap output to a file (and streaming to ATEX) instead of stdout; keep rules_from_verbose() as a pure parsing generator
  • lib/virt.py: stream virt-install output to ATEX as virt-install.log

Changes to tests:

  • All oscap.report_from_verbose() callers now pass to_file='oscap.log' and call results.add_log('oscap.log') to submit the file for TMT

Resolves: #521

Add atex_upload_log_data() to lib/results.py, which streams raw data
to a named ATEX log file using partial result appending (same filename
in multiple partial=True calls causes ATEX to append to the file).

This allows ansible-playbook, oscap and virt-install output to be
uploaded to ATEX incrementally as it is produced, providing crash-safety
(if the test dies mid-execution, ATEX already has all output up to that
point) and keeping output.txt smaller.

The ATEX protocol is consolidated into shared helpers: _atex_write_all()
retries partial writes and EINTR, and _atex_send() sends the JSON header
then either inline data (per-line streaming) or log files read in 64 KiB
chunks. The control fd is cached at module level to avoid repeated env
var lookups.

Changes to library modules:
- lib/results.py: add _atex_write_all(), _atex_send(), _get_atex_fd()
  cache, and atex_upload_log_data(); modify add_log() and report_atex()
  to skip re-uploading logs already streamed via _streamed_atex_logs
- lib/ansible.py: report_from_output() now streams to ATEX when to_file
  is set, using the file's basename as the ATEX log name
- lib/oscap.py: add to_file parameter to report_from_verbose(), writing
  all oscap output to a file (and streaming to ATEX) instead of stdout;
  keep rules_from_verbose() as a pure parsing generator
- lib/virt.py: stream virt-install output to ATEX as virt-install.log

Changes to tests:
- All oscap.report_from_verbose() callers now pass to_file='oscap.log'
  and call results.add_log('oscap.log') to submit the file for TMT

Resolves: RHSecurityCompliance#521
@matusmarhefka matusmarhefka marked this pull request as ready for review June 15, 2026 11:49

@comps comps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I glanced a bit through the code, provided a few comments inline.

Comment thread lib/ansible.py
Comment on lines +54 to +55
when ATEX is available, the output is streamed to ATEX under the file's
basename.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why basename? ATEX supports full sub-paths in file names, so if somebody uses to_file='foo/bar.log' it should AFAIK work just fine.

Comment thread lib/oscap.py
Comment on lines +242 to +247
for line in lines:
if atex_name:
results.atex_upload_log_data(atex_name, f'{line}\n')
out_file.write(f'{line}\n')
out_file.flush()
yield line

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we write to console here via tee(), but not for ansible (above) where the writing-to-stdout was removed completely?

Comment thread lib/results.py
Comment on lines +102 to +109
_atex_fd = None


def _get_atex_fd():
global _atex_fd
if _atex_fd is None:
_atex_fd = int(os.environ['ATEX_TEST_CONTROL'])
return _atex_fd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the caching? Is getting a variable from os.environ and converting it to an integer an expensive operation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use ATEX file upload appending for logs

2 participants