blob: 9a4e3eedcee4abe2f4968b10d7ec83dde1eeb767 [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)"'
dcech47a950a2018-09-18 10:14:58 +02007STATUS_COMMAND = "contrail-status -t 10"
Mikhail Chernike6d470f2018-08-08 18:29:57 +02008
9def get_contrail_status(salt_client, pillar, command, processor):
10 return salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050011 tgt=pillar,
12 param='{} | {}'.format(command, processor),
Mikhail Chernike6d470f2018-08-08 18:29:57 +020013 expr_form='pillar'
14 )
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000015
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050016@pytest.mark.sl_dup
17#ContrailApiDown, ContrailApiDownMinor
18@pytest.mark.full
Hanna Arhipova10e2db42019-05-02 13:17:00 +030019def test_contrail_compute_status(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020020 cs = get_contrail_status(local_salt_client, 'nova:compute',
21 STATUS_COMMAND, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000022 broken_services = []
23
24 for node in cs:
25 for line in cs[node].split('\n'):
26 line = line.strip()
Oleksii Zhurba2d06aca2017-11-20 15:20:14 -060027 if len (line.split(None, 1)) == 1:
28 err_msg = "{0}: {1}".format(
29 node, line)
30 broken_services.append(err_msg)
31 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000032 name, status = line.split(None, 1)
33 if status not in {'active'}:
34 err_msg = "{node}:{service} - {status}".format(
35 node=node, service=name, status=status)
36 broken_services.append(err_msg)
37
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020038 assert not broken_services, (
39 'Some Contrail services are in wrong state on computes: {}'.format(
40 json.dumps(broken_services, indent=4))
41 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000042
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050043@pytest.mark.smoke
Hanna Arhipova10e2db42019-05-02 13:17:00 +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
Dmitriy Kruglova34a3042019-08-20 11:45:35 +020069 assert not broken_services, (
70 'Some Contrail services are in wrong state on Contrail controllers: '
71 '{}'.format(json.dumps(broken_services, indent=4))
72 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000073
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050074@pytest.mark.smoke
Hanna Arhipova10e2db42019-05-02 13:17:00 +030075def test_contrail_vrouter_count(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020076 cs = get_contrail_status(local_salt_client, 'nova:compute',
77 STATUS_COMMAND, STATUS_FILTER)
78
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000079 # TODO: what if compute lacks these service unintentionally?
80 if not cs:
81 pytest.skip("Contrail services were not found on compute nodes")
82
83 actual_vrouter_count = 0
84 for node in cs:
85 for line in cs[node].split('\n'):
86 if 'contrail-vrouter-nodemgr' in line:
87 actual_vrouter_count += 1
88
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030089 assert actual_vrouter_count == len(list(cs.keys())),\
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000090 'The length of vRouters {} differs' \
91 ' from the length of compute nodes {}'.format(actual_vrouter_count,
Ekaterina Chernovae32e3f92019-11-12 14:56:03 +030092 len(list(cs.keys())))
Oleksii Zhurba25215d92019-01-31 16:35:57 -060093
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050094@pytest.mark.smoke
Hanna Arhipova10e2db42019-05-02 13:17:00 +030095def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack):
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050096 IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
Oleksii Zhurba25215d92019-01-31 16:35:57 -060097 protocol = 'https'
98 port = '8143'
99 url = "{}://{}:{}".format(protocol, IP, port)
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -0500100 result = local_salt_client.cmd_any(
101 tgt=ctl_nodes_pillar,
102 param='curl -k {}/ 2>&1 | \
103 grep Contrail'.format(url))
104 assert len(result) != 0, \
Oleksii Zhurba25215d92019-01-31 16:35:57 -0600105 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url)