blob: 22242f7f05fa0dc03bd34f372f23a1c80cf0ab4f [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()
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):
41 cs = local_salt_client.cmd(
42 'opencontrail:client:analytics_node', 'cmd.run',
Oleksii Zhurbaad020102017-11-14 16:30:38 -060043 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support|boot)\''],
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000044 expr_form='pillar'
45 )
46 cs.update(local_salt_client.cmd(
47 'opencontrail:control', 'cmd.run',
Oleksii Zhurbaad020102017-11-14 16:30:38 -060048 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support|boot)\''],
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000049 expr_form='pillar')
50 )
51 if not cs:
Oleksii Zhurba06223b72017-10-02 20:25:45 +000052 pytest.skip("Contrail is not found on this environment")
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):
Oleksii Zhurba06223b72017-10-02 20:25:45 +000072 probe = local_salt_client.cmd(
73 'opencontrail:control', 'cmd.run',
74 ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''],
75 expr_form='pillar'
76 )
77 if not probe:
78 pytest.skip("Contrail is not found on this environment")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000079 cs = local_salt_client.cmd(
80 'nova:compute', 'cmd.run', ['contrail-status | grep -Pv \'(==|^$)\''],
81 expr_form='pillar'
82 )
83 # TODO: what if compute lacks these service unintentionally?
84 if not cs:
85 pytest.skip("Contrail services were not found on compute nodes")
86
87 actual_vrouter_count = 0
88 for node in cs:
89 for line in cs[node].split('\n'):
90 if 'contrail-vrouter-nodemgr' in line:
91 actual_vrouter_count += 1
92
93 assert actual_vrouter_count == len(cs.keys()),\
94 'The length of vRouters {} differs' \
95 ' from the length of compute nodes {}'.format(actual_vrouter_count,
96 len(cs.keys()))