Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 1 | import json |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 2 | import pytest |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 3 | import logging |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 4 | |
| 5 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 6 | @pytest.mark.full |
Oleksii Zhurba | c342221 | 2018-01-16 20:22:30 +0000 | [diff] [blame] | 7 | def test_uncommited_changes(local_salt_client): |
| 8 | git_status = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 9 | tgt='salt:master', |
| 10 | param='cd /srv/salt/reclass/classes/cluster/; git status', |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 11 | expr_form='pillar', check_status=True) |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 12 | assert 'nothing to commit' in list(git_status.values())[0], ( |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 13 | "Git status shows some unmerged changes:\n{}".format( |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 14 | list(git_status.values())[0]) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 15 | ) |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 16 | |
| 17 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 18 | @pytest.mark.smoke |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 19 | def test_reclass_smoke(local_salt_client): |
| 20 | reclass = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 21 | tgt='salt:master', |
| 22 | param='reclass-salt --top; echo $?', |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 23 | expr_form='pillar', check_status=True) |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 24 | result = reclass[list(reclass.keys())[0]][-1] |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 25 | |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 26 | assert result == '0', 'Reclass is broken:\n{}'.format(reclass) |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 27 | |
| 28 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 29 | @pytest.mark.smoke |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 30 | def test_reclass_nodes(local_salt_client): |
| 31 | reclass = local_salt_client.cmd( |
| 32 | tgt='salt:master', |
| 33 | param='reclass-salt -o json --top', |
| 34 | expr_form='pillar', check_status=True) |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 35 | salt = list(local_salt_client.cmd( |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 36 | tgt='salt:master', |
| 37 | param='salt-run manage.status timeout=10 --out=json', |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 38 | expr_form='pillar', check_status=True).values())[0] or {} |
| 39 | reclass_warnings = reclass[list(reclass.keys())[0]].split('{\n "base":')[0] |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 40 | if reclass_warnings: |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 41 | logging.warning("\nReclass-salt output has warnings: {}".format(reclass_warnings)) |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 42 | reclass_nodes = reclass[list(reclass.keys())[0]].split('{\n "base":')[1] |
Oleksii Zhurba | d6c250e | 2019-01-30 20:55:38 -0600 | [diff] [blame] | 43 | assert reclass_nodes != '', 'No nodes were found in' \ |
| 44 | ' reclass-salt --top output' |
| 45 | reclass_nodes = sorted(json.loads(reclass_nodes.strip("}")).keys()) |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 46 | salt_nodes = sorted([x for xs in list(json.loads(salt).values()) for x in xs]) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 47 | assert salt_nodes == reclass_nodes, ( |
| 48 | "Mismatch between registered salt nodes (left) and node defined in " |
| 49 | "reclass (right)." |
| 50 | ) |