Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions show/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ def ssdhealth(device, verbose, vendor):
if platform_data:
device = platform_data.get("chassis", {}).get("disk", {}).get("device", None)

if not device:
# Fallback to discovery
device = os.popen("lsblk -o NAME,TYPE -p | grep disk").readline().strip().split()[0]
# if device argument is not provided ssdutil will display the health of the disk containing
# the /host partition. In sonic this is the primary storage device.
if device:
cmd = ['sudo', 'ssdutil', '-d', str(device)]
else:
cmd = ['sudo', 'ssdutil']

cmd = ['sudo', 'ssdutil', '-d', str(device)]
options = ["-v"] if verbose else []
options += ["-e"] if vendor else []
clicommon.run_command(cmd + options, display_cmd=verbose)
Expand Down
10 changes: 3 additions & 7 deletions tests/show_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,17 @@ def test_ssdhealth(self, mock_run_command):
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_json_data')
def test_ssdhealth_default_device(self, mock_plat_json, mock_run_command, mock_open):
def test_ssdhealth_default_device(self, mock_plat_json, mock_run_command):
mock_plat_json.return_value = {
"chassis": {
"name": "mock_platform"
}
}
mock_fd = mock.MagicMock()
mock_fd.readline.return_value = "/dev/nvme0n1 disk\n"
mock_open.return_value = mock_fd

CliRunner().invoke(show.cli.commands['platform'].commands['ssdhealth'], ['--verbose'])
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_run_command.assert_called_with(['sudo', 'ssdutil', '-v'], display_cmd=True)

mock_plat_json.return_value = {
"chassis": {
Expand Down
7 changes: 2 additions & 5 deletions tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,21 +686,18 @@ def test_syseeprom(self, mock_run_command):

@mock.patch('sonic_py_common.device_info.get_platform_json_data')
@patch('utilities_common.cli.run_command')
@patch('os.popen')
def test_ssdhealth(self, mock_popen, mock_run_command, mock_plat_json):
def test_ssdhealth(self, mock_run_command, mock_plat_json):
mock_plat_json.return_value = {
"chassis": {
"name": "mock_platform"
}
}
mock_popen.return_value.readline.return_value = '/dev/sda\n'
runner = CliRunner()
result = runner.invoke(show.cli.commands['platform'].commands['ssdhealth'], ['--verbose', '--vendor'])
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_run_command.assert_called_once_with(['sudo', 'ssdutil', '-d', '/dev/sda', '-v', '-e'], display_cmd=True)
mock_run_command.assert_called_once_with(['sudo', 'ssdutil', '-v', '-e'], display_cmd=True)

@patch('utilities_common.cli.run_command')
def test_pcieinfo(self, mock_run_command):
Expand Down
Loading