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