-
Notifications
You must be signed in to change notification settings - Fork 661
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
[ssdutil] Inform if the disk is not SSD #1957
base: master
Are you sure you want to change the base?
Changes from 1 commit
3ac184a
217079b
3cbf9b9
d17a02f
35b5cf1
237caf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forking to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is also more pythonic to do this and add error handling in order to handle the |
||
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) | ||
neethajohn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ssd = import_ssd_api(args.device) | ||
|
||
print("Device Model : {}".format(ssd.get_model())) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to validate if the listed diskdev is valid as listed by "lsblk" otherwise the utility will crash. you can use
to get the list of all disk names available in the host