summaryrefslogtreecommitdiffstats
path: root/qa
diff options
context:
space:
mode:
authorPatrick Donnelly <pdonnell@redhat.com>2023-04-05 04:12:18 +0200
committerPatrick Donnelly <pdonnell@redhat.com>2023-05-01 17:21:26 +0200
commitc82d2a41f12f2e769e24aff091fdc03d2fa42de7 (patch)
tree2ad884647a353718c8e9c0fc856461f76940b04b /qa
parentMerge pull request #51284 from zdover23/wip-doc-2023-04-29-cephfs-nfs (diff)
downloadceph-c82d2a41f12f2e769e24aff091fdc03d2fa42de7.tar.xz
ceph-c82d2a41f12f2e769e24aff091fdc03d2fa42de7.zip
qa: support checking for a log message that should not exist
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
Diffstat (limited to 'qa')
-rw-r--r--qa/tasks/ceph_test_case.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/qa/tasks/ceph_test_case.py b/qa/tasks/ceph_test_case.py
index 4070390fb5d..3f355825c6f 100644
--- a/qa/tasks/ceph_test_case.py
+++ b/qa/tasks/ceph_test_case.py
@@ -92,7 +92,7 @@ class CephTestCase(unittest.TestCase):
def assert_cluster_log(self, expected_pattern, invert_match=False,
- timeout=10, watch_channel=None):
+ timeout=10, watch_channel=None, present=True):
"""
Context manager. Assert that during execution, or up to 5 seconds later,
the Ceph cluster log emits a message matching the expected pattern.
@@ -102,6 +102,8 @@ class CephTestCase(unittest.TestCase):
:param watch_channel: Specifies the channel to be watched. This can be
'cluster', 'audit', ...
:type watch_channel: str
+ :param present: Assert the log entry is present (default: True) or not (False).
+ :type present: bool
"""
ceph_manager = self.ceph_cluster.mon_manager
@@ -118,10 +120,13 @@ class CephTestCase(unittest.TestCase):
self.watcher_process = ceph_manager.run_ceph_w(watch_channel)
def __exit__(self, exc_type, exc_val, exc_tb):
+ fail = False
if not self.watcher_process.finished:
# Check if we got an early match, wait a bit if we didn't
- if self.match():
+ if present and self.match():
return
+ elif not present and self.match():
+ fail = True
else:
log.debug("No log hits yet, waiting...")
# Default monc tick interval is 10s, so wait that long and
@@ -134,9 +139,12 @@ class CephTestCase(unittest.TestCase):
except CommandFailedError:
pass
- if not self.match():
- log.error("Log output: \n{0}\n".format(self.watcher_process.stdout.getvalue()))
- raise AssertionError("Expected log message not found: '{0}'".format(expected_pattern))
+ if present and not self.match():
+ log.error(f"Log output: \n{self.watcher_process.stdout.getvalue()}\n")
+ raise AssertionError(f"Expected log message found: '{expected_pattern}'")
+ elif fail or (not present and self.match()):
+ log.error(f"Log output: \n{self.watcher_process.stdout.getvalue()}\n")
+ raise AssertionError(f"Unexpected log message found: '{expected_pattern}'")
return ContextManager()