Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | from cvp_checks import utils |
Oleksii Zhurba | 1a21b56 | 2019-02-26 17:33:43 -0600 | [diff] [blame^] | 2 | import json |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 3 | |
| 4 | |
Oleksii Zhurba | 17a8848 | 2017-10-06 14:29:05 -0500 | [diff] [blame] | 5 | def test_ntp_sync(local_salt_client): |
Oleksii Zhurba | 1a21b56 | 2019-02-26 17:33:43 -0600 | [diff] [blame^] | 6 | """Test checks that system time is the same across all nodes""" |
| 7 | |
| 8 | active_nodes = utils.get_active_nodes() |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 9 | config = utils.get_configuration() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 10 | nodes_time = local_salt_client.cmd( |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 11 | utils.list_to_target_string(active_nodes, 'or'), |
| 12 | 'cmd.run', |
| 13 | ['date +%s'], |
| 14 | expr_form='compound') |
Oleksii Zhurba | 1a21b56 | 2019-02-26 17:33:43 -0600 | [diff] [blame^] | 15 | result = {} |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 16 | for node, time in nodes_time.iteritems(): |
Oleksii Zhurba | 1a21b56 | 2019-02-26 17:33:43 -0600 | [diff] [blame^] | 17 | 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)) |