blob: b900e12771231f3bf865ce25f48e49a151f47e00 [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 Zhurbaa10927b2017-09-27 22:09:23 +000020 for node, time in nodes_time.iteritems():
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +000021 if (int(time) - saltmaster_time) > config.get(testname)["time_deviation"] or \
22 (int(time) - saltmaster_time) < -config.get(testname)["time_deviation"]:
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023 fail[node] = time
24
25 assert not fail, 'SaltMaster time: {}\n' \
26 'Nodes with time mismatch:\n {}'.format(saltmaster_time,
27 fail)