Skip to content

Commit

Permalink
[nvidia-bluefield] Use NVMe Disk as default for show ssdhealth
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Reddy <vkarri@nvidia.com>
  • Loading branch information
vivekrnv committed Dec 5, 2024
1 parent b767cb8 commit 9528ec4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion show/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ 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]
lsblk_cmd = "lsblk -o NAME,TYPE -p"
platform_info = device_info.get_platform_info()
if platform_info.get('asic_type', '') == 'nvidia-bluefield':
# Skip considering MMC block devices by default
lsblk_cmd = lsblk_cmd + " -e179"
device = os.popen(lsblk_cmd + " | grep disk").readline().strip().split()[0]

cmd = ['sudo', 'ssdutil', '-d', str(device)]
options = ["-v"] if verbose else []
options += ["-e"] if vendor else []
Expand Down
29 changes: 29 additions & 0 deletions tests/show_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,32 @@ def test_verbose(self):
CliRunner().invoke(show.cli.commands['platform'].commands['psustatus'], ['--verbose'])
assert mock_run_command.call_count == 1
mock_run_command.assert_called_with(['psushow', '-s'], display_cmd=True)

class TestShowPlatformSsdhealth(object):
# Test 'show platform ssdhealth'
@mock.patch('utilities_common.cli.run_command')
def test_ssdhealth(self, mock_run_command):
result = CliRunner().invoke(show.cli.commands['platform'].commands['ssdhealth'], ["/dev/nvme0n1", '--verbose'])
assert result.exit_code == 0, result.output
assert mock_run_command.call_count == 1
mock_run_command.assert_called_with(['sudo', 'ssdutil', '-d', '/dev/nvme0n1', '-v'], display_cmd=True)

@mock.patch('os.popen')
@mock.patch('utilities_common.cli.run_command')
@mock.patch('sonic_py_common.device_info.get_platform_info')
def test_ssdhealth_nvda_bf(self, mock_plat_info, mock_run_command, mock_open):
mock_fd = mock.MagicMock()
mock_fd.readline.return_value = "/dev/nvme0n1 disk\n"
mock_open.return_value = mock_fd

result = CliRunner().invoke(show.cli.commands['platform'].commands['ssdhealth'], ['--verbose'])
assert result.exit_code == 0, result.output
mock_open.assert_called_with("lsblk -o NAME,TYPE -p | grep disk")
mock_run_command.assert_called_with(['sudo', 'ssdutil', '-d', '/dev/nvme0n1', '-v'], display_cmd=True)

# Mock platform
mock_plat_info.return_value = {'asic_type': 'nvidia-bluefield'}
result = CliRunner().invoke(show.cli.commands['platform'].commands['ssdhealth'], ['--verbose'])
assert result.exit_code == 0, result.output
mock_open.assert_called_with("lsblk -o NAME,TYPE -p -e179 | grep disk")
mock_run_command.assert_called_with(['sudo', 'ssdutil', '-d', '/dev/nvme0n1', '-v'], display_cmd=True)

0 comments on commit 9528ec4

Please sign in to comment.