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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,22 @@ def disks(self):
disks.sort()
return disks

def disk_is_available(self, disk):
def raw_disk_is_available(self, disk: str) -> bool:
"""
Check if a raw disk (without any identifiable filesystem or partition label) is available.
It suggests the disk is "raw" and likely unformatted thus available.
"""
return self.ssh_with_result(['blkid', '/dev/' + disk]).returncode == 2

def disk_is_available(self, disk: str) -> bool:
"""
Check if a disk is unmounted and appears available for use.
It may or may not contain identifiable filesystem or partition label.
If there are no mountpoints, it is assumed that the disk is not in use.

Warn: This function may misclassify LVM_member disks (e.g. in XOSTOR, RAID, ZFS) as "available".
Such disks may not have mountpoints but still be in use.
"""
return len(self.ssh(['lsblk', '-n', '-o', 'MOUNTPOINT', '/dev/' + disk]).strip()) == 0

def available_disks(self, blocksize=512):
Expand Down