in selftest/selftest.py [0:0]
def get_disk_size_gib(disk_path: str) -> int:
"""Get the size of the disk in GiB."""
try:
proc = subprocess.run(
["lsblk", "-b", "-n", "-o", "SIZE", "-d", disk_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
check=True,
)
logger.debug("lsblk output: %r", proc)
size_bytes = int(proc.stdout.strip())
size_gib = size_bytes // (1024**3)
return size_gib
except subprocess.CalledProcessError as error:
logger.error("error while fetching disk size: %r", error)
raise
except FileNotFoundError:
logger.error("lsblk command not found")
raise