blob: 16c3389a76f26f68657f4a146f27e77d0de2e34c [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
3
4def test_contrail_compute_status(local_salt_client):
5 cs = local_salt_client.cmd(
6 'nova:compute', 'cmd.run',
7 ['contrail-status | grep -Pv \'(==|^$)\''],
8 expr_form='pillar'
9 )
10 # TODO: what if compute lacks these service unintentionally?
11 if not cs:
12 pytest.skip("Contrail services were not found on compute nodes")
13 broken_services = []
14
15 for node in cs:
16 for line in cs[node].split('\n'):
17 line = line.strip()
18 name, status = line.split(None, 1)
19 if status not in {'active'}:
20 err_msg = "{node}:{service} - {status}".format(
21 node=node, service=name, status=status)
22 broken_services.append(err_msg)
23
24 assert not broken_services, 'Broken services: {}'.format(json.dumps(
25 broken_services,
26 indent=4))
27
28
29def test_contrail_node_status(local_salt_client):
30 cs = local_salt_client.cmd(
31 'opencontrail:client:analytics_node', 'cmd.run',
32 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
33 expr_form='pillar'
34 )
35 cs.update(local_salt_client.cmd(
36 'opencontrail:control', 'cmd.run',
37 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
38 expr_form='pillar')
39 )
40 if not cs:
41 pytest.skip("Contrail nodes were not found on compute nodes")
42 broken_services = []
43 for node in cs:
44 for line in cs[node].split('\n'):
45 line = line.strip()
46 if 'crashes/core.java.' not in line:
47 name, status = line.split(None, 1)
48 else:
49 name, status = line,'FATAL'
50 if status not in {'active', 'backup'}:
51 err_msg = "{node}:{service} - {status}".format(
52 node=node, service=name, status=status)
53 broken_services.append(err_msg)
54
55 assert not broken_services, 'Broken services: {}'.format(json.dumps(
56 broken_services,
57 indent=4))
58
59
60def test_contrail_vrouter_count(local_salt_client):
61 cs = local_salt_client.cmd(
62 'nova:compute', 'cmd.run', ['contrail-status | grep -Pv \'(==|^$)\''],
63 expr_form='pillar'
64 )
65 # TODO: what if compute lacks these service unintentionally?
66 if not cs:
67 pytest.skip("Contrail services were not found on compute nodes")
68
69 actual_vrouter_count = 0
70 for node in cs:
71 for line in cs[node].split('\n'):
72 if 'contrail-vrouter-nodemgr' in line:
73 actual_vrouter_count += 1
74
75 assert actual_vrouter_count == len(cs.keys()),\
76 'The length of vRouters {} differs' \
77 ' from the length of compute nodes {}'.format(actual_vrouter_count,
78 len(cs.keys()))