]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: show stdout and stderr on failure in check_output()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Aug 2022 21:40:46 +0000 (06:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Aug 2022 10:37:49 +0000 (19:37 +0900)
test/test-network/systemd-networkd-tests.py

index cb014d67f3f46d5c5f6d6a159155ae424286a5c1..60ed22291c4bc26fad9e06d8a71462ad1bc0fe87 100755 (executable)
@@ -98,7 +98,12 @@ def touch(path):
 def check_output(*command, **kwargs):
     # This checks the result and returns stdout (and stderr) on success.
     command = command[0].split() + list(command[1:])
-    return subprocess.run(command, check=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs).stdout.rstrip()
+    ret = subprocess.run(command, check=False, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kwargs)
+    if ret.returncode == 0:
+        return ret.stdout.rstrip()
+    # When returncode != 0, print stdout and stderr, then trigger CalledProcessError.
+    print(ret.stdout)
+    ret.check_returncode()
 
 def call(*command, **kwargs):
     # This returns returncode. stdout and stderr are merged and shown in console
@@ -871,7 +876,7 @@ class Utilities():
         try:
             check_output(*args, env=wait_online_env)
         except subprocess.CalledProcessError as e:
-            print(e.stdout) # show logs only on failure
+            # show detailed status on failure
             for link in links_with_operstate:
                 name = link.split(':')[0]
                 if link_exists(name):