|
25 | 25 | ############################################################################### |
26 | 26 | import os |
27 | 27 | import re |
| 28 | +import traceback |
28 | 29 |
|
29 | 30 | from pydantic import ValidationError |
30 | 31 |
|
@@ -103,11 +104,11 @@ def collect_data( |
103 | 104 | if all_device_data: |
104 | 105 | try: |
105 | 106 | nvme_data = NvmeDataModel(devices=all_device_data) |
106 | | - except ValidationError as e: |
| 107 | + except ValidationError as exp: |
107 | 108 | self._log_event( |
108 | 109 | category=EventCategory.SW_DRIVER, |
109 | 110 | description="Validation error while building NvmeDataModel", |
110 | | - data={"error": str(e)}, |
| 111 | + data={"errors": traceback.format_tb(exp.__traceback__)}, |
111 | 112 | priority=EventPriority.ERROR, |
112 | 113 | ) |
113 | 114 | self.result.message = "NVMe data invalid format" |
@@ -135,9 +136,19 @@ def collect_data( |
135 | 136 |
|
136 | 137 | def _get_nvme_devices(self) -> list[str]: |
137 | 138 | nvme_devs = [] |
138 | | - for entry in os.listdir("/dev"): |
139 | | - full_path = os.path.join("/dev", entry) |
140 | 139 |
|
141 | | - if re.fullmatch(r"nvme\d+$", entry) and os.path.exists(full_path): |
142 | | - nvme_devs.append(full_path) |
| 140 | + res = self._run_sut_cmd("ls /dev", sudo=False) |
| 141 | + if res.exit_code != 0: |
| 142 | + self._log_event( |
| 143 | + category=EventCategory.SW_DRIVER, |
| 144 | + description="Failed to list /dev directory", |
| 145 | + data={"exit_code": res.exit_code, "stderr": res.stderr}, |
| 146 | + priority=EventPriority.ERROR, |
| 147 | + ) |
| 148 | + return [] |
| 149 | + |
| 150 | + for entry in res.stdout.strip().splitlines(): |
| 151 | + if re.fullmatch(r"nvme\d+$", entry): |
| 152 | + nvme_devs.append(f"/dev/{entry}") |
| 153 | + |
143 | 154 | return nvme_devs |
0 commit comments