]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | """ |
2 | Handle clock skews in monitors. | |
3 | """ | |
4 | import logging | |
7c673cae FG |
5 | import ceph_manager |
6 | import time | |
7c673cae FG |
7 | from teuthology import misc as teuthology |
8 | ||
9 | log = logging.getLogger(__name__) | |
10 | ||
11 | class ClockSkewCheck: | |
12 | """ | |
224ce89b WB |
13 | Check if there are any clock skews among the monitors in the |
14 | quorum. | |
7c673cae FG |
15 | |
16 | This task accepts the following options: | |
17 | ||
224ce89b | 18 | interval amount of seconds to wait before check. (default: 30.0) |
7c673cae FG |
19 | expect-skew 'true' or 'false', to indicate whether to expect a skew during |
20 | the run or not. If 'true', the test will fail if no skew is | |
21 | found, and succeed if a skew is indeed found; if 'false', it's | |
22 | the other way around. (default: false) | |
7c673cae FG |
23 | |
24 | - mon_clock_skew_check: | |
224ce89b | 25 | expect-skew: true |
7c673cae FG |
26 | """ |
27 | ||
28 | def __init__(self, ctx, manager, config, logger): | |
29 | self.ctx = ctx | |
30 | self.manager = manager | |
31 | ||
32 | self.stopping = False | |
33 | self.logger = logger | |
34 | self.config = config | |
35 | ||
36 | if self.config is None: | |
37 | self.config = dict() | |
38 | ||
7c673cae | 39 | |
7c673cae | 40 | def task(ctx, config): |
7c673cae FG |
41 | if config is None: |
42 | config = {} | |
43 | assert isinstance(config, dict), \ | |
44 | 'mon_clock_skew_check task only accepts a dict for configuration' | |
224ce89b WB |
45 | interval = float(config.get('interval', 30.0)) |
46 | expect_skew = config.get('expect-skew', False) | |
47 | ||
7c673cae FG |
48 | log.info('Beginning mon_clock_skew_check...') |
49 | first_mon = teuthology.get_first_mon(ctx, config) | |
9f95a23c | 50 | (mon,) = ctx.cluster.only(first_mon).remotes.keys() |
7c673cae FG |
51 | manager = ceph_manager.CephManager( |
52 | mon, | |
53 | ctx=ctx, | |
54 | logger=log.getChild('ceph_manager'), | |
55 | ) | |
56 | ||
224ce89b WB |
57 | quorum_size = len(teuthology.get_mon_names(ctx)) |
58 | manager.wait_for_mon_quorum_size(quorum_size) | |
59 | ||
60 | # wait a bit | |
61 | log.info('sleeping for {s} seconds'.format( | |
62 | s=interval)) | |
63 | time.sleep(interval) | |
64 | ||
65 | health = manager.get_mon_health(True) | |
66 | log.info('got health %s' % health) | |
67 | if expect_skew: | |
68 | if 'MON_CLOCK_SKEW' not in health['checks']: | |
69 | raise RuntimeError('expected MON_CLOCK_SKEW but got none') | |
70 | else: | |
71 | if 'MON_CLOCK_SKEW' in health['checks']: | |
72 | raise RuntimeError('got MON_CLOCK_SKEW but expected none') | |
7c673cae | 73 |