Skip to content

tests: replace hardcoded test pool names with unique checksummed names#995

Open
tasleson wants to merge 1 commit into
snapshotmanager:mainfrom
tasleson:test_asset_names
Open

tests: replace hardcoded test pool names with unique checksummed names#995
tasleson wants to merge 1 commit into
snapshotmanager:mainfrom
tasleson:test_asset_names

Conversation

@tasleson

@tasleson tasleson commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Test resources previously used generic names (test_vg0, pool0, pool1)
that could theoretically collide with real resources and made it
impossible to verify ownership before cleanup.

Replace with dynamically generated names in the format:
snapm_<8 random hex>_<4 hex SHA-256 checksum>

The embedded checksum allows the cleanup script to validate that a
resource was created by the test suite before destroying it. A
standalone bash CLI tool (snapm-test-name) is provided for developers
to manually generate and validate names.

Resolves: #978

Note: This may all seem like overkill, but this is one of those "Low-probability, high-consequence events"

Summary by CodeRabbit

  • Chores
    • Added checksum-based helpers for generating and validating snapm test resource names, replacing brittle fixed identifiers.
    • Introduced a new command-line utility to generate/validate snapm test names.
    • Improved test cleanup to remove only snapshot-managed devices using validated naming patterns.
    • Updated test infrastructure to derive LVM volume-group and Stratis pool identifiers dynamically, including fstab/device path expectations.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8727df2e-77c1-4ced-a098-df54b7618e59

📥 Commits

Reviewing files that changed from the base of the PR and between 789c9a1 and ac2f559.

📒 Files selected for processing (8)
  • tests/_util.py
  • tests/bin/cleanup.sh
  • tests/bin/snapm-test-name
  • tests/test_boot.py
  • tests/test_lvm2.py
  • tests/test_manager.py
  • tests/test_mounts.py
  • tests/test_stratis.py
✅ Files skipped from review due to trivial changes (1)
  • tests/test_manager.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • tests/test_lvm2.py
  • tests/test_boot.py
  • tests/_util.py
  • tests/bin/cleanup.sh
  • tests/bin/snapm-test-name
  • tests/test_mounts.py

Walkthrough

This pull request adds checksum-based helpers for generating and validating snapm test names, updates the cleanup script to target only validated snapshot-managed devices, and replaces hardcoded LVM and Stratis identifiers across the tests with shared generated constants.

Changes

Test naming and cleanup

Layer / File(s) Summary
Shared naming helpers
tests/_util.py
Adds checksum-based test-name generation and validation helpers, and replaces fixed LVM and Stratis identifiers with generated names.
Cleanup script validation
tests/bin/cleanup.sh
Adds snapm name validation, derives the repository root from the script location, and cleans up matching LVM and Stratis resources by discovered name.
Test suite name updates
tests/test_boot.py, tests/test_lvm2.py, tests/test_manager.py, tests/test_mounts.py, tests/test_stratis.py
Switches tests from hardcoded test_vg0, pool0, and pool1 values to shared generated constants in device paths, pool lookups, and accounting assertions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • snapshotmanager/snapm#388: Updates the same Stratis cleanup path in tests/bin/cleanup.sh, including filesystem destruction before conditional pool removal.

Suggested labels: Python, Cleanup

Suggested reviewers: bmr-cymru

Poem

A rabbit hopped through names so neat,
With checksums tucked at tail and feet.
No more pool names bland and plain,
Or cleanup woes from stray domain.
Hop, hop—tests glow tidy and sweet.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the main change: replacing hardcoded test names with generated checksummed names.
Linked Issues check ✅ Passed The changes satisfy #978 by replacing hardcoded pool names, updating test references, and hardening cleanup to only remove test-created resources.
Out of Scope Changes check ✅ Passed The added name-generation CLI is a supporting utility for the naming change and does not appear unrelated to the issue scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@packit-as-a-service

Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo dnf install -y 'dnf*-command(copr)'
  • dnf copr enable packit/snapshotmanager-snapm-995
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/bin/snapm-test-name (1)

15-24: Reject invalid subsystem and context values at generation time.

This CLI currently accepts arbitrary strings, so it can emit names with spaces, slashes, or overlong segments that LVM/Stratis cannot actually create. Failing fast here keeps the new manual workflow reliable.

