From c11406e90ae39c0fce45d04a85f4d7af95b7f7fc 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 | 15 +++++++++++ avocado_vt/plugins/vt_init.py | 13 ++++++++++ avocado_vt/test.py | 49 +++++++++++++++++++++-------------- 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/avocado_vt/plugins/vt.py b/avocado_vt/plugins/vt.py index 922e25d33d..9eb1b631ef 100644 --- a/avocado_vt/plugins/vt.py +++ b/avocado_vt/plugins/vt.py @@ -250,6 +250,21 @@ 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..cb4a2ece53 100644 --- a/avocado_vt/test.py +++ b/avocado_vt/test.py @@ -150,6 +150,11 @@ def setUp(self): except exceptions.TestSkipError: self.__exc_info = sys.exc_info() raise # This one has to be raised in setUp + except OSError as e: + if not self._config.get("vt.omit_data_loss"): + raise e + elif e.errno != 9: + raise e except: # nopep8 Old-style exceptions are not inherited from Exception() self.__exc_info = sys.exc_info() self.__status = self.__exc_info[1] @@ -169,28 +174,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