blob: 2d358e9678e90210741919bf281df748532f2094 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
3
Mikhail Chernike6d470f2018-08-08 18:29:57 +02004pytestmark = pytest.mark.usefixtures("contrail")
5
6STATUS_FILTER = r'grep -Pv "(==|^$|Disk|unix|support|boot|\*\*|FOR NODE)"'
7STATUS_COMMAND = "contrail-status"
8
9def get_contrail_status(salt_client, pillar, command, processor):
10 return salt_client.cmd(
11 pillar, 'cmd.run',
12 ['{} | {}'.format(command, processor)],
13 expr_form='pillar'
14 )
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000015
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000016def test_contrail_compute_status(local_salt_client):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020017 cs = get_contrail_status(local_salt_client, 'nova:compute',
18 STATUS_COMMAND, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000019 broken_services = []
20
21 for node in cs:
22 for line in cs[node].split('\n'):
23 line = line.strip()
Oleksii Zhurba2d06aca2017-11-20 15:20:14 -060024 if len (line.split(None, 1)) == 1:
25 err_msg = "{0}: {1}".format(
26 node, line)
27 broken_services.append(err_msg)
28 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000029 name, status = line.split(None, 1)
30 if status not in {'active'}:
31 err_msg = "{node}:{service} - {status}".format(
32 node=node, service=name, status=status)
33 broken_services.append(err_msg)
34
35 assert not broken_services, 'Broken services: {}'.format(json.dumps(
36 broken_services,
37 indent=4))
38
39
40def test_contrail_node_status(local_salt_client):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020041 command = STATUS_COMMAND
42
43 # TODO: what will be in OpenContrail 5?
44 if pytest.contrail == '4':
45 command = "doctrail all " + command
46 cs = get_contrail_status(local_salt_client,
47 'opencontrail:client:analytics_node',
48 command, STATUS_FILTER)
49 cs.update(get_contrail_status(local_salt_client, 'opencontrail:control',
50 command, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000051 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000052 broken_services = []
53 for node in cs:
54 for line in cs[node].split('\n'):
55 line = line.strip()
56 if 'crashes/core.java.' not in line:
57 name, status = line.split(None, 1)
58 else:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000059 name, status = line, 'FATAL'
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000060 if status not in {'active', 'backup'}:
61 err_msg = "{node}:{service} - {status}".format(
62 node=node, service=name, status=status)
63 broken_services.append(err_msg)
64
65 assert not broken_services, 'Broken services: {}'.format(json.dumps(
66 broken_services,
67 indent=4))
68
69
70def test_contrail_vrouter_count(local_salt_client):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020071 cs = get_contrail_status(local_salt_client, 'nova:compute',
72 STATUS_COMMAND, STATUS_FILTER)
73
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000074 # TODO: what if compute lacks these service unintentionally?
75 if not cs:
76 pytest.skip("Contrail services were not found on compute nodes")
77
78 actual_vrouter_count = 0
79 for node in cs:
80 for line in cs[node].split('\n'):
81 if 'contrail-vrouter-nodemgr' in line:
82 actual_vrouter_count += 1
83
84 assert actual_vrouter_count == len(cs.keys()),\
85 'The length of vRouters {} differs' \
86 ' from the length of compute nodes {}'.format(actual_vrouter_count,
87 len(cs.keys()))