Skip to content

Commit

Permalink
omit_data_loss config variable
Browse files Browse the repository at this point in the history
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: avocado-framework/avocado#6019
Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
richtja committed Oct 17, 2024
1 parent 37e94de commit 6e40e56
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 27 deletions.
14 changes: 14 additions & 0 deletions avocado_vt/plugins/vt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions avocado_vt/plugins/vt_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
64 changes: 37 additions & 27 deletions avocado_vt/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6e40e56

Please sign in to comment.