Skip to content

lib/host: Added raw_disk_is_available() using blkid for reliable raw disk checks. #301

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rushikeshjadhav
Copy link
Contributor

An issue (#276) occurred while expanding a pool using/finding free disks of the hosts (PR #282), hence fixing with this PR.
blkid returns 2 if there is nothing on the disk e.g. LVM, gpt, etc. hence marking disk_is_available.

@stormi
Copy link
Member

stormi commented Apr 22, 2025

I fear regressions here. We use and reuse the same disks over and over in CI. After a test, they do have contents. We don't wipe them fresh everytime we unmount them.

@rushikeshjadhav
Copy link
Contributor Author

I fear regressions here. We use and reuse the same disks over and over in CI. After a test, they do have contents. We don't wipe them fresh everytime we unmount them.

Do you mean that the content is "required to be kept" when unmounting or it's just not cleaned in those CI? May be a wipefs would do during a teardown.

Else we could introduce a different function disk_is_raw and handle it using blkid wherever suitable.

@stormi
Copy link
Member

stormi commented Apr 25, 2025

It's just not cleaned, and we didn't have a reason to enforce that the disk be void of anything before starting tests. The SR creation takes care of overwriting what exists. That's why an available disk is defined as a disk that is not mounted.

If XOSTOR has different requirements, maybe it should use a separate fixture?

@rushikeshjadhav rushikeshjadhav force-pushed the issue-276-available-disk branch from 84039b3 to 1451730 Compare April 28, 2025 12:58
@rushikeshjadhav
Copy link
Contributor Author

rushikeshjadhav commented Apr 28, 2025

In XOSTOR, both used and unused disks are not mounted, so while finding a free disk on server that has "used" disk(s) during pool expansion, the current disk_is_available marks both used and unused disks as available. Proposing to introduce disk_raw=True, does it fit?

@rushikeshjadhav rushikeshjadhav force-pushed the issue-276-available-disk branch 2 times, most recently from 9232983 to 8498419 Compare April 28, 2025 14:32
Copy link
Member

@stormi stormi left a comment

Choose a reason for hiding this comment

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

Works for me. To be seen if creating a new raw_disk_is_available function would be preferred by others.

lib/host.py Outdated
@@ -516,10 +516,12 @@ def disks(self):
disks.sort()
return disks

def disk_is_available(self, disk):
def disk_is_available(self, disk, disk_raw=False):
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this new param is explicit for everyone.
I prefer something like: check_unformatted, check_no_fs or check_wiped.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also find its naming unclear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can rename the parameter from disk_raw to check_raw, else for more elaborate use type option can be introduced. Where type can be raw, LVM2_member, ext3, part etc. and it can be found from blkid or suitable disk management command based on type.

e.g disk_is_available(self, disk, type='raw')

Copy link
Contributor

Choose a reason for hiding this comment

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

Could be interesting to have but I think it should be a different function that the parameter check_raw could use and keep it a bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added raw_disk_is_available() and kept the current function untouched.

@rushikeshjadhav rushikeshjadhav force-pushed the issue-276-available-disk branch from 8498419 to c06bae7 Compare April 29, 2025 18:20
@rushikeshjadhav rushikeshjadhav changed the title lib/host: Improved disk_is_available() using blkid for reliable disk checks. lib/host: Added raw_disk_is_available() using blkid for reliable raw disk checks. Apr 29, 2025
lib/host.py Outdated
Comment on lines 519 to 525
def raw_disk_is_available(self, disk):
return self.ssh_with_result(['blkid', '/dev/' + disk]).returncode == 2

Copy link
Contributor

Choose a reason for hiding this comment

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

A docstring explaining what this new method wrt disk_is_available would be useful, as well as one for the latter for easier comparison.

It could also be good to add type hints on such new functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

…hecks.

Added docstring explaining what this new method does vs `disk_is_available`.
Added type hints.

Signed-off-by: Rushikesh Jadhav <[email protected]>
@rushikeshjadhav rushikeshjadhav force-pushed the issue-276-available-disk branch from c06bae7 to 72bb94a Compare May 7, 2025 17:44
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.

5 participants