Skip to content

Commit

Permalink
Fixed potential issue with parse_id_number not reconciling leading/tr…
Browse files Browse the repository at this point in the history
…ailing spaces
  • Loading branch information
assrinivasan committed May 24, 2024
1 parent af596c9 commit f13e549
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sonic_platform_base/sonic_storage/ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def parse_id_number(self, id, buffer):
if buffer:
buffer_lines = buffer.split('\n')
for line in buffer_lines:
if line.startswith(str(id)):
if line.strip().startswith(str(id)):
return line[len(str(id)):]

return NOT_AVAILABLE
12 changes: 12 additions & 0 deletions tests/test_ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
Selective Self-tests/Logging not supported"""

output_ssd_leading_trailing_spaces = """
241 Host_Writes_32MiB 0x0002 100 001 000 Old_age Always - 178564
242 Host_Reads_32MiB 0x0002 100 001 000 Old_age Always - 760991
"""

output_Innodisk_ssd = """smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.10.0-23-2-amd64] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org
Expand Down Expand Up @@ -1161,6 +1166,13 @@ def test_ssd(self):
assert(ssd.get_disk_io_writes() == '178564')
assert(ssd.get_reserved_blocks() == '146')

@mock.patch('sonic_platform_base.sonic_storage.ssd.SsdUtil._execute_shell', mock.MagicMock(return_value=output_ssd_leading_trailing_spaces))
def test_ssd_leading_trailing_spaces(self):
# Test parsing a normal ssd info
ssd = SsdUtil('/dev/sda')

assert(ssd.get_disk_io_writes() == '178564')
assert(ssd.get_disk_io_reads() == '760991')

@mock.patch('sonic_platform_base.sonic_storage.ssd.SsdUtil._execute_shell', mock.MagicMock(return_value=output_lack_info_ssd))
def test_ssd_with_na_path(self):
Expand Down

0 comments on commit f13e549

Please sign in to comment.