blob: 31e47f7bda9bb816565bc9ee493e4d7de30b8f89 [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import utils
2import json
Oleksii Zhurbabb630be2019-05-09 14:18:17 -05003import pytest
Ievgeniia Zadorozhna0bc54972019-12-30 14:32:13 +03004import re
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03005
6
Oleksii Zhurba23c18332019-05-09 18:53:40 -05007@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03008def 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 Zhurbabb630be2019-05-09 14:18:17 -050013 2. Check that exactly 1 node responds with something.
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030014 """
15 groups = utils.calculate_groups()
Oleksii Zhurbabb630be2019-05-09 14:18:17 -050016
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 Zadorozhna0bc54972019-12-30 14:32:13 +030021
22 # Let's exclude cmp, kvm, ceph OSD nodes, k8s-cmp, cfg, apt, dns,
23 # gtw, ceph mon nodes
24 exclude_nodes = local_salt_client.test_ping(
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
34 expr_form='compound').keys()
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)
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030049 no_vip = {}
50 for group in groups:
Ievgeniia Zadorozhna0bc54972019-12-30 14:32:13 +030051 if group in exclude_groups:
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030052 continue
53 nodes_list = local_salt_client.cmd(
Oleksii Zhurbabb630be2019-05-09 14:18:17 -050054 tgt="L@" + ','.join(groups[group]),
55 fun='cmd.run',
56 param='ip a | grep /32 ' + exclude_from_grep,
57 expr_form='compound')
Ekaterina Chernovac73bc4e2019-11-12 14:56:03 +030058 result = [x for x in list(nodes_list.values()) if x]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030059 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 Kruglovbc0a88b2019-08-20 11:45:35 +020064 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 )