|
29 | 29 | import abc |
30 | 30 | import collections |
31 | 31 | import copy |
32 | | -import json |
| 32 | +import io |
33 | 33 | import logging |
34 | 34 | import os |
35 | 35 | import posixpath |
|
41 | 41 | import uuid |
42 | 42 |
|
43 | 43 | from absl import flags |
44 | | -from packaging import version as packaging_version |
| 44 | +import pandas as pd |
45 | 45 | from perfkitbenchmarker import background_tasks |
46 | 46 | from perfkitbenchmarker import disk |
47 | 47 | from perfkitbenchmarker import errors |
@@ -2220,41 +2220,27 @@ def GetNVMEDeviceInfo(self): |
2220 | 2220 | """Get the NVME disk device info, by querying the VM.""" |
2221 | 2221 | self.InstallPackages('nvme-cli') |
2222 | 2222 | version_str, _ = self.RemoteCommand('sudo nvme --version') |
2223 | | - version_num = version_str.split()[2] |
2224 | | - # TODO(arushigaur): Version check can be removed and we can just parse |
2225 | | - # the raw output. |
2226 | | - if packaging_version.parse(version_num) >= packaging_version.parse( |
2227 | | - '1.5' |
2228 | | - ) and packaging_version.parse(version_num) < packaging_version.parse( |
2229 | | - '2.11' |
2230 | | - ): |
2231 | | - stdout, _ = self.RemoteCommand('sudo nvme list --output-format json') |
2232 | | - if not stdout: |
2233 | | - return [] |
2234 | | - response = json.loads(stdout) |
2235 | | - return response.get('Devices', []) |
2236 | | - else: |
2237 | | - # custom parsing for older OSes that do not ship nvme-cli ver 1.5+. |
2238 | | - response = [] |
2239 | | - stdout, _ = self.RemoteCommand('sudo nvme list') |
2240 | | - if 'No NVMe devices detected' in stdout: |
2241 | | - return [] |
2242 | | - rows = stdout.splitlines() |
2243 | | - delimiter_row = rows[1] # row 0 is the column headers |
2244 | | - delimiter_index = [0] + [ |
2245 | | - i for i in range(len(delimiter_row)) if delimiter_row[i] == ' ' |
2246 | | - ] |
2247 | | - for row in rows[2:]: |
2248 | | - device = {} |
2249 | | - device_info = [ |
2250 | | - row[i:j] |
2251 | | - for i, j in zip(delimiter_index, delimiter_index[1:] + [None]) |
2252 | | - ] |
2253 | | - device['DevicePath'] = device_info[0].strip() |
2254 | | - device['SerialNumber'] = device_info[1].strip() |
2255 | | - device['ModelNumber'] = device_info[2].strip() |
2256 | | - response.append(device) |
2257 | | - return response |
| 2223 | + logging.info('nvme-cli version: %s', version_str.split()[2]) |
| 2224 | + response = [] |
| 2225 | + stdout, _ = self.RemoteCommand('sudo nvme list') |
| 2226 | + if 'No NVMe devices detected' in stdout: |
| 2227 | + return [] |
| 2228 | + rows = stdout.splitlines() |
| 2229 | + header_row = rows[0] |
| 2230 | + delimiter_row = rows[1] |
| 2231 | + col_spans = [ |
| 2232 | + (m.start(), m.end()) for m in re.finditer(r'-+', delimiter_row) |
| 2233 | + ] |
| 2234 | + data = '\n'.join([header_row] + rows[2:]) |
| 2235 | + df_colspecs = pd.read_fwf(io.StringIO(data), colspecs=col_spans) |
| 2236 | + df_rows = df_colspecs.to_dict(orient='records') |
| 2237 | + for row in df_rows: |
| 2238 | + response.append({ |
| 2239 | + 'DevicePath': row.get('Node'), |
| 2240 | + 'SerialNumber': row.get('SN'), |
| 2241 | + 'ModelNumber': row.get('Model'), |
| 2242 | + }) |
| 2243 | + return response |
2258 | 2244 |
|
2259 | 2245 | def GenerateAndCaptureLogs(self) -> list[str]: |
2260 | 2246 | """Generates and/or captures logs for this VM and returns the paths. |
|
0 commit comments