LGTM, thanks On Wed, Jul 30, 2014 at 6:36 PM, Yuto KAWAMURA(kawamuray) < [email protected]> wrote:
> When using the timeout option of RunCmd, in some cases that we want to > know if a command failed by timing out or due to other issues. > This commit extends RunResult to hold an additional variable > "failed_by_timeout" which is set to True if a command was killed by > the timeout. > > Signed-off-by: Yuto KAWAMURA(kawamuray) <[email protected]> > --- > lib/utils/process.py | 6 +++++- > test/py/ganeti.utils.process_unittest.py | 10 ++++++++++ > 2 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/lib/utils/process.py b/lib/utils/process.py > index 2521c58..8a9785e 100644 > --- a/lib/utils/process.py > +++ b/lib/utils/process.py > @@ -78,11 +78,14 @@ class RunResult(object): > @type failed: boolean > @ivar failed: True in case the program was > terminated by a signal or exited with a non-zero exit code > + @type failed_by_timeout: boolean > + @ivar failed_by_timeout: True in case the program was > + terminated by timeout > @ivar fail_reason: a string detailing the termination reason > > """ > __slots__ = ["exit_code", "signal", "stdout", "stderr", > - "failed", "fail_reason", "cmd"] > + "failed", "failed_by_timeout", "fail_reason", "cmd"] > > def __init__(self, exit_code, signal_, stdout, stderr, cmd, > timeout_action, > timeout): > @@ -92,6 +95,7 @@ class RunResult(object): > self.stdout = stdout > self.stderr = stderr > self.failed = (signal_ is not None or exit_code != 0) > + self.failed_by_timeout = timeout_action != _TIMEOUT_NONE > > fail_msgs = [] > if self.signal is not None: > diff --git a/test/py/ganeti.utils.process_unittest.py b/test/py/ > ganeti.utils.process_unittest.py > index 2e36cfa..3cdad20 100755 > --- a/test/py/ganeti.utils.process_unittest.py > +++ b/test/py/ganeti.utils.process_unittest.py > @@ -259,6 +259,16 @@ class TestRunCmd(testutils.GanetiTestCase): > self.assertEqual(result.signal, 15) > self.assertEqual(result.output, "") > > + def testTimeoutFlagTrue(self): > + result = utils.RunCmd(["sleep", "2"], timeout=0.1) > + self.assertTrue(result.failed) > + self.assertTrue(result.failed_by_timeout) > + > + def testTimeoutFlagFalse(self): > + result = utils.RunCmd(["false"], timeout=5) > + self.assertTrue(result.failed) > + self.assertFalse(result.failed_by_timeout) > + > def testTimeoutClean(self): > cmd = ("trap 'exit 0' TERM; echo >&%d; read < %s" % > (self.proc_ready_helper.write_fd, self.fifo_file)) > -- > 1.8.5.5 > > Hrvoje Ribicic Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370
