blob: 09b323f02b1ee6986056cc07d978d7032ad1ab32 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001from cvp_checks import utils
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00002import os
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00003
4
Oleksii Zhurba17a88482017-10-06 14:29:05 -05005def test_ntp_sync(local_salt_client):
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00006 testname = os.path.basename(__file__).split('.')[0]
7 active_nodes = utils.get_active_nodes(os.path.basename(__file__))
8 config = utils.get_configuration()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00009 fail = {}
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000010 saltmaster_time = int(local_salt_client.cmd(
Oleksii Zhurba17a88482017-10-06 14:29:05 -050011 'salt:master',
12 'cmd.run',
13 ['date +%s'],
14 expr_form='pillar').values()[0])
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000015 nodes_time = local_salt_client.cmd(
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +000016 utils.list_to_target_string(active_nodes, 'or'),
17 'cmd.run',
18 ['date +%s'],
19 expr_form='compound')
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000020 diff = config.get(testname)["time_deviation"] or 30
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000021 for node, time in nodes_time.iteritems():
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000022 if (int(time) - saltmaster_time) > diff or \
23 (int(time) - saltmaster_time) < -diff:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000024 fail[node] = time
25
26 assert not fail, 'SaltMaster time: {}\n' \
27 'Nodes with time mismatch:\n {}'.format(saltmaster_time,
28 fail)