Repository navigation
feat(insights): capture additional archive data for insights-client tests - #71
stephenbourke wants to merge 2 commits into
Conversation
5f2144d to
9d6c7dd
Compare
9d6c7dd to
92d2003
Compare
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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", ...).
There was a problem hiding this comment.
This fixture will now record the status in insights-client-status.txt through _archive_registration_state.
| with open("/etc/os-release") as f: | ||
| for line in f: | ||
| key, sep, value = line.partition("=") | ||
| if sep and key.strip() == "PRETTY_NAME": |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
|
|
||
| def _test_branch(): | ||
| """Return the git branch of the running test project.""" | ||
| branch = os.environ.get("GIT_BRANCH") or os.environ.get("BRANCH") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
_test_branch now employs this suggested approach.
| return ( | ||
| f"compose: {_os_compose()}\n" | ||
| f"arch: {platform.machine()}\n" | ||
| f"fips: {_fips_enabled()}\n" |
There was a problem hiding this comment.
Nit: fips: enabled/disabled reads better than 1/0
| ## 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
92d2003 to
8b27be4
Compare
…f sensitive information' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Card ID: CCT-2799
.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 git branch of the test project is captured in environment.txt.
audit-log flush from from plugin to selinux. SELinuxAVCChecker.finish()
encapsulates collects AVCs in a single call and closes the minitoring
window.