Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | from cvp_checks import utils |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 2 | import os |
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 | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 6 | testname = os.path.basename(__file__).split('.')[0] |
| 7 | active_nodes = utils.get_active_nodes(os.path.basename(__file__)) |
| 8 | config = utils.get_configuration() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 9 | fail = {} |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 10 | saltmaster_time = int(local_salt_client.cmd( |
Oleksii Zhurba | 17a8848 | 2017-10-06 14:29:05 -0500 | [diff] [blame] | 11 | 'salt:master', |
| 12 | 'cmd.run', |
| 13 | ['date +%s'], |
| 14 | expr_form='pillar').values()[0]) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 15 | nodes_time = local_salt_client.cmd( |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 16 | utils.list_to_target_string(active_nodes, 'or'), |
| 17 | 'cmd.run', |
| 18 | ['date +%s'], |
| 19 | expr_form='compound') |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame^] | 20 | diff = config.get(testname)["time_deviation"] or 30 |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 21 | for node, time in nodes_time.iteritems(): |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame^] | 22 | if (int(time) - saltmaster_time) > diff or \ |
| 23 | (int(time) - saltmaster_time) < -diff: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 24 | fail[node] = time |
| 25 | |
| 26 | assert not fail, 'SaltMaster time: {}\n' \ |
| 27 | 'Nodes with time mismatch:\n {}'.format(saltmaster_time, |
| 28 | fail) |