blob: 691da0ab256f949233b33d6f3b0a8cee506d7888 [file] [log] [blame]
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -06001import json
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05002import pytest
Hanna Arhipova56eab942019-05-06 20:14:18 +03003import logging
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -06004
5
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05006@pytest.mark.full
Oleksii Zhurbac3422212018-01-16 20:22:30 +00007def test_uncommited_changes(local_salt_client):
8 git_status = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -05009 tgt='salt:master',
10 param='cd /srv/salt/reclass/classes/cluster/; git status',
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -060011 expr_form='pillar', check_status=True)
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030012 assert 'nothing to commit' in list(git_status.values())[0], (
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020013 "Git status shows some unmerged changes:\n{}".format(
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030014 list(git_status.values())[0])
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020015 )
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050016
17
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050018@pytest.mark.smoke
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050019def test_reclass_smoke(local_salt_client):
20 reclass = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050021 tgt='salt:master',
22 param='reclass-salt --top; echo $?',
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -060023 expr_form='pillar', check_status=True)
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030024 result = reclass[list(reclass.keys())[0]][-1]
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050025
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020026 assert result == '0', 'Reclass is broken:\n{}'.format(reclass)
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -060027
28
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050029@pytest.mark.smoke
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -060030def 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 Chernovae32e3f92019-11-12 14:56:03 +030035 salt = list(local_salt_client.cmd(
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -060036 tgt='salt:master',
37 param='salt-run manage.status timeout=10 --out=json',
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030038 expr_form='pillar', check_status=True).values())[0] or {}
39 reclass_warnings = reclass[list(reclass.keys())[0]].split('{\n "base":')[0]
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -060040 if reclass_warnings:
Hanna Arhipova56eab942019-05-06 20:14:18 +030041 logging.warning("\nReclass-salt output has warnings: {}".format(reclass_warnings))
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030042 reclass_nodes = reclass[list(reclass.keys())[0]].split('{\n "base":')[1]
Oleksii Zhurbad6c250e2019-01-30 20:55:38 -060043 assert reclass_nodes != '', 'No nodes were found in' \
44 ' reclass-salt --top output'
45 reclass_nodes = sorted(json.loads(reclass_nodes.strip("}")).keys())
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030046 salt_nodes = sorted([x for xs in list(json.loads(salt).values()) for x in xs])
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020047 assert salt_nodes == reclass_nodes, (
48 "Mismatch between registered salt nodes (left) and node defined in "
49 "reclass (right)."
50 )