blob: b8955f01a91cb604bdcd40c75e5a401601976cbd [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
3
Oleksii Zhurba3dbed242017-10-31 19:58:53 +00004
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00005def test_contrail_compute_status(local_salt_client):
Oleksii Zhurba06223b72017-10-02 20:25:45 +00006 probe = local_salt_client.cmd(
7 'opencontrail:control', 'cmd.run',
8 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
9 expr_form='pillar'
10 )
11 if not probe:
12 pytest.skip("Contrail is not found on this environment")
13
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000014 cs = local_salt_client.cmd(
15 'nova:compute', 'cmd.run',
16 ['contrail-status | grep -Pv \'(==|^$)\''],
17 expr_form='pillar'
18 )
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()
24 name, status = line.split(None, 1)
25 if status not in {'active'}:
26 err_msg = "{node}:{service} - {status}".format(
27 node=node, service=name, status=status)
28 broken_services.append(err_msg)
29
30 assert not broken_services, 'Broken services: {}'.format(json.dumps(
31 broken_services,
32 indent=4))
33
34
35def test_contrail_node_status(local_salt_client):
36 cs = local_salt_client.cmd(
37 'opencontrail:client:analytics_node', 'cmd.run',
38 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
39 expr_form='pillar'
40 )
41 cs.update(local_salt_client.cmd(
42 'opencontrail:control', 'cmd.run',
43 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
44 expr_form='pillar')
45 )
46 if not cs:
Oleksii Zhurba06223b72017-10-02 20:25:45 +000047 pytest.skip("Contrail is not found on this environment")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000048 broken_services = []
49 for node in cs:
50 for line in cs[node].split('\n'):
51 line = line.strip()
52 if 'crashes/core.java.' not in line:
53 name, status = line.split(None, 1)
54 else:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000055 name, status = line, 'FATAL'
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000056 if status not in {'active', 'backup'}:
57 err_msg = "{node}:{service} - {status}".format(
58 node=node, service=name, status=status)
59 broken_services.append(err_msg)
60
61 assert not broken_services, 'Broken services: {}'.format(json.dumps(
62 broken_services,
63 indent=4))
64
65
66def test_contrail_vrouter_count(local_salt_client):
Oleksii Zhurba06223b72017-10-02 20:25:45 +000067 probe = local_salt_client.cmd(
68 'opencontrail:control', 'cmd.run',
69 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
70 expr_form='pillar'
71 )
72 if not probe:
73 pytest.skip("Contrail is not found on this environment")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000074 cs = local_salt_client.cmd(
75 'nova:compute', 'cmd.run', ['contrail-status | grep -Pv \'(==|^$)\''],
76 expr_form='pillar'
77 )
78 # TODO: what if compute lacks these service unintentionally?
79 if not cs:
80 pytest.skip("Contrail services were not found on compute nodes")
81
82 actual_vrouter_count = 0
83 for node in cs:
84 for line in cs[node].split('\n'):
85 if 'contrail-vrouter-nodemgr' in line:
86 actual_vrouter_count += 1
87
88 assert actual_vrouter_count == len(cs.keys()),\
89 'The length of vRouters {} differs' \
90 ' from the length of compute nodes {}'.format(actual_vrouter_count,
91 len(cs.keys()))