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 <jarichte@redhat.com>
  • Loading branch information
richtja committed Sep 13, 2024
1 parent 37e94de commit c11406e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 19 deletions.
15 changes: 15 additions & 0 deletions avocado_vt/plugins/vt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
49 changes: 30 additions & 19 deletions avocado_vt/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit c11406e

Please sign in to comment.