blob: 1c1ad13955a6a989dd5054b624b0838e2455de8b [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -06003from cvp_checks import 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(
12 pillar, 'cmd.run',
13 ['{} | {}'.format(command, processor)],
14 expr_form='pillar'
15 )
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000016
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000017def test_contrail_compute_status(local_salt_client):
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
41def test_contrail_node_status(local_salt_client):
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
71def test_contrail_vrouter_count(local_salt_client):
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
91def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar):
92 IP = utils.get_monitoring_ip('cluster_public_host')
93 protocol = 'https'
94 port = '8143'
95 url = "{}://{}:{}".format(protocol, IP, port)
96 result = local_salt_client.cmd(
97 ctl_nodes_pillar,
98 'cmd.run',
99 ['curl -k {}/ 2>&1 | \
100 grep Contrail'.format(url)],
101 expr_form='pillar')
102 assert len(result[result.keys()[0]]) != 0, \
103 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url)