linux-system-roles / storage

Ansible role for linux storage management
https://linux-system-roles.github.io/storage/
MIT License
99 stars 55 forks source link

test: fix sector-based disk size calculation from ansible_devices #433

Closed vojtechtrefny closed 3 months ago

vojtechtrefny commented 3 months ago

Device sizes specified in sectors are in general in 512 sectors regardless of the actual device physical sector size. Example of ansible_devices facts for a 4k sector size drive:

... "sectors": "41943040", "sectorsize": "4096", "size": "20.00 GB" ...

Resolves: RHEL-30959

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 13.35%. Comparing base (da929b9) to head (0dc6ee8). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #433 +/- ## ========================================== - Coverage 16.54% 13.35% -3.20% ========================================== Files 2 8 +6 Lines 284 1775 +1491 Branches 79 79 ========================================== + Hits 47 237 +190 - Misses 237 1538 +1301 ``` | [Flag](https://app.codecov.io/gh/linux-system-roles/storage/pull/433/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=linux-system-roles) | Coverage Δ | | |---|---|---| | [sanity](https://app.codecov.io/gh/linux-system-roles/storage/pull/433/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=linux-system-roles) | `16.54% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=linux-system-roles#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

richm commented 3 months ago

So is there a bug in https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts/hardware/linux.py#L674 ? specifically https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/facts/hardware/linux.py#L770

                    part['sectorsize'] = get_file_content(part_sysdir + "/queue/logical_block_size")
                    if not part['sectorsize']:
                        part['sectorsize'] = get_file_content(part_sysdir + "/queue/hw_sector_size", 512)

? If so, what should be done to fix that?

richm commented 3 months ago

[citest]

vojtechtrefny commented 3 months ago

The anbile calculations are correct -- all sizes in sysfs are in 512 sectors (large sizes, small sizes like the sector size itself are in bytes) so ansible is just displaying the size the same way kernel/sysfs would. When displaying the "human readable" size the number of sectors is correctly multiplied by 512. For our use case we can simply ignore sector size here, we don't need it.