Exemplo n.º 1
0
 def report(self, reason: str, message: str) -> None:
     logger.info("[REPORT] Reason: %s. Message: %s", reason, message)
     try:
         rc = self._report_command
         rc = rc.replace("%REASON%", reason)
         rc = rc.replace("%MESSAGE%", message)
         exec_shell_command(rc)
     except Exception as ex:
         logger.warning("Report failed: %s", ex, exc_info=True)
Exemplo n.º 2
0
 def _alert_cmd(self, shell_cmd):
     if not shell_cmd:
         return
     try:
         exec_shell_command(shell_cmd)
     except Exception as e:
         logger.warning(
             "Enable to execute %s trigger command %s:\n%s",
             self.trigger_name,
             shell_cmd,
             e,
         )
Exemplo n.º 3
0
    def _get_temp(self) -> Tuple[TempCelsius, TempCelsius, TempCelsius]:
        temps = [
            float(line.strip())
            for line in exec_shell_command(self._shell_command).split("\n")
            if line.strip()
        ]
        temp = TempCelsius(temps[0])

        if self._min is not None:
            min_t = self._min
        else:
            min_t = TempCelsius(temps[1])

        if self._max is not None:
            max_t = self._max
        else:
            max_t = TempCelsius(temps[2])

        return temp, min_t, max_t
Exemplo n.º 4
0
 def _call_hddtemp(self) -> str:
     # `disk_path` might be a glob, so it has to be executed with a shell.
     shell_command = "%s -n -u C -- %s" % (self._hddtemp_bin,
                                           self._disk_path)
     return exec_shell_command(shell_command, timeout=10)
Exemplo n.º 5
0
def test_exec_shell_command_successful():
    assert "42\n" == exec_shell_command("echo 42")
Exemplo n.º 6
0
def test_exec_shell_command_expands_glob(temp_path):
    (temp_path / "sda").write_text("")
    (temp_path / "sdb").write_text("")

    expected = "{0}/sda {0}/sdb\n".format(temp_path)
    assert expected == exec_shell_command('echo "%s/sd"?' % temp_path)
Exemplo n.º 7
0
def test_exec_shell_command_raises_for_unicode():
    with pytest.raises(ValueError):
        exec_shell_command("echo привет")
Exemplo n.º 8
0
def test_exec_shell_command_erroneous():
    with pytest.raises(subprocess.SubprocessError):
        exec_shell_command("echo 42 && false")
Exemplo n.º 9
0
def test_exec_shell_command_ignores_stderr():
    assert "42\n" == exec_shell_command("echo 111 >&2; echo 42")
Exemplo n.º 10
0
 def sensed_exec_shell_command(*args, **kwargs):
     exec_shell_command_stdout.append(exec_shell_command(*args, **kwargs))
     return exec_shell_command_stdout[-1]
Exemplo n.º 11
0
 def _call_ipmi_sensors(self) -> str:
     shell_command = "%s %s --sensor-types Fan --comma-separated-output" % (
         self._ipmi_sensors_bin,
         self._ipmi_sensors_extra_args,
     )
     return exec_shell_command(shell_command, timeout=2)