Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

vojtechtrefny
Copy link
Collaborator

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

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

Signed-off-by: Vojtech Trefny <[email protected]>
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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 Coverage Δ
sanity 16.54% <ø> (ø)

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.

@richm
Copy link
Contributor

richm commented Apr 3, 2024

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
Copy link
Contributor

richm commented Apr 3, 2024

[citest]

@vojtechtrefny
Copy link
Collaborator Author

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.

@richm richm merged commit bb1eb23 into linux-system-roles:main Apr 4, 2024
23 of 28 checks passed
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.

2 participants