From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
Eduardo Habkost <ehabkost@redhat.com>,
qemu-block@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
Cleber Rosa <crosa@redhat.com>, John Snow <jsnow@redhat.com>
Subject: [PATCH v5 5/8] iotests: Conditionally silence certain AQMP errors
Date: Tue, 26 Oct 2021 13:56:09 -0400 [thread overview]
Message-ID: <20211026175612.4127598-6-jsnow@redhat.com> (raw)
In-Reply-To: <20211026175612.4127598-1-jsnow@redhat.com>
AQMP likes to be very chatty about errors it encounters. In general,
this is good because it allows us to get good diagnostic information for
otherwise complex async failures.
For example, during a failed QMP connection attempt, we might see:
+ERROR:qemu.aqmp.qmp_client.qemub-2536319:Negotiation failed: EOFError
+ERROR:qemu.aqmp.qmp_client.qemub-2536319:Failed to establish session: EOFError
This might be nice in iotests output, because failure scenarios
involving the new QMP library will be spelled out plainly in the output
diffs.
For tests that are intentionally causing this scenario though, filtering
that log output could be a hassle. For now, add a context manager that
simply lets us toggle this output off during a critical region.
(Additionally, a forthcoming patch allows the use of either legacy or
async QMP to be toggled with an environment variable. In this
circumstance, we can't amend the iotest output to just always expect the
error message, either. Just suppress it for now. More rigorous log
filtering can be investigated later if/when it is deemed safe to
permanently replace the legacy QMP library.)
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
---
tests/qemu-iotests/iotests.py | 20 +++++++++++++++++++-
tests/qemu-iotests/tests/mirror-top-perms | 12 ++++++++----
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index e5fff6ddcfc..e2f9d873ada 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -30,7 +30,7 @@
import subprocess
import sys
import time
-from typing import (Any, Callable, Dict, Iterable,
+from typing import (Any, Callable, Dict, Iterable, Iterator,
List, Optional, Sequence, TextIO, Tuple, Type, TypeVar)
import unittest
@@ -114,6 +114,24 @@
sample_img_dir = os.environ['SAMPLE_IMG_DIR']
+@contextmanager
+def change_log_level(
+ logger_name: str, level: int = logging.CRITICAL) -> Iterator[None]:
+ """
+ Utility function for temporarily changing the log level of a logger.
+
+ This can be used to silence errors that are expected or uninteresting.
+ """
+ _logger = logging.getLogger(logger_name)
+ current_level = _logger.level
+ _logger.setLevel(level)
+
+ try:
+ yield
+ finally:
+ _logger.setLevel(current_level)
+
+
def unarchive_sample_image(sample, fname):
sample_fname = os.path.join(sample_img_dir, sample + '.bz2')
with bz2.open(sample_fname) as f_in, open(fname, 'wb') as f_out:
diff --git a/tests/qemu-iotests/tests/mirror-top-perms b/tests/qemu-iotests/tests/mirror-top-perms
index a2d5c269d7a..0a51a613f39 100755
--- a/tests/qemu-iotests/tests/mirror-top-perms
+++ b/tests/qemu-iotests/tests/mirror-top-perms
@@ -26,7 +26,7 @@ from qemu.machine import machine
from qemu.qmp import QMPConnectError
import iotests
-from iotests import qemu_img
+from iotests import change_log_level, qemu_img
image_size = 1 * 1024 * 1024
@@ -100,9 +100,13 @@ class TestMirrorTopPerms(iotests.QMPTestCase):
self.vm_b.add_blockdev(f'file,node-name=drive0,filename={source}')
self.vm_b.add_device('virtio-blk,drive=drive0,share-rw=on')
try:
- self.vm_b.launch()
- print('ERROR: VM B launched successfully, this should not have '
- 'happened')
+ # Silence AQMP errors temporarily.
+ # TODO: Remove this and just allow the errors to be logged when
+ # AQMP fully replaces QMP.
+ with change_log_level('qemu.aqmp'):
+ self.vm_b.launch()
+ print('ERROR: VM B launched successfully, '
+ 'this should not have happened')
except (QMPConnectError, ConnectError):
assert 'Is another process using the image' in self.vm_b.get_log()
--
2.31.1
next prev parent reply other threads:[~2021-10-26 18:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 17:56 [PATCH v5 0/8] Switch iotests to using Async QMP John Snow
2021-10-26 17:56 ` [PATCH v5 1/8] python/machine: remove has_quit argument John Snow
2021-10-26 17:56 ` [PATCH v5 2/8] python/machine: Handle QMP errors on close more meticulously John Snow
2021-10-27 11:19 ` Kevin Wolf
2021-10-27 17:49 ` John Snow
2021-10-28 10:01 ` Kevin Wolf
2021-10-28 15:35 ` John Snow
2021-10-26 17:56 ` [PATCH v5 3/8] python/aqmp: Remove scary message John Snow
2021-10-26 17:56 ` [PATCH v5 4/8] iotests: Accommodate async QMP Exception classes John Snow
2021-10-26 17:56 ` John Snow [this message]
2021-10-26 17:56 ` [PATCH v5 6/8] iotests/300: avoid abnormal shutdown race condition John Snow
2021-10-27 12:56 ` Kevin Wolf
2021-10-27 17:55 ` John Snow
2021-10-26 17:56 ` [PATCH v5 7/8] python/aqmp: Create sync QMP wrapper for iotests John Snow
2021-10-26 17:56 ` [PATCH v5 8/8] python, iotests: replace qmp with aqmp John Snow
2021-10-28 10:37 ` [PATCH v5 0/8] Switch iotests to using Async QMP Kevin Wolf
2021-10-28 14:48 ` John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211026175612.4127598-6-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).