blob: 25891656addcdca52d509f59c503910d2db43a17 [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import json
2import utils
3import pytest
Hanna Arhipova1eef8312019-05-06 20:14:18 +03004import logging
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03005
Oleksii Zhurba23c18332019-05-09 18:53:40 -05006
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03007@pytest.mark.xfail
Oleksii Zhurba23c18332019-05-09 18:53:40 -05008@pytest.mark.smoke
9#move to sl?
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030010def test_ntp_sync(local_salt_client):
11 """Test checks that system time is the same across all nodes"""
12
13 config = utils.get_configuration()
14 nodes_time = local_salt_client.cmd(
15 tgt='*',
16 param='date +%s',
17 expr_form='compound')
18 result = {}
19 for node, time in nodes_time.iteritems():
20 if isinstance(nodes_time[node], bool):
21 time = 'Cannot access node(-s)'
22 if node in config.get("ntp_skipped_nodes"):
23 continue
24 if time in result:
25 result[time].append(node)
26 result[time].sort()
27 else:
28 result[time] = [node]
Dmitriy Kruglovbc0a88b2019-08-20 11:45:35 +020029 assert len(result) <= 1, (
30 'Time is out of sync on the following nodes:\n{}'.format(
31 json.dumps(result, indent=4))
32 )
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030033
34
Ievgeniia Zadorozhnab7b00b52019-11-06 15:46:26 +030035@pytest.mark.flaky(reruns=5, reruns_delay=60)
Oleksii Zhurba23c18332019-05-09 18:53:40 -050036@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030037def test_ntp_peers_state(local_salt_client):
38 """Test gets ntpq peers state and checks the system peer is declared"""
39 state = local_salt_client.cmd(
40 tgt='*',
41 param='ntpq -pn',
42 expr_form='compound')
43 final_result = {}
44 for node in state:
45 sys_peer_declared = False
46 if not state[node]:
47 # TODO: do not skip
Hanna Arhipova1eef8312019-05-06 20:14:18 +030048 logging.warning("Node {} is skipped".format(node))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030049 continue
50 ntpq_output = state[node].split('\n')
51 # if output has no 'remote' in the head of ntpq output
52 # the 'ntqp -np' command failed and cannot check peers
53 if 'remote' not in ntpq_output[0]:
54 final_result[node] = ntpq_output
55 continue
56
57 # take 3rd+ line of output (the actual peers)
58 try:
59 peers = ntpq_output[2:]
60 except IndexError:
61 final_result[node] = ntpq_output
62 continue
63 for p in peers:
64 if p.split()[0].startswith("*"):
65 sys_peer_declared = True
66 if not sys_peer_declared:
67 final_result[node] = ntpq_output
Dmitriy Kruglovbc0a88b2019-08-20 11:45:35 +020068 assert not final_result, (
69 "NTP peers state is not as expected on some nodes; could not find "
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030070 "declared system peer:\n{}".format(json.dumps(final_result, indent=4))
Dmitriy Kruglovbc0a88b2019-08-20 11:45:35 +020071 )