Oleksii Zhurba | 10b3603 | 2019-04-24 18:16:43 -0500 | [diff] [blame] | 1 | import utils |
| 2 | import json |
Oleksii Zhurba | 100dc38 | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 3 | import pytest |
Ievgeniia Zadorozhna | 6210f78 | 2019-12-30 14:32:13 +0300 | [diff] [blame] | 4 | import re |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 5 | |
| 6 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 7 | @pytest.mark.smoke |
Oleksii Zhurba | 10b3603 | 2019-04-24 18:16:43 -0500 | [diff] [blame] | 8 | def test_single_vip_exists(local_salt_client): |
| 9 | """Test checks that there is only one VIP address |
| 10 | within one group of nodes (where applicable). |
| 11 | Steps: |
| 12 | 1. Get IP addresses for nodes via salt cmd.run 'ip a | grep /32' |
Oleksii Zhurba | 100dc38 | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 13 | 2. Check that exactly 1 node responds with something. |
Oleksii Zhurba | 10b3603 | 2019-04-24 18:16:43 -0500 | [diff] [blame] | 14 | """ |
| 15 | groups = utils.calculate_groups() |
Oleksii Zhurba | 100dc38 | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 16 | |
| 17 | keywords_to_exclude_interfaces = ["flannel.1"] |
| 18 | exclude_from_grep = " | grep -v {}".format('\|'.join(keywords_to_exclude_interfaces)) \ |
| 19 | if len(keywords_to_exclude_interfaces) > 0 \ |
| 20 | else "" |
Ievgeniia Zadorozhna | 6210f78 | 2019-12-30 14:32:13 +0300 | [diff] [blame] | 21 | |
| 22 | # Let's exclude cmp, kvm, ceph OSD nodes, k8s-cmp, cfg, apt, dns, |
| 23 | # gtw, ceph mon nodes |
Hanna Arhipova | 2e4fb91 | 2020-02-11 22:20:08 +0200 | [diff] [blame^] | 24 | exclude_nodes = list(local_salt_client.test_ping( |
Ievgeniia Zadorozhna | 6210f78 | 2019-12-30 14:32:13 +0300 | [diff] [blame] | 25 | tgt="I@nova:compute or " # cmp |
| 26 | "I@ceph:osd or " # ceph osd |
| 27 | "I@salt:control or " # kvm |
| 28 | "I@ceph:mon or " # ceph mon |
| 29 | "I@salt:master or " # cfg |
| 30 | "I@neutron:gateway or " # gtw |
| 31 | "I@powerdns:server or " # dns |
| 32 | "I@debmirror:client or " # apt |
| 33 | "I@kubernetes:* and not I@etcd:*", # k8s-cmp |
Hanna Arhipova | 2e4fb91 | 2020-02-11 22:20:08 +0200 | [diff] [blame^] | 34 | expr_form='compound').keys()) |
Ievgeniia Zadorozhna | 6210f78 | 2019-12-30 14:32:13 +0300 | [diff] [blame] | 35 | |
| 36 | # bmk nodes has no unique pillar, let's add it separately to skip |
| 37 | bmk_hostname = local_salt_client.pillar_get( |
| 38 | param='_param:openstack_benchmark_node01_hostname') |
| 39 | if bmk_hostname: |
| 40 | exclude_nodes.append(bmk_hostname) |
| 41 | |
| 42 | exclude_groups = [] |
| 43 | for node in exclude_nodes: |
| 44 | index = re.search('[0-9]{1,3}$', node.split('.')[0]) |
| 45 | if index: |
| 46 | exclude_groups.append(node.split('.')[0][:-len(index.group(0))]) |
| 47 | else: |
| 48 | exclude_groups.append(node) |
Oleksii Zhurba | 10b3603 | 2019-04-24 18:16:43 -0500 | [diff] [blame] | 49 | no_vip = {} |
| 50 | for group in groups: |
Ievgeniia Zadorozhna | 6210f78 | 2019-12-30 14:32:13 +0300 | [diff] [blame] | 51 | if group in exclude_groups: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 52 | continue |
Oleksii Zhurba | 10b3603 | 2019-04-24 18:16:43 -0500 | [diff] [blame] | 53 | nodes_list = local_salt_client.cmd( |
Oleksii Zhurba | 100dc38 | 2019-05-09 14:18:17 -0500 | [diff] [blame] | 54 | tgt="L@" + ','.join(groups[group]), |
| 55 | fun='cmd.run', |
| 56 | param='ip a | grep /32 ' + exclude_from_grep, |
| 57 | expr_form='compound') |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 58 | result = [x for x in list(nodes_list.values()) if x] |
Oleksii Zhurba | 10b3603 | 2019-04-24 18:16:43 -0500 | [diff] [blame] | 59 | if len(result) != 1: |
| 60 | if len(result) == 0: |
| 61 | no_vip[group] = 'No vip found' |
| 62 | else: |
| 63 | no_vip[group] = nodes_list |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 64 | assert len(no_vip) < 1, ( |
| 65 | "The following group(s) of nodes have problem with vip:\n{}".format( |
| 66 | json.dumps(no_vip, indent=4)) |
| 67 | ) |