]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
ftests: Throw an exception if len(stderr) > 0
authorTom Hromatka <tom.hromatka@oracle.com>
Wed, 10 Feb 2021 20:29:13 +0000 (20:29 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 1 Mar 2021 17:16:57 +0000 (10:16 -0700)
To better facilitate error handling, throw a RunError
if the stderr has been populated.

cgclassify currently prints warnings to stderr if a
setting isn't in the allow or deny list; ignore these
warnings for now.  Also, non-containerized Github
Actions runs complain about missing coverage files for
cgget; ignore those errors.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ftests/cgroup.py
ftests/run.py

index e58fcc44fc1bd82b1b58c3119f0650f40ffc5028..31fc7ee01fbfbb57cbc9747c561aef49d30e33a7 100644 (file)
@@ -24,7 +24,7 @@ from controller import Controller
 from enum import Enum
 import multiprocessing as mp
 import os
-from run import Run
+from run import Run, RunError
 import time
 import utils
 
@@ -236,7 +236,13 @@ class Cgroup(object):
         if config.args.container:
             ret = config.container.run(cmd)
         else:
-            ret = Run.run(cmd)
+            try:
+                ret = Run.run(cmd)
+            except RunError as re:
+                if "profiling" in re.stderr:
+                    ret = re.stdout
+                else:
+                    raise re
 
         return ret
 
@@ -365,14 +371,23 @@ class Cgroup(object):
 
         # ensure the deny list file exists
         if config.args.container:
-            config.container.run(['sudo', 'touch', '/etc/cgsnapshot_blacklist.conf'])
+            try:
+                config.container.run(['sudo', 'touch', '/etc/cgsnapshot_blacklist.conf'])
+            except RunError as re:
+                if re.ret == 0 and "unable to resolve host" in re.stderr:
+                    pass
         else:
             Run.run(['sudo', 'touch', '/etc/cgsnapshot_blacklist.conf'])
 
-        if config.args.container:
-            res = config.container.run(cmd)
-        else:
-            res = Run.run(cmd)
+        try:
+            if config.args.container:
+                res = config.container.run(cmd)
+            else:
+                res = Run.run(cmd)
+        except RunError as re:
+            if re.ret == 0 and \
+               "neither blacklisted nor whitelisted" in re.stderr:
+                res = re.stdout
 
         # convert the cgsnapshot stdout to a dict of cgroup objects
         return Cgroup.snapshot_to_dict(res)
index 53b4f34c257d7cc815b23f0a260e008541f4787f..ad8f07d2a6f2e3a0c48ce8e7f163b6f88e08c799 100644 (file)
@@ -53,7 +53,7 @@ class Run(object):
                 "run:\n\tcommand = {}\n\tret = {}\n\tstdout = {}\n\tstderr = {}".format(
                 ' '.join(command), ret, out, err))
 
-        if ret != 0:
+        if ret != 0 or len(err) > 0:
             raise RunError("Command '{}' failed".format(''.join(command)),
                            command, ret, out, err)