Skip to content

test: refactor test setup to add device info#617

Open
richm wants to merge 2 commits intolinux-system-roles:mainfrom
richm:test-refactor-setup
Open

test: refactor test setup to add device info#617
richm wants to merge 2 commits intolinux-system-roles:mainfrom
richm:test-refactor-setup

Conversation

@richm
Copy link
Copy Markdown
Contributor

@richm richm commented Apr 30, 2026

Refactor the tests so that we can have a common tests/tasks/setup.yml to handle
common setup tasks as well as print some diagnostic information before each
test run to see if we can solve some of these test flakes.

Signed-off-by: Rich Megginson [email protected]

Summary by Sourcery

Refactor storage-related Ansible tests to use a shared setup task file for common preparation and diagnostics.

Tests:

  • Introduce a shared tests/tasks/setup.yml to centralize storage test preparation, including role invocation, skip checks, package/distro facts, unused disk discovery, and device diagnostics.
  • Update all storage-focused test playbooks to use the shared setup task with configurable _storage* variables for disk selection and environment conditions.
  • Move and generalize get_unused_disk task into tests/tasks/get_unused_disk.yml so it can consume the shared _storage* parameters across tests.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 30, 2026

Reviewer's Guide

Refactors storage-related Ansible tests to use a new shared tests/tasks/setup.yml that centralizes role prep, package fact gathering, distribution flags, unused-disk discovery, and device diagnostics, replacing duplicated setup logic in each test and updating calls to the disk discovery helper.

File-Level Changes

Change Details Files
Introduce centralized storage test setup task file and wire most tests to it via _storage* variables.
  • Add tests/tasks/setup.yml to encapsulate running the storage role, setting storage_skip_checks, gathering package facts, computing blivet_pkg_version, setting is_rhel*/is_fedora/is_rhel78 flags, optionally discovering unused disks, and printing storage device diagnostics.
  • Replace per-playbook setup blocks (run_role_with_clear_facts, storage_skip_checks, package_facts, blivet version and distro flags, and direct get_unused_disk calls) with a single include of tasks/setup.yml in the various storage test playbooks.
  • Use per-test _storage* variables (e.g., __storage_min_size, __storage_max_return, __storage_disks_needed, __storage_match_sector_size, __storage_max_size, __storage_storage_skip_checks, __storage_get_package_facts, __storage_get_unused_disks) to parameterize common setup behavior without duplicating logic.
tests/tasks/setup.yml
tests/tests_create_lvmvdo_then_remove.yml
tests/tests_lvm_pool_members.yml
tests/tests_stratis.yml
tests/tests_create_lvm_cache_then_remove.yml
tests/tests_create_raid_pool_then_remove.yml
tests/tests_resize.yml
tests/tests_lvm_pool_shared.yml
tests/tests_swap.yml
tests/tests_misc.yml
tests/tests_lvm_multiple_disks_multiple_volumes.yml
tests/tests_fatals_cache_volume.yml
tests/tests_lvm_pool_pv_grow.yml
tests/tests_lvm_auto_size_cap.yml
tests/tests_change_disk_fs.yml
tests/tests_change_disk_mount.yml
tests/tests_change_fs.yml
tests/tests_change_fs_use_partitions.yml
tests/tests_change_mount.yml
tests/tests_create_lv_size_equal_to_vg.yml
tests/tests_create_lvm_pool_then_remove.yml
tests/tests_create_raid_volume_then_remove.yml
tests/tests_disk_errors.yml
tests/tests_existing_lvm_pool.yml
tests/tests_fatals_raid_pool.yml
tests/tests_fatals_raid_volume.yml
tests/tests_lvm_errors.yml
tests/tests_lvm_one_disk_multiple_volumes.yml
tests/tests_lvm_one_disk_one_volume.yml
tests/tests_null_raid_pool.yml
tests/tests_raid_pool_options.yml
tests/tests_raid_volume_options.yml
tests/tests_remove_mount.yml
tests/tests_safe_mode_check.yml
tests/tests_volume_relabel.yml
tests/tests_create_disk_then_remove.yml
tests/tests_create_multiple_partitions_dos.yml
tests/tests_create_multiple_partitions_gpt.yml
tests/tests_create_partition_volume_then_remove.yml
tests/tests_filesystem_one_disk.yml
tests/tests_luks_pool.yml
tests/tests_missing_volume_type_in_pool.yml
tests/tests_raid_volume_cleanup.yml
tests/tests_remove_nonexistent_pool.yml
tests/tests_create_thinp_then_remove.yml
tests/tests_luks.yml
tests/tests_luks2.yml
tests/tests_lvm_percent_size.yml
Refactor unused-disk discovery helper and its usage to support new _storage* parameters and task path.
  • Move get_unused_disk.yml into tests/tasks/get_unused_disk.yml and update all includes to use ansible.builtin.include_tasks with the new path.
  • Enhance the find_unused_disk call to fall back from local variables (min_size, max_size, max_return, match_sector_size) to corresponding _storage* variables when the former are not defined, allowing central configuration from setup.yml or the play.
  • Keep behavior of storage_test_use_interface and unused_disks_return registration intact while making the helper more flexible and compatible with the new setup flow.
tests/tasks/get_unused_disk.yml
tests/tests_create_lvmvdo_then_remove.yml
tests/tests_lvm_pool_members.yml
tests/tests_stratis.yml
tests/tests_create_lvm_cache_then_remove.yml
tests/tests_create_raid_pool_then_remove.yml
tests/tests_resize.yml
tests/tests_lvm_pool_shared.yml
tests/tests_misc.yml
Add pre-test storage device diagnostics to help debug flaky tests.
  • In setup.yml, add a shell task that runs lsblk, mdadm --examine --scan, dmsetup ls --tree, lvm vgdisplay, and udevadm settle to log current storage topology before tests run, without marking the play as changed.
  • Ensure the diagnostics write to stderr and are non-destructive, serving purely as informational output for debugging test flakes.
tests/tasks/setup.yml
Minor cleanups and Ansible best-practice updates in tests.
  • Prefix core Ansible tasks with ansible.builtin (e.g., include_tasks, command, shell, package_facts, set_fact, stat) for clarity and FQCN compliance.
  • Simplify some when conditions by relying on distro/version flags defined centrally in setup.yml instead of recomputing them in each play.
  • Remove the now-unused tasks/stat_device.yml file as its responsibility is effectively covered by the new diagnostics step.
tests/tests_create_lvmvdo_then_remove.yml
tests/tests_lvm_pool_members.yml
tests/tests_stratis.yml
tests/tests_lvm_pool_shared.yml
tests/tests_misc.yml
tests/tasks/setup.yml
tasks/stat_device.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 10.16%. Comparing base (59fd1c6) to head (0b5fd4a).
⚠️ Report is 139 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (59fd1c6) and HEAD (0b5fd4a). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (59fd1c6) HEAD (0b5fd4a)
sanity 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #617      +/-   ##
==========================================
- Coverage   16.54%   10.16%   -6.39%     
==========================================
  Files           2        9       +7     
  Lines         284     2056    +1772     
  Branches       79        0      -79     
==========================================
+ Hits           47      209     +162     
- Misses        237     1847    +1610     
Flag Coverage Δ
sanity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@richm
Copy link
Copy Markdown
Contributor Author

richm commented Apr 30, 2026

[citest]

Refactor the tests so that we can have a common tests/tasks/setup.yml to handle
common setup tasks as well as print some diagnostic information before each
test run to see if we can solve some of these test flakes.

Signed-off-by: Rich Megginson <[email protected]>
@richm richm force-pushed the test-refactor-setup branch from 388395f to 6c0c2f3 Compare April 30, 2026 22:25
@richm
Copy link
Copy Markdown
Contributor Author

richm commented Apr 30, 2026

[citest]

@richm
Copy link
Copy Markdown
Contributor Author

richm commented May 1, 2026

[citest]

1 similar comment
@richm
Copy link
Copy Markdown
Contributor Author

richm commented May 1, 2026

[citest]

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.

1 participant