-
Notifications
You must be signed in to change notification settings - Fork 710
[ssdutil] Inform if the disk is not SSD #1957
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
sujinmkang
wants to merge
6
commits into
sonic-net:master
Choose a base branch
from
sujinmkang:hdd_ssdutil
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3ac184a
Inform if the disk is not SSD
sujinmkang 217079b
check the disk available
sujinmkang 3cbf9b9
disk name should be same
sujinmkang d17a02f
add finding default-device instead of using the hardcoded one
sujinmkang 35b5cf1
fix lgtm
sujinmkang 237caf7
Update disk check
sujinmkang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,29 @@ | |
|
||
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""" | ||
diskdev_name = diskdev.replace('/dev/','') | ||
cmd = "lsblk -l -n |grep disk" | ||
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE) | ||
outs = proc.stdout.readlines() | ||
for out in outs: | ||
if out.split()[0] is diskdev_name: | ||
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. what if diskdev_name is one of ['sda', 'sdb', 'sdc'], but you seem to be checking only the first element |
||
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): | ||
""" | ||
Loads platform specific or generic ssd_util module from source | ||
|
@@ -65,6 +84,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())) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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