]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/ceph_test_case.py
270c18553edbbfdf9e30139bbb9d0ccc454704d5
6 from teuthology
.orchestra
.run
import CommandFailedError
8 log
= logging
.getLogger(__name__
)
11 class CephTestCase(unittest
.TestCase
):
13 For test tasks that want to define a structured set of
14 tests implemented in python. Subclass this with appropriate
15 helpers for the subsystem you're testing.
18 # Environment references
29 self
.ceph_cluster
.mon_manager
.raw_cluster_cmd("log",
30 "Starting test {0}".format(self
.id()))
33 self
.ceph_cluster
.mon_manager
.raw_cluster_cmd("log",
34 "Ended test {0}".format(self
.id()))
36 def assert_cluster_log(self
, expected_pattern
, invert_match
=False, timeout
=10):
38 Context manager. Assert that during execution, or up to 5 seconds later,
39 the Ceph cluster log emits a message matching the expected pattern.
41 :param expected_pattern: a string that you expect to see in the log output
44 ceph_manager
= self
.ceph_cluster
.mon_manager
46 class ContextManager(object):
48 found
= expected_pattern
in self
.watcher_process
.stdout
.getvalue()
55 self
.watcher_process
= ceph_manager
.run_ceph_w()
57 def __exit__(self
, exc_type
, exc_val
, exc_tb
):
58 if not self
.watcher_process
.finished
:
59 # Check if we got an early match, wait a bit if we didn't
63 log
.debug("No log hits yet, waiting...")
64 # Default monc tick interval is 10s, so wait that long and
66 time
.sleep(5 + timeout
)
68 self
.watcher_process
.stdin
.close()
70 self
.watcher_process
.wait()
71 except CommandFailedError
:
75 log
.error("Log output: \n{0}\n".format(self
.watcher_process
.stdout
.getvalue()))
76 raise AssertionError("Expected log message not found: '{0}'".format(expected_pattern
))
78 return ContextManager()
80 def wait_for_health(self
, pattern
, timeout
):
82 Wait until 'ceph health' contains messages matching the pattern
84 def seen_health_warning():
85 health
= self
.ceph_cluster
.mon_manager
.get_mon_health()
86 summary_strings
= [s
['summary'] for s
in health
['summary']]
87 if len(summary_strings
) == 0:
88 log
.debug("Not expected number of summary strings ({0})".format(summary_strings
))
91 for ss
in summary_strings
:
95 log
.debug("Not found expected summary strings yet ({0})".format(summary_strings
))
98 self
.wait_until_true(seen_health_warning
, timeout
)
100 def wait_for_health_clear(self
, timeout
):
102 Wait until `ceph health` returns no messages
105 health
= self
.ceph_cluster
.mon_manager
.get_mon_health()
106 return len(health
['summary']) == 0
108 self
.wait_until_true(is_clear
, timeout
)
110 def wait_until_equal(self
, get_fn
, expect_val
, timeout
, reject_fn
=None):
115 if val
== expect_val
:
117 elif reject_fn
and reject_fn(val
):
118 raise RuntimeError("wait_until_equal: forbidden value {0} seen".format(val
))
120 if elapsed
>= timeout
:
121 raise RuntimeError("Timed out after {0} seconds waiting for {1} (currently {2})".format(
122 elapsed
, expect_val
, val
125 log
.debug("wait_until_equal: {0} != {1}, waiting...".format(val
, expect_val
))
129 log
.debug("wait_until_equal: success")
131 def wait_until_true(self
, condition
, timeout
):
136 log
.debug("wait_until_true: success in {0}s".format(elapsed
))
139 if elapsed
>= timeout
:
140 raise RuntimeError("Timed out after {0}s".format(elapsed
))
142 log
.debug("wait_until_true: waiting...")