Skip to content

Commit 0512105

Browse files
authored
Make nvme_metrics.py work with missing paths
Signed-off-by: Orsiris de Jong <ozy@netpower.fr>
1 parent 4242258 commit 0512105

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

nvme_metrics.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,15 @@ def exec_nvme(*args):
137137
in child process environment so that the nvme tool does not perform any locale-specific number
138138
or date formatting, etc.
139139
"""
140-
cmd = ["nvme", *args]
140+
nvme_command = None
141+
for sys_path in ['/usr/sbin', '/usr/bin', '/usr/local/sbin', '/usr/local/bin']:
142+
nvme_command = os.path.join(sys_path, 'nvme')
143+
if os.path.isfile(nvme_command):
144+
break
145+
nvme_command = None
146+
if not nvme_command:
147+
raise FileNotFoundError("Did not find command path for {}".format(nvme_command))
148+
cmd = [nvme_command, *args]
141149
return subprocess.check_output(cmd, stderr=subprocess.PIPE, env=dict(os.environ, LC_ALL="C"))
142150

143151

0 commit comments

Comments
 (0)