blob: 578528c7e677a5aaf64df649ae3a9d26f90ce0c1 [file] [log] [blame]
Oleksii Zhurba10b36032019-04-24 18:16:43 -05001import utils
2import json
Oleksii Zhurba100dc382019-05-09 14:18:17 -05003import pytest
Ievgeniia Zadorozhna6210f782019-12-30 14:32:13 +03004import re
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00005
6
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05007@pytest.mark.smoke
Oleksii Zhurba10b36032019-04-24 18:16:43 -05008def 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 Zhurba100dc382019-05-09 14:18:17 -050013 2. Check that exactly 1 node responds with something.
Oleksii Zhurba10b36032019-04-24 18:16:43 -050014 """
15 groups = utils.calculate_groups()
Oleksii Zhurba100dc382019-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 Zadorozhna6210f782019-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
Hanna Arhipova2e4fb912020-02-11 22:20:08 +020024 exclude_nodes = list(local_salt_client.test_ping(
Ievgeniia Zadorozhna6210f782019-12-30 14:32:13 +030025 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 Arhipova2e4fb912020-02-11 22:20:08 +020034 expr_form='compound').keys())
Ievgeniia Zadorozhna6210f782019-12-30 14:32:13 +030035
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 Zhurba10b36032019-04-24 18:16:43 -050049 no_vip = {}
50 for group in groups:
Ievgeniia Zadorozhna6210f782019-12-30 14:32:13 +030051 if group in exclude_groups:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050052 continue
Oleksii Zhurba10b36032019-04-24 18:16:43 -050053 nodes_list = local_salt_client.cmd(
Oleksii Zhurba100dc382019-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 Chernovae32e3f92019-11-12 14:56:03 +030058 result = [x for x in list(nodes_list.values()) if x]
Oleksii Zhurba10b36032019-04-24 18:16:43 -050059 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 Kruglova34a3042019-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 )