From 6e40e56ea2ce9cf69c64071e309eb37db8885b79 Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Fri, 13 Sep 2024 10:56:51 +0200 Subject: [PATCH] omit_data_loss config variable In tp_libvrt testing, We've seen many occurrences where "Bad file descriptor" OSError was raised during clean up phase when an external command is executed via `avocado.utils.process` utility. It happens when `SubProcess` class wants to flush the stdout and stderr of the external command after finishes. These kinds of errors might lead to stdout and stderr data loss, but during the tp_libvrt testing it leads to false positive failures, which makes test evaluation harder. This commit introduces a new config variable `omit_data_loss` which, when is enabled, will omit these errors, and they won't affect the overall test result. Reference: https://github.com/avocado-framework/avocado/pull/6019 Signed-off-by: Jan Richter --- avocado_vt/plugins/vt.py | 14 ++++++++ avocado_vt/plugins/vt_init.py | 13 +++++++ avocado_vt/test.py | 64 ++++++++++++++++++++--------------- 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/avocado_vt/plugins/vt.py b/avocado_vt/plugins/vt.py index 922e25d33d..d0b1c66350 100644 --- a/avocado_vt/plugins/vt.py +++ b/avocado_vt/plugins/vt.py @@ -250,6 +250,20 @@ def configure(self, parser): help=help_msg, ) + help_msg = ( + "Omits the `OSError [Errno 9] Bad file descriptor` caused by " + "avocado.utils.process utility during clean up. This can be used " + "when this error would cause false positive failures of a test." + ) + add_option( + vt_compat_group_common, + dest="vt.omit_data_loss", + arg="--vt-omit-data-loss", + action="store_true", + default=False, + help=help_msg, + ) + def run(self, config): """ Run test modules or simple tests. diff --git a/avocado_vt/plugins/vt_init.py b/avocado_vt/plugins/vt_init.py index 4c13d81b88..61c78bf891 100644 --- a/avocado_vt/plugins/vt_init.py +++ b/avocado_vt/plugins/vt_init.py @@ -125,6 +125,19 @@ def initialize(self): help_msg=help_msg, ) + help_msg = ( + "Omits the `OSError [Errno 9] Bad file descriptor` caused by " + "avocado.utils.process utility during clean up. This can be used " + "when this error would cause false positive failures of a test." + ) + settings.register_option( + section, + key="omit_data_loss", + key_type=bool, + default=False, + help_msg=help_msg, + ) + # [vt.setup] section section = "vt.setup" diff --git a/avocado_vt/test.py b/avocado_vt/test.py index 71161f8f60..89168a13a6 100644 --- a/avocado_vt/test.py +++ b/avocado_vt/test.py @@ -169,28 +169,34 @@ def setUp(self): os.remove(libvirtd_log) else: # tar the libvirtd log and archive - self.log.info("archiving libvirtd debug logs") - from virttest import utils_package - - if utils_package.package_install("tar"): - if os.path.isfile(libvirtd_log): - archive = os.path.join( - os.path.dirname(libvirtd_log), "libvirtd.tar.gz" - ) - cmd = "tar -zcf %s -P %s" % ( - shlex.quote(archive), - shlex.quote(libvirtd_log), - ) - if process.system(cmd) == 0: - os.remove(libvirtd_log) + try: + self.log.info("archiving libvirtd debug logs") + from virttest import utils_package + + if utils_package.package_install("tar"): + if os.path.isfile(libvirtd_log): + archive = os.path.join( + os.path.dirname(libvirtd_log), "libvirtd.tar.gz" + ) + cmd = "tar -zcf %s -P %s" % ( + shlex.quote(archive), + shlex.quote(libvirtd_log), + ) + if process.system(cmd) == 0: + os.remove(libvirtd_log) + else: + self.log.error( + "Unable to find log file: %s", libvirtd_log + ) else: self.log.error( - "Unable to find log file: %s", libvirtd_log + "Unable to find tar to compress libvirtd " "logs" ) - else: - self.log.error( - "Unable to find tar to compress libvirtd " "logs" - ) + except OSError as e: + if not self._config.get("vt.omit_data_loss"): + raise e + elif e.errno != 9: + raise e if env_lang: os.environ["LANG"] = env_lang @@ -307,14 +313,18 @@ def _runTest(self): params["test_passed"] = str(test_passed) env_process.postprocess(self, params, env) except: # nopep8 Old-style exceptions are not inherited from Exception() - - stacktrace.log_exc_info(sys.exc_info(), "avocado.test") - if test_passed: - raise - self.log.error( - "Exception raised during " "postprocessing: %s", - sys.exc_info()[1], - ) + if not ( + self._config.get("vt.omit_data_loss") + and "[Errno 9] Bad file descriptor" + in str(sys.exc_info()[1]) + ): + stacktrace.log_exc_info(sys.exc_info(), "avocado.test") + if test_passed: + raise + self.log.error( + "Exception raised during " "postprocessing: %s", + sys.exc_info()[1], + ) finally: if ( self._safe_env_save(env)