Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-131373 / 25.04 / Fix serialization error #14568

Merged
merged 5 commits into from
Sep 24, 2024
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
11 changes: 6 additions & 5 deletions src/middlewared/middlewared/plugins/smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
aiden3c marked this conversation as resolved.
Show resolved Hide resolved
import time
import json
from typing import Any

from humanize import ordinal

Expand Down Expand Up @@ -40,7 +41,7 @@ async def annotate_disk_smart_tests(middleware, tests_filter, disk):
return dict(tests=filter_list(tests, tests_filter), current_test=current_test, **disk)


def parse_smart_selftest_results(data) -> list[AtaSelfTest] | list[NvmeSelfTest] | list[ScsiSelfTest] | None:
def parse_smart_selftest_results(data) -> list[dict[str, Any]] | None:
tests = []

# ataprint.cpp
Expand Down Expand Up @@ -71,7 +72,7 @@ def parse_smart_selftest_results(data) -> list[AtaSelfTest] | list[NvmeSelfTest]
else:
test.status = "FAILED"

tests.append(test)
tests.append(test.dict())

return tests

Expand Down Expand Up @@ -103,7 +104,7 @@ def parse_smart_selftest_results(data) -> list[AtaSelfTest] | list[NvmeSelfTest]
else:
test.status = "FAILED"

tests.append(test)
tests.append(test.dict())

return tests

Expand All @@ -112,7 +113,7 @@ def parse_smart_selftest_results(data) -> list[AtaSelfTest] | list[NvmeSelfTest]
if "scsi_self_test_0" in data: # 0 is most recent test
for index in range(0, 20): # only 20 tests can ever return
test_key = f"scsi_self_test_{index}"
if not test_key in data:
if test_key not in data:
break
entry = data[test_key]

Expand Down Expand Up @@ -145,7 +146,7 @@ def parse_smart_selftest_results(data) -> list[AtaSelfTest] | list[NvmeSelfTest]
else:
test.status = "FAILED"

tests.append(test)
tests.append(test.dict())

return tests

Expand Down
96 changes: 48 additions & 48 deletions src/middlewared/middlewared/pytest/unit/plugins/test_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ def test__parse_smart_selftest_results__ataprint__1():
}
}
assert parse_smart_selftest_results(data) == [
AtaSelfTest(
num=0,
description="Short offline",
status="SUCCESS",
status_verbose="Completed without error",
remaining=0.0,
lifetime=16590,
lba_of_first_error=None
),
AtaSelfTest(
num=1,
description="Short offline",
status="SUCCESS",
status_verbose="Completed without error",
remaining=0.0,
lifetime=16589,
lba_of_first_error=None
)
{
"num": 0,
"description": "Short offline",
"status": "SUCCESS",
"status_verbose": "Completed without error",
"remaining": 0.0,
"lifetime": 16590,
"lba_of_first_error": None
},
{
"num": 1,
"description": "Short offline",
"status": "SUCCESS",
"status_verbose": "Completed without error",
"remaining": 0.0,
"lifetime": 16589,
"lba_of_first_error": None
}
]


Expand Down Expand Up @@ -93,15 +93,15 @@ def test__parse_smart_selftest_results__ataprint__2():
}
}
assert parse_smart_selftest_results(data) == [
AtaSelfTest(
num=0,
description="Offline",
status="RUNNING",
status_verbose="Self-test routine in progress",
remaining=1.0,
lifetime=0,
lba_of_first_error=None
)
{
"num": 0,
"description": "Offline",
"status": "RUNNING",
"status_verbose": "Self-test routine in progress",
"remaining": 1.0,
"lifetime": 0,
"lba_of_first_error": None
}
]


Expand All @@ -123,18 +123,18 @@ def test__parse_smart_selftest_results__nvmeprint__1():
"error_count_outdated": 0
}
}) == [
NvmeSelfTest(
num=0,
description="Short",
status="SUCCESS",
status_verbose="Completed without error",
power_on_hours=18636,
failing_lba=None,
nsid=None,
seg=None,
sct=0x0,
code=0x0
),
{
"num": 0,
"description": "Short",
"status": "SUCCESS",
"status_verbose": "Completed without error",
"power_on_hours": 18636,
"failing_lba": None,
"nsid": None,
"seg": None,
"sct": 0x0,
"code": 0x0
},
]


Expand All @@ -152,15 +152,15 @@ def test__parse_smart_selftest_results__scsiprint__1():
}
}
}) == [
ScsiSelfTest(
num=0,
description="Background short",
status="FAILED",
status_verbose="Completed, segment failed",
segment_number=None,
lifetime=3943,
lba_of_first_error=None
),
{
"num": 0,
"description": "Background short",
"status": "FAILED",
"status_verbose": "Completed, segment failed",
"segment_number": None,
"lifetime": 3943,
"lba_of_first_error": None
}
]


Expand Down
Loading