Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sujinmkang
Copy link
Collaborator

@sujinmkang sujinmkang commented Dec 1, 2021

sonic-net/sonic-buildimage#9407

What I did

Inform that the disk is not SSD for the platform with non-SSD disk

How I did it

Check disk type and exit the ssdutil command

How to verify it

Check show platform ssdhealth command on the platform with non SSD disk

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

ssdutil/main.py Outdated Show resolved Hide resolved
prgeor
prgeor previously approved these changes Dec 3, 2021
@prgeor prgeor added the Bug label Dec 3, 2021
neethajohn
neethajohn previously approved these changes Dec 3, 2021

# Global logger instance
log = logger.Logger(SYSLOG_IDENTIFIER)


def get_disk_type(diskdev):
Copy link
Contributor

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

lsblk -l -n | grep 'disk' 

to get the list of all disk names available in the host

@sujinmkang sujinmkang dismissed stale reviews from neethajohn and prgeor via 217079b December 5, 2021 01:18
ssdutil/main.py Outdated
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:
Copy link
Contributor

Choose a reason for hiding this comment

The 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

@lgtm-com
Copy link

lgtm-com bot commented Dec 7, 2021

This pull request introduces 1 alert when merging d17a02f into 2e462ef - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@neethajohn
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@neethajohn
Copy link
Contributor

@prgeor, can you look at the new changes?

prgeor
prgeor previously approved these changes Dec 15, 2021
@neethajohn
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@alexrallen alexrallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sujinmkang while looking this over I had a few comments / questions. Please take a look, thanks.

ssdutil/main.py Outdated
if args.device:
disk_device = args.device
else:
disk_device = get_default_disk()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call get_default_disk() from within argparse? i.e. default=get_default_disk() that would remove the necessity of this code.

if diskdev_name not in out:
return DISK_INVAILD
cmd = "cat /sys/block/{}/queue/rotational".format(diskdev_name)
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forking to cat here seems unnecessary. Is there a reason you chose not to use native python io here?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 DISK_INVALID case rather than forking lsblk as well.

cmd = "lsblk -l -n |grep {}".format(host_mnt)
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
out = proc.stdout.readline()
if host_mnt in out:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary? grep should take care of this. Perhaps check if the result is not empty (or grep return code)?

"""Check default disk"""
default_device = DEFAULT_DEVICE
host_mnt = '/host'
cmd = "lsblk -l -n |grep {}".format(host_mnt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to do this cleaner with df

admin@r-lionfish-16:~$ df --output=source /host
Filesystem
/dev/sda3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants