Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 1 | import json |
| 2 | import utils |
| 3 | import pytest |
Hanna Arhipova | 1eef831 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 4 | import logging |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 5 | |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 6 | |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 7 | @pytest.mark.xfail |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 8 | @pytest.mark.smoke |
| 9 | #move to sl? |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 10 | def 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 Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 33 | @pytest.mark.smoke |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 34 | def 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 Arhipova | 1eef831 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 45 | logging.warning("Node {} is skipped".format(node)) |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 46 | 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)) |