blob: fcb96f9e65daedc51cfb4d9492b07d354b9aa9ef [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03003import utils
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00004
Mikhail Chernike6d470f2018-08-08 18:29:57 +02005pytestmark = pytest.mark.usefixtures("contrail")
6
7STATUS_FILTER = r'grep -Pv "(==|^$|Disk|unix|support|boot|\*\*|FOR NODE)"'
dcech47a950a2018-09-18 10:14:58 +02008STATUS_COMMAND = "contrail-status -t 10"
Mikhail Chernike6d470f2018-08-08 18:29:57 +02009
10def get_contrail_status(salt_client, pillar, command, processor):
11 return salt_client.cmd(
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030012 tgt=pillar,
13 param='{} | {}'.format(command, processor),
Mikhail Chernike6d470f2018-08-08 18:29:57 +020014 expr_form='pillar'
15 )
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000016
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030017def test_contrail_compute_status(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020018 cs = get_contrail_status(local_salt_client, 'nova:compute',
19 STATUS_COMMAND, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000020 broken_services = []
21
22 for node in cs:
23 for line in cs[node].split('\n'):
24 line = line.strip()
Oleksii Zhurba2d06aca2017-11-20 15:20:14 -060025 if len (line.split(None, 1)) == 1:
26 err_msg = "{0}: {1}".format(
27 node, line)
28 broken_services.append(err_msg)
29 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000030 name, status = line.split(None, 1)
31 if status not in {'active'}:
32 err_msg = "{node}:{service} - {status}".format(
33 node=node, service=name, status=status)
34 broken_services.append(err_msg)
35
36 assert not broken_services, 'Broken services: {}'.format(json.dumps(
37 broken_services,
38 indent=4))
39
40
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030041def test_contrail_node_status(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020042 command = STATUS_COMMAND
43
44 # TODO: what will be in OpenContrail 5?
45 if pytest.contrail == '4':
46 command = "doctrail all " + command
47 cs = get_contrail_status(local_salt_client,
48 'opencontrail:client:analytics_node',
49 command, STATUS_FILTER)
50 cs.update(get_contrail_status(local_salt_client, 'opencontrail:control',
51 command, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000052 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000053 broken_services = []
54 for node in cs:
55 for line in cs[node].split('\n'):
56 line = line.strip()
57 if 'crashes/core.java.' not in line:
58 name, status = line.split(None, 1)
59 else:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000060 name, status = line, 'FATAL'
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000061 if status not in {'active', 'backup'}:
62 err_msg = "{node}:{service} - {status}".format(
63 node=node, service=name, status=status)
64 broken_services.append(err_msg)
65
66 assert not broken_services, 'Broken services: {}'.format(json.dumps(
67 broken_services,
68 indent=4))
69
70
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030071def test_contrail_vrouter_count(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020072 cs = get_contrail_status(local_salt_client, 'nova:compute',
73 STATUS_COMMAND, STATUS_FILTER)
74
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000075 # TODO: what if compute lacks these service unintentionally?
76 if not cs:
77 pytest.skip("Contrail services were not found on compute nodes")
78
79 actual_vrouter_count = 0
80 for node in cs:
81 for line in cs[node].split('\n'):
82 if 'contrail-vrouter-nodemgr' in line:
83 actual_vrouter_count += 1
84
85 assert actual_vrouter_count == len(cs.keys()),\
86 'The length of vRouters {} differs' \
87 ' from the length of compute nodes {}'.format(actual_vrouter_count,
88 len(cs.keys()))
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -060089
90
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030091def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack):
92 IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -060093 protocol = 'https'
94 port = '8143'
95 url = "{}://{}:{}".format(protocol, IP, port)
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030096 result = local_salt_client.cmd_any(
97 tgt=ctl_nodes_pillar,
98 param='curl -k {}/ 2>&1 | \
99 grep Contrail'.format(url))
100 assert len(result) != 0, \
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -0600101 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url)