Skip to content

feat(insights): capture additional archive data for insights-client tests - #71

Open
stephenbourke wants to merge 2 commits into
mainfrom
sbourke/insights-client-collect-artifacts
Open

stephenbourke wants to merge 2 commits into
mainfrom
sbourke/insights-client-collect-artifacts

Conversation

@stephenbourke

@stephenbourke stephenbourke commented Nov 24, 2026 •

Copy link
Copy Markdown
  • Card ID: CCT-2799

    • Registration markers (/etc/insights-client/.registered and
      .unregistered) and machine-id are stored in the archive.
      They are backed up before each test and restored after, so
      tests start from a known registration state.
    • The OS compose, architecture, FIPS mode, ENV_FOR_DYNACONF and
      the git branch of the test project is captured in environment.txt.
    • Every audit-tool invocation goes through one helper. Moved the
      audit-log flush from from plugin to selinux. SELinuxAVCChecker.finish()
      encapsulates collects AVCs in a single call and closes the minitoring
      window.
    • Updated TESTING.MD with test artifact layout.

@stephenbourke
stephenbourke force-pushed the sbourke/insights-client-collect-artifacts branch 5 times, most recently from 5f2144d to 9d6c7dd Compare November 24, 2026 16:27
@stephenbourke stephenbourke changed the title feat(insights): capture additional archive data for insights-client t… feat(insights): capture additional archive data for insights-client tests Nov 24, 2026
@stephenbourke
stephenbourke force-pushed the sbourke/insights-client-collect-artifacts branch from 9d6c7dd to 92d2003 Compare November 24, 2026 16:40
Comment thread pytest_client_tools/selinux.py Resolved
marker = f"pytest-client-tools-{uuid.uuid4()}"
_run_audit_tool(["auditctl", "-m", marker], check=True)
for _ in range(1, 100):
proc = _run_audit_tool(["ausearch", "-i", "-m", "user"], check=False)

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.

No timeout, and the loop gives up after 100 iterations silently — finish() can return an incomplete excerpt. Add timeout=10 and a warning log when the marker never appears.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a loop with a timeout (10s) when checking for the marker and a warning log when not found.

self.end_time = datetime.now()
return False

def finish(self):

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.

This is untested. flush_audit_events() and finish() are mock-friendly (assert order: flush → end_time → all AVCs); please add cases in tests/test_selinux.py if possiblee

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added some tests for these functions in test_selinux.py

_flush_audit_events()
checker.end_time = datetime.datetime.now()
avcs = list(checker.get_avcs(skiplisted=False))
avcs = checker.finish()

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.

Clean runs return [] (see selinux.py:266), so the if avcs: guard below never writes selinux.log, no AVC section for the most common failure shape. Potential fix might be to write checker.last_report unconditionally.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the guard. So selinux.log will be written unconditionally.

def insights_client(save_insights_client_files, test_config):
def insights_client(save_insights_client_files, test_config, request):
running_data = pytest._client_tools.running_data[request.node.nodeid]
running_data.artifacts.write_text("environment.txt", collect_environment_metadata())

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.

Only tests pulling this fixture get env metadata, while selinux.log is autouse; a subman/rhc failure gets no env. Also, AC2 wants a --status snapshot: add insights-client.run("--status", check=False, selinux_context=None) → write_text("insights-client-status.txt", ...).

@stephenbourke stephenbourke Nov 26, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This fixture will now record the status in insights-client-status.txt through _archive_registration_state.

Comment thread pytest_client_tools/util.py Outdated
with open("/etc/os-release") as f:
for line in f:
key, sep, value = line.partition("=")
if sep and key.strip() == "PRETTY_NAME":

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.

PRETTY_NAME is identical across nightlies ("RHEL 9.7 (Plow)") — not a compose. Please capture a real build id (TF request metadata, or VERSION_ID/BUILD_ID + rpm -q insights-client insights-core selinux-policy).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed PRETTY_NAME and now capturing VERSION_ID/BUILD_ID and the output rpm -q specifically for the presence of each package in the environment.txt artifact.

Comment thread pytest_client_tools/util.py Outdated

def _test_branch():
"""Return the git branch of the running test project."""
branch = os.environ.get("GIT_BRANCH") or os.environ.get("BRANCH")

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.

In CI this might yield HEAD (detached rev-parse --abbrev-ref) or unknown (TF sources without .git), no?. Also check CHANGE_BRANCH/GITHUB_HEAD_REF, use cwd=$TMT_TREE, and always record git rev-parse --short HEAD as that's what makes a run reproducible.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

_test_branch now employs this suggested approach.

Comment thread pytest_client_tools/util.py Outdated
return (
f"compose: {_os_compose()}\n"
f"arch: {platform.machine()}\n"
f"fips: {_fips_enabled()}\n"

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.

Nit: fips: enabled/disabled reads better than 1/0

Comment thread TESTING.md
## Per-test artifact bundle

Each test collects its artifacts in its own directory under `artifacts/`,
laid out as `artifacts/<module>[/<class>]/<test>/`. The bundle is

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.

AC3 also asks for where to find it: add that the systemtest copies ./artifacts to $TMT_PLAN_DATA (systemtest/tests/integration/test.sh:49-52) and that on Jenkins it's artifacts/ in the workspace, plus one line that no secrets are captured.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Update the description to include the above.

…ests

* Card ID: CCT-2799

- Registration markers (/etc/insights-client/.registered and
  .unregistered) and machine-id are stored in the archive.
  They are backed up before each test and restored after, so
  tests start from a known registration state.
- The OS compose, architecture, FIPS mode, ENV_FOR_DYNACONF and
  the git branch of the test project is captured in environment.txt.
- Every audit-tool invocation goes through one helper. Moved the
  audit-log flush from from plugin to selinux. SELinuxAVCChecker.finish()
  encapsulates collects AVCs in a single call and closes the minitoring
  window.
- Updated TESTING.MD with test artifact layout

Signed-off-by: Stephen Bourke <sbourke@redhat.com>
@stephenbourke
stephenbourke force-pushed the sbourke/insights-client-collect-artifacts branch from 92d2003 to 8b27be4 Compare November 26, 2026 14:31
Comment thread pytest_client_tools/util.py Fixed
…f sensitive information'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@Peto-RH
Peto-RH self-requested a review November 26, 2026 15:40

This branch has not been deployed

No deployments
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.

3 participants