Skip to content

Commit

Permalink
stabilize ssdhealth UT
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekrnv authored Dec 24, 2024
1 parent 7094494 commit bae161f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions tests/show_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,43 @@ def test_verbose(self):
class TestShowPlatformSsdhealth(object):
# Test 'show platform ssdhealth'
@mock.patch('utilities_common.cli.run_command')
def test_ssdhealth(self, mock_run_command):
@mock.patch('sonic_py_common.device_info.get_platform_json_data')
def test_ssdhealth(self, mock_plat_json, mock_run_command):
mock_plat_json.return_value = {
"chassis": {
"name": "mock_platform"
}
}
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_plat_json.assert_called_with()

@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):
mock_plat_json.return_value = {
"chassis" : {
"name" : "mock_platform"
"chassis": {
"name": "mock_platform"
}
}
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'])
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_plat_json.return_value = {
"chassis" : {
"name" : "mock_platform2",
"disk" : {
"device" : "/dev/nvme0n1"
"chassis": {
"name": "mock_platform2",
"disk": {
"device": "/dev/nvme0n1"
}
}
}
result = CliRunner().invoke(show.cli.commands['platform'].commands['ssdhealth'], ['--verbose'])
CliRunner().invoke(show.cli.commands['platform'].commands['ssdhealth'], ['--verbose'])
mock_plat_json.assert_called_with()
mock_run_command.assert_called_with(['sudo', 'ssdutil', '-d', '/dev/nvme0n1', '-v'], display_cmd=True)

0 comments on commit bae161f

Please sign in to comment.