blob: f2bbe8f1fe5708e581a606395918d45bc40abcbb [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]
29 assert len(result) <= 1, 'Not all nodes have the same time:\n {}'.format(
30 json.dumps(result, indent=4))
31
32
Oleksii Zhurba23c18332019-05-09 18:53:40 -050033@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030034def test_ntp_peers_state(local_salt_client):
35 """Test gets ntpq peers state and checks the system peer is declared"""
36 state = local_salt_client.cmd(
37 tgt='*',
38 param='ntpq -pn',
39 expr_form='compound')
40 final_result = {}
41 for node in state:
42 sys_peer_declared = False
43 if not state[node]:
44 # TODO: do not skip
Hanna Arhipova1eef8312019-05-06 20:14:18 +030045 logging.warning("Node {} is skipped".format(node))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030046 continue
47 ntpq_output = state[node].split('\n')
48 # if output has no 'remote' in the head of ntpq output
49 # the 'ntqp -np' command failed and cannot check peers
50 if 'remote' not in ntpq_output[0]:
51 final_result[node] = ntpq_output
52 continue
53
54 # take 3rd+ line of output (the actual peers)
55 try:
56 peers = ntpq_output[2:]
57 except IndexError:
58 final_result[node] = ntpq_output
59 continue
60 for p in peers:
61 if p.split()[0].startswith("*"):
62 sys_peer_declared = True
63 if not sys_peer_declared:
64 final_result[node] = ntpq_output
65 assert not final_result,\
66 "NTP peers state is not expected on some nodes, could not find " \
67 "declared system peer:\n{}".format(json.dumps(final_result, indent=4))