From 217079be3bc35f8d9adcafcd396b3f336415ba78 Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Sat, 4 Dec 2021 17:18:30 -0800 Subject: [PATCH] check the disk available --- ssdutil/main.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ssdutil/main.py b/ssdutil/main.py index eedac43d35..c2c1c867a2 100755 --- a/ssdutil/main.py +++ b/ssdutil/main.py @@ -25,10 +25,19 @@ def get_disk_type(diskdev): """Check disk type""" - cmd = "cat /sys/block/{}/queue/rotational".format(diskdev.replace('/dev/','')) + diskdev_name = diskdev.replace('/dev/','') + cmd = "lsblk -l -n |grep disk" proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE) - out = proc.stdout.readline() - return out.rstrip() + outs = proc.stdout.readlines() + for out in outs: + if out.split()[0] in diskdev_name: + cmd = "cat /sys/block/{}/queue/rotational".format(diskdev_name) + proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE) + out = proc.stdout.readline() + return out.rstrip() + + print("disk {} does not exist in the device".format(diskdev_name)) + sys.exit(1) def import_ssd_api(diskdev):