diff --git a/show/platform.py b/show/platform.py index d3e9fa098a3..c890889badc 100644 --- a/show/platform.py +++ b/show/platform.py @@ -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 [] diff --git a/tests/show_platform_test.py b/tests/show_platform_test.py index a867f067ee1..aa31cc47f4f 100644 --- a/tests/show_platform_test.py +++ b/tests/show_platform_test.py @@ -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)