From 10efa9dfbff42ee9b499b8f6d7ae9e62883fa210 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 10 Feb 2021 20:29:13 +0000 Subject: [PATCH] ftests: Throw an exception if len(stderr) > 0 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 --- ftests/cgroup.py | 29 ++++++++++++++++++++++------- ftests/run.py | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ftests/cgroup.py b/ftests/cgroup.py index e58fcc44..31fc7ee0 100644 --- a/ftests/cgroup.py +++ b/ftests/cgroup.py @@ -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) diff --git a/ftests/run.py b/ftests/run.py index 53b4f34c..ad8f07d2 100644 --- a/ftests/run.py +++ b/ftests/run.py @@ -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) -- 2.47.2