]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/ceph_test_case.py
47f3921347dbd980ed0050d7576af5e917e1a23b
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 codes
= [s
for s
in health
['checks']]
87 summary_strings
= [s
[1]['message'] for s
in health
['checks'].iteritems()]
88 if len(summary_strings
) == 0:
89 log
.debug("Not expected number of summary strings ({0})".format(summary_strings
))
92 for ss
in summary_strings
:
98 log
.debug("Not found expected summary strings yet ({0})".format(summary_strings
))
101 self
.wait_until_true(seen_health_warning
, timeout
)
103 def wait_for_health_clear(self
, timeout
):
105 Wait until `ceph health` returns no messages
108 health
= self
.ceph_cluster
.mon_manager
.get_mon_health()
109 return len(health
['checks']) == 0
111 self
.wait_until_true(is_clear
, timeout
)
113 def wait_until_equal(self
, get_fn
, expect_val
, timeout
, reject_fn
=None):
118 if val
== expect_val
:
120 elif reject_fn
and reject_fn(val
):
121 raise RuntimeError("wait_until_equal: forbidden value {0} seen".format(val
))
123 if elapsed
>= timeout
:
124 raise RuntimeError("Timed out after {0} seconds waiting for {1} (currently {2})".format(
125 elapsed
, expect_val
, val
128 log
.debug("wait_until_equal: {0} != {1}, waiting...".format(val
, expect_val
))
132 log
.debug("wait_until_equal: success")
134 def wait_until_true(self
, condition
, timeout
):
139 log
.debug("wait_until_true: success in {0}s".format(elapsed
))
142 if elapsed
>= timeout
:
143 raise RuntimeError("Timed out after {0}s".format(elapsed
))
145 log
.debug("wait_until_true: waiting...")