This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit a59f1db48bedd3b72a58e4d5193eb17c413aa4d0
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Sun Feb 25 23:02:00 2018 +0200
Show stderr when sanlock command fail
When util.sanlock() fail, we show now also the command stderr, allowing
assertions about sanlock behavior, and easier debugging.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
tests/daemon_test.py | 3 +--
tests/util.py | 22 ++++++++++++++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/tests/daemon_test.py b/tests/daemon_test.py
index 9697658..84afacb 100644
--- a/tests/daemon_test.py
+++ b/tests/daemon_test.py
@@ -5,7 +5,6 @@ Test sanlock client operations.
import io
import signal
import struct
-import subprocess
import pytest
@@ -38,7 +37,7 @@ def test_start_after_kill():
def test_client_failure():
# No daemon is running, client must fail
- with pytest.raises(subprocess.CalledProcessError) as e:
+ with pytest.raises(util.CommandError) as e:
util.sanlock("client", "status")
assert e.value.returncode == 1
diff --git a/tests/util.py b/tests/util.py
index 157624a..9bd35fb 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -16,6 +16,20 @@ class TimeoutExpired(Exception):
""" Raised when timeout expired """
+class CommandError(Exception):
+ msg = ("Command {self.cmd} failed with returncode={self.returncode}, "
+ "stdout={self.stdout!r}, stderr={self.stderr!r}")
+
+ def __init__(self, cmd, returncode, stdout, stderr):
+ self.cmd = cmd
+ self.returncode = returncode
+ self.stdout = stdout
+ self.stderr = stderr
+
+ def __str__(self):
+ return self.msg.format(self=self)
+
+
def start_daemon():
cmd = [SANLOCK, "daemon",
# no fork and print all logging to stderr
@@ -57,11 +71,15 @@ def wait_for_daemon(timeout):
def sanlock(*args):
"""
Run sanlock returning the process stdout, or raising
- subprocess.CalledProcessError on failures.
+ util.CommandError on failures.
"""
cmd = [SANLOCK]
cmd.extend(args)
- return subprocess.check_output(cmd)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ if p.returncode:
+ raise CommandError(cmd, p.returncode, out, err)
+ return out
def wait_for_termination(p, timeout):
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.