blob: 8da6fad3cb5c36c3ba39ccf10625c410265a219b [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import json
2import utils
3import pytest
4
Oleksii Zhurba23c18332019-05-09 18:53:40 -05005
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03006@pytest.mark.xfail
Oleksii Zhurba23c18332019-05-09 18:53:40 -05007@pytest.mark.smoke
8#move to sl?
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03009def test_ntp_sync(local_salt_client):
10 """Test checks that system time is the same across all nodes"""
11
12 config = utils.get_configuration()
13 nodes_time = local_salt_client.cmd(
14 tgt='*',
15 param='date +%s',
16 expr_form='compound')
17 result = {}
18 for node, time in nodes_time.iteritems():
19 if isinstance(nodes_time[node], bool):
20 time = 'Cannot access node(-s)'
21 if node in config.get("ntp_skipped_nodes"):
22 continue
23 if time in result:
24 result[time].append(node)
25 result[time].sort()
26 else:
27 result[time] = [node]
28 assert len(result) <= 1, 'Not all nodes have the same time:\n {}'.format(
29 json.dumps(result, indent=4))
30
31
Oleksii Zhurba23c18332019-05-09 18:53:40 -050032@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030033def test_ntp_peers_state(local_salt_client):
34 """Test gets ntpq peers state and checks the system peer is declared"""
35 state = local_salt_client.cmd(
36 tgt='*',
37 param='ntpq -pn',
38 expr_form='compound')
39 final_result = {}
40 for node in state:
41 sys_peer_declared = False
42 if not state[node]:
43 # TODO: do not skip
44 print ("Node {} is skipped".format(node))
45 continue
46 ntpq_output = state[node].split('\n')
47 # if output has no 'remote' in the head of ntpq output
48 # the 'ntqp -np' command failed and cannot check peers
49 if 'remote' not in ntpq_output[0]:
50 final_result[node] = ntpq_output
51 continue
52
53 # take 3rd+ line of output (the actual peers)
54 try:
55 peers = ntpq_output[2:]
56 except IndexError:
57 final_result[node] = ntpq_output
58 continue
59 for p in peers:
60 if p.split()[0].startswith("*"):
61 sys_peer_declared = True
62 if not sys_peer_declared:
63 final_result[node] = ntpq_output
64 assert not final_result,\
65 "NTP peers state is not expected on some nodes, could not find " \
66 "declared system peer:\n{}".format(json.dumps(final_result, indent=4))