blob: 862606a5ca1525b3954f12c9b81b1b873124bab9 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03003import 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(
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030012 tgt=pillar,
13 param='{} | {}'.format(command, processor),
Mikhail Chernike6d470f2018-08-08 18:29:57 +020014 expr_form='pillar'
15 )
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000016
Oleksii Zhurba23c18332019-05-09 18:53:40 -050017@pytest.mark.sl_dup
18#ContrailApiDown, ContrailApiDownMinor
19@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030020def test_contrail_compute_status(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020021 cs = get_contrail_status(local_salt_client, 'nova:compute',
22 STATUS_COMMAND, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000023 broken_services = []
24
25 for node in cs:
26 for line in cs[node].split('\n'):
27 line = line.strip()
Oleksii Zhurba2d06aca2017-11-20 15:20:14 -060028 if len (line.split(None, 1)) == 1:
29 err_msg = "{0}: {1}".format(
30 node, line)
31 broken_services.append(err_msg)
32 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000033 name, status = line.split(None, 1)
34 if status not in {'active'}:
35 err_msg = "{node}:{service} - {status}".format(
36 node=node, service=name, status=status)
37 broken_services.append(err_msg)
38
39 assert not broken_services, 'Broken services: {}'.format(json.dumps(
40 broken_services,
41 indent=4))
42
Oleksii Zhurba23c18332019-05-09 18:53:40 -050043@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030044def test_contrail_node_status(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020045 command = STATUS_COMMAND
46
47 # TODO: what will be in OpenContrail 5?
48 if pytest.contrail == '4':
49 command = "doctrail all " + command
50 cs = get_contrail_status(local_salt_client,
51 'opencontrail:client:analytics_node',
52 command, STATUS_FILTER)
53 cs.update(get_contrail_status(local_salt_client, 'opencontrail:control',
54 command, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000055 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000056 broken_services = []
57 for node in cs:
58 for line in cs[node].split('\n'):
59 line = line.strip()
60 if 'crashes/core.java.' not in line:
61 name, status = line.split(None, 1)
62 else:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000063 name, status = line, 'FATAL'
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000064 if status not in {'active', 'backup'}:
65 err_msg = "{node}:{service} - {status}".format(
66 node=node, service=name, status=status)
67 broken_services.append(err_msg)
68
69 assert not broken_services, 'Broken services: {}'.format(json.dumps(
70 broken_services,
71 indent=4))
72
Oleksii Zhurba23c18332019-05-09 18:53:40 -050073@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030074def test_contrail_vrouter_count(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020075 cs = get_contrail_status(local_salt_client, 'nova:compute',
76 STATUS_COMMAND, STATUS_FILTER)
77
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000078 # 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()))
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -060092
Oleksii Zhurba23c18332019-05-09 18:53:40 -050093@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030094def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack):
95 IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -060096 protocol = 'https'
97 port = '8143'
98 url = "{}://{}:{}".format(protocol, IP, port)
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030099 result = local_salt_client.cmd_any(
100 tgt=ctl_nodes_pillar,
101 param='curl -k {}/ 2>&1 | \
102 grep Contrail'.format(url))
103 assert len(result) != 0, \
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -0600104 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url)