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