Skip to content

Commit

Permalink
Use the disk currently in use by SONiC for the 'show platform ssdheal…
Browse files Browse the repository at this point in the history
…th' command.
  • Loading branch information
roger530-ho committed Sep 19, 2024
1 parent 867fc54 commit c711c64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion show/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ def psustatus(index, json, verbose):
def ssdhealth(device, verbose, vendor):
"""Show SSD Health information"""
if not device:
device = os.popen("lsblk -o NAME,TYPE -p | grep disk").readline().strip().split()[0]
# Looking for the SSD disk currently used by the SONiC.

base_device = os.popen("lsblk -l -o NAME,TYPE,MOUNTPOINT -p | grep -w '/host'").readline().strip().split()[0]

# Extract the base device name, handling both 'p' and non-'p' partitioning schemes
# Example : /dev/sda1 => /dev/sda
# /dev/nvme0n1p2 => /dev/nvme0n1
# /dev/mmcblk0p1 => /dev/mmcblk0
device = base_device.rstrip("0123456789").split("p")[0]
cmd = ['sudo', 'ssdutil', '-d', str(device)]
options = ["-v"] if verbose else []
options += ["-e"] if vendor else []
Expand Down
2 changes: 1 addition & 1 deletion tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def test_ssdhealth(self, mock_popen, mock_run_command):
print(result.exit_code)
print(result.output)
assert result.exit_code == 0
mock_popen.assert_called_once_with('lsblk -o NAME,TYPE -p | grep disk')
mock_popen.assert_called_once_with("lsblk -l -o NAME,TYPE,MOUNTPOINT -p | grep -w '/host'")
mock_run_command.assert_called_once_with(['sudo', 'ssdutil', '-d', '/dev/sda', '-v', '-e'], display_cmd=True)

@patch('utilities_common.cli.run_command')
Expand Down

0 comments on commit c711c64

Please sign in to comment.