Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 1 | import utils |
| 2 | import json |
Oleksii Zhurba | bb630be | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 3 | import pytest |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 4 | |
| 5 | |
| 6 | def test_single_vip_exists(local_salt_client): |
| 7 | """Test checks that there is only one VIP address |
| 8 | within one group of nodes (where applicable). |
| 9 | Steps: |
| 10 | 1. Get IP addresses for nodes via salt cmd.run 'ip a | grep /32' |
Oleksii Zhurba | bb630be | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 11 | 2. Check that exactly 1 node responds with something. |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 12 | """ |
| 13 | groups = utils.calculate_groups() |
Oleksii Zhurba | bb630be | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 14 | |
| 15 | keywords_to_exclude_interfaces = ["flannel.1"] |
| 16 | exclude_from_grep = " | grep -v {}".format('\|'.join(keywords_to_exclude_interfaces)) \ |
| 17 | if len(keywords_to_exclude_interfaces) > 0 \ |
| 18 | else "" |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 19 | no_vip = {} |
| 20 | for group in groups: |
| 21 | if group in ['cmp', 'cfg', 'kvm', 'cmn', 'osd', 'gtw']: |
| 22 | continue |
| 23 | nodes_list = local_salt_client.cmd( |
Oleksii Zhurba | bb630be | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 24 | tgt="L@" + ','.join(groups[group]), |
| 25 | fun='cmd.run', |
| 26 | param='ip a | grep /32 ' + exclude_from_grep, |
| 27 | expr_form='compound') |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 28 | result = [x for x in nodes_list.values() if x] |
| 29 | if len(result) != 1: |
| 30 | if len(result) == 0: |
| 31 | no_vip[group] = 'No vip found' |
| 32 | else: |
| 33 | no_vip[group] = nodes_list |
| 34 | assert len(no_vip) < 1, "Some groups of nodes have problem with vip " \ |
| 35 | "\n{}".format(json.dumps(no_vip, indent=4)) |