Suggested hardening
 _generate() {
     local subsystem="$1"
     local context="$2"
+    [[ "$subsystem" =~ ^(lm|st)$ ]] || {
+        printf 'Invalid subsystem: %s\n' "$subsystem" >&2
+        return 2
+    }
+    [[ "$context" =~ ^[a-z0-9]+$ ]] || {
+        printf 'Invalid context: %s\n' "$context" >&2
+        return 2
+    }
     local random_hex
     random_hex=$(od -An -tx1 -N4 /dev/urandom | tr -d ' \n')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/bin/snapm-test-name` around lines 15 - 24, In _generate(), validate the
incoming subsystem and context variables before building the name: ensure they
are non-empty, match a safe charset (e.g., allow only [A-Za-z0-9._-] and reject
spaces/slashes/other punctuation), and enforce a maximum segment length (pick a
sane limit like 32 characters) to prevent overly long LVM/Stratis names; if
validation fails, print a clear error to stderr and exit or return a non-zero
status instead of emitting a name. Use the existing symbols subsystem, context,
and the _generate function to locate where to add these checks and the error
path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/bin/cleanup.sh`:
- Around line 25-39: The _validate_snapm_name() function currently only checks
the trailing separator and 4-char checksum; tighten it to validate the full
advertised format by matching the name against the pattern
snapm_<subsystem>_<context>_<8hex>_<4hex> (validate subsystem/context token
structure and that the two hex fields are the correct lengths and hex
characters), then compute/verify the trailing 4-char checksum as now; update the
validators in tests/_util.py and tests/bin/snapm-test-name to use the same
strict regex and checksum logic so the ownership check used before
vgremove/stratis destroy only accepts properly formatted test-owned names.
- Around line 41-49: The cleanup loop currently sets LVM_SYSTEM_DIR from the
caller's $PWD which breaks when the script is run outside the repo; instead
determine the repo root relative to the script and set LVM_SYSTEM_DIR from that.
In tests/bin/cleanup.sh compute the script directory using ${BASH_SOURCE[0]}
(e.g., resolve dirname "${BASH_SOURCE[0]}" and cd to its parent to get the repo
root) and export LVM_SYSTEM_DIR="$REPO_ROOT/tests/lvm" before calling vgremove
inside the for-loop (symbols to update: the LVM_SYSTEM_DIR export in the
vgremove block, and ensure this resolution happens prior to using
_validate_snapm_name / vgremove).

---

Nitpick comments:
In `@tests/bin/snapm-test-name`:
- Around line 15-24: In _generate(), validate the incoming subsystem and context
variables before building the name: ensure they are non-empty, match a safe
charset (e.g., allow only [A-Za-z0-9._-] and reject spaces/slashes/other
punctuation), and enforce a maximum segment length (pick a sane limit like 32
characters) to prevent overly long LVM/Stratis names; if validation fails, print
a clear error to stderr and exit or return a non-zero status instead of emitting
a name. Use the existing symbols subsystem, context, and the _generate function
to locate where to add these checks and the error path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2fb3ff91-40ed-4964-8cd6-6cfa9b3d0bb3

📥 Commits

Reviewing files that changed from the base of the PR and between 50e9872 and 789c9a1.

📒 Files selected for processing (8)
  • tests/_util.py
  • tests/bin/cleanup.sh
  • tests/bin/snapm-test-name
  • tests/test_boot.py
  • tests/test_lvm2.py
  • tests/test_manager.py
  • tests/test_mounts.py
  • tests/test_stratis.py

Comment thread tests/bin/cleanup.sh
Comment thread tests/bin/cleanup.sh
@bmr-cymru bmr-cymru assigned bmr-cymru and tasleson and unassigned bmr-cymru Jun 10, 2026
@bmr-cymru bmr-cymru self-requested a review June 10, 2026 12:40
@bmr-cymru

Copy link
Copy Markdown
Contributor

Rebased to current main to pick up GitHub CI fix.

Test resources previously used generic names (test_vg0, pool0, pool1)
that could theoretically collide with real resources and made it
impossible to verify ownership before cleanup.

Replace with dynamically generated names in the format:
snapm_<subsystem>_<context>_<8 random hex>_<4 hex SHA-256 checksum>

The embedded checksum allows the cleanup script to validate that a
resource was created by the test suite before destroying it. A
standalone bash CLI tool (snapm-test-name) is provided for developers
to manually generate and validate names.

Resolves: snapshotmanager#978

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>

@bmr-cymru bmr-cymru 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 was a bit wary of the more complicated device names initially, but I've played around with them and they are not to onerous, either in the CLI/test logs, or in the terminal. I like the checksum validation and I think this is a good solution to the problem.

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.

tests: make test pool names more collision resistant

2 participants