2014-02-14 02:18:56 +00:00
|
|
|
"""
|
|
|
|
Handle clock skews in monitors.
|
|
|
|
"""
|
2013-01-04 18:16:58 +00:00
|
|
|
import logging
|
|
|
|
import contextlib
|
|
|
|
import ceph_manager
|
|
|
|
import time
|
|
|
|
import gevent
|
2013-07-22 16:58:41 +00:00
|
|
|
from StringIO import StringIO
|
2013-01-04 18:16:58 +00:00
|
|
|
from teuthology import misc as teuthology
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
class ClockSkewCheck:
|
2014-02-14 02:18:56 +00:00
|
|
|
"""
|
2017-06-27 18:57:53 +00:00
|
|
|
Check if there are any clock skews among the monitors in the
|
|
|
|
quorum.
|
2014-02-14 02:18:56 +00:00
|
|
|
|
|
|
|
This task accepts the following options:
|
|
|
|
|
2017-06-27 18:57:53 +00:00
|
|
|
interval amount of seconds to wait before check. (default: 30.0)
|
2014-02-14 02:18:56 +00:00
|
|
|
expect-skew 'true' or 'false', to indicate whether to expect a skew during
|
|
|
|
the run or not. If 'true', the test will fail if no skew is
|
|
|
|
found, and succeed if a skew is indeed found; if 'false', it's
|
|
|
|
the other way around. (default: false)
|
2013-01-04 18:16:58 +00:00
|
|
|
|
|
|
|
- mon_clock_skew_check:
|
2017-06-27 18:57:53 +00:00
|
|
|
expect-skew: true
|
2014-02-14 02:18:56 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, ctx, manager, config, logger):
|
|
|
|
self.ctx = ctx
|
|
|
|
self.manager = manager
|
|
|
|
|
|
|
|
self.stopping = False
|
|
|
|
self.logger = logger
|
|
|
|
self.config = config
|
|
|
|
|
|
|
|
if self.config is None:
|
|
|
|
self.config = dict()
|
|
|
|
|
|
|
|
|
2013-01-04 18:16:58 +00:00
|
|
|
def task(ctx, config):
|
2014-02-14 02:18:56 +00:00
|
|
|
if config is None:
|
|
|
|
config = {}
|
|
|
|
assert isinstance(config, dict), \
|
|
|
|
'mon_clock_skew_check task only accepts a dict for configuration'
|
2017-06-27 18:57:53 +00:00
|
|
|
interval = float(config.get('interval', 30.0))
|
|
|
|
expect_skew = config.get('expect-skew', False)
|
|
|
|
|
2014-02-14 02:18:56 +00:00
|
|
|
log.info('Beginning mon_clock_skew_check...')
|
|
|
|
first_mon = teuthology.get_first_mon(ctx, config)
|
2014-03-27 16:35:28 +00:00
|
|
|
(mon,) = ctx.cluster.only(first_mon).remotes.iterkeys()
|
2014-02-14 02:18:56 +00:00
|
|
|
manager = ceph_manager.CephManager(
|
|
|
|
mon,
|
|
|
|
ctx=ctx,
|
|
|
|
logger=log.getChild('ceph_manager'),
|
|
|
|
)
|
|
|
|
|
2017-06-27 18:57:53 +00:00
|
|
|
quorum_size = len(teuthology.get_mon_names(ctx))
|
|
|
|
manager.wait_for_mon_quorum_size(quorum_size)
|
|
|
|
|
|
|
|
# wait a bit
|
|
|
|
log.info('sleeping for {s} seconds'.format(
|
|
|
|
s=interval))
|
|
|
|
time.sleep(interval)
|
|
|
|
|
|
|
|
health = manager.get_mon_health(True)
|
|
|
|
log.info('got health %s' % health)
|
|
|
|
if expect_skew:
|
|
|
|
if 'MON_CLOCK_SKEW' not in health['checks']:
|
|
|
|
raise RuntimeError('expected MON_CLOCK_SKEW but got none')
|
|
|
|
else:
|
|
|
|
if 'MON_CLOCK_SKEW' in health['checks']:
|
|
|
|
raise RuntimeError('got MON_CLOCK_SKEW but expected none')
|
2013-01-04 18:16:58 +00:00
|
|
|
|