Commit 42b2b5ef authored by Jérome Perrin's avatar Jérome Perrin Committed by Thomas Gambier

collect: tolerate "No sensors found!" error running sensors

/reviewed-on !81
parent d4d89cce
from __future__ import print_function
from multiprocessing import Process, active_children, cpu_count, Pipe
import subprocess
try:
import subprocess32 as subprocess
except ImportError:
import subprocess
import os
import signal
import sys
......@@ -15,9 +18,18 @@ except NotImplementedError:
DEFAULT_CPU = 1
def collectComputerTemperature(sensor_bin="sensors"):
stdout = subprocess.check_output((sensor_bin, '-u'), universal_newlines=True)
sensor_output_list = stdout.splitlines()
result = subprocess.run((sensor_bin, '-u'),
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if result.returncode:
# This can happen on environments where sensors are not available,
# such as virtual machines.
if "No sensors found!" not in result.stdout:
  • This may fail depending of the localization set on the server. Can this test be based on a returncode instead ?

  • Good point. In the version we are using, there's no translation apparently (not here for 3.3.5 also not on master), so it seems OK for now.

    The rest of this function also parse the output, so it's vulnerable from the same problem.

    In the discussions on 7467ef4c (comment 71574) slapos!479 (merged) and !81 (merged) we also said that rather than parsing output like this we could use psutil (but I don't think anybody confirmed we'll do this).

Please register or sign in to reply
raise RuntimeError("Error executing {}: {}".format(sensor_bin, result.stdout))
sensor_output_list = result.stdout.splitlines()
adapter_name = ""
sensor_temperature_list = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment