From 3ac184af53644caa5b6a699f61a07d36eee8766d Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Wed, 1 Dec 2021 14:40:46 -0800 Subject: [PATCH] Inform if the disk is not SSD --- ssdutil/main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ssdutil/main.py b/ssdutil/main.py index 62f43037e7..eedac43d35 100755 --- a/ssdutil/main.py +++ b/ssdutil/main.py @@ -8,6 +8,7 @@ try: import argparse import os + import subprocess import sys from sonic_py_common import device_info, logger @@ -16,11 +17,20 @@ DEFAULT_DEVICE="/dev/sda" SYSLOG_IDENTIFIER = "ssdutil" +DISK_TYPE_SSD = "0" # Global logger instance log = logger.Logger(SYSLOG_IDENTIFIER) +def get_disk_type(diskdev): + """Check disk type""" + cmd = "cat /sys/block/{}/queue/rotational".format(diskdev.replace('/dev/','')) + proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE) + out = proc.stdout.readline() + return out.rstrip() + + def import_ssd_api(diskdev): """ Loads platform specific or generic ssd_util module from source @@ -65,6 +75,11 @@ def ssdutil(): parser.add_argument("-e", "--vendor", action="store_true", default=False, help="Show vendor output (extended output if provided by platform vendor)") args = parser.parse_args() + disk_type = get_disk_type(args.device) + if disk_type != DISK_TYPE_SSD: + print("Disk is not SSD") + sys.exit(1) + ssd = import_ssd_api(args.device) print("Device Model : {}".format(ssd.get_model()))