blob: 5c9c1739836f575a2f39b0e226b20c4cbcb74ca0 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001from cvp_checks import utils
Oleksii Zhurba1a21b562019-02-26 17:33:43 -06002import json
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00003
4
Oleksii Zhurba17a88482017-10-06 14:29:05 -05005def test_ntp_sync(local_salt_client):
Oleksii Zhurba1a21b562019-02-26 17:33:43 -06006 """Test checks that system time is the same across all nodes"""
7
8 active_nodes = utils.get_active_nodes()
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00009 config = utils.get_configuration()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000010 nodes_time = local_salt_client.cmd(
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +000011 utils.list_to_target_string(active_nodes, 'or'),
12 'cmd.run',
13 ['date +%s'],
14 expr_form='compound')
Oleksii Zhurba1a21b562019-02-26 17:33:43 -060015 result = {}
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000016 for node, time in nodes_time.iteritems():
Oleksii Zhurba1a21b562019-02-26 17:33:43 -060017 if node in config.get("ntp_skipped_nodes"):
18 continue
19 if time in result:
20 result[time].append(node)
21 result[time].sort()
22 else:
23 result[time] = [node]
24 assert len(result) <= 1, 'Not all nodes have the same time:\n {}'.format(
25 json.dumps(result, indent=4))