blob: 7d153d442b678c0da08b0339a7040584fa27c425 [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
38 assert not broken_services, 'Broken services: {}'.format(json.dumps(
39 broken_services,
40 indent=4))
41
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050042@pytest.mark.smoke
Hanna Arhipova10e2db42019-05-02 13:17:00 +030043def test_contrail_node_status(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020044 command = STATUS_COMMAND
45
46 # TODO: what will be in OpenContrail 5?
47 if pytest.contrail == '4':
48 command = "doctrail all " + command
49 cs = get_contrail_status(local_salt_client,
50 'opencontrail:client:analytics_node',
51 command, STATUS_FILTER)
52 cs.update(get_contrail_status(local_salt_client, 'opencontrail:control',
53 command, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000054 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000055 broken_services = []
56 for node in cs:
57 for line in cs[node].split('\n'):
58 line = line.strip()
59 if 'crashes/core.java.' not in line:
60 name, status = line.split(None, 1)
61 else:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000062 name, status = line, 'FATAL'
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000063 if status not in {'active', 'backup'}:
64 err_msg = "{node}:{service} - {status}".format(
65 node=node, service=name, status=status)
66 broken_services.append(err_msg)
67
68 assert not broken_services, 'Broken services: {}'.format(json.dumps(
69 broken_services,
70 indent=4))
71
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050072@pytest.mark.smoke
Hanna Arhipova10e2db42019-05-02 13:17:00 +030073def test_contrail_vrouter_count(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020074 cs = get_contrail_status(local_salt_client, 'nova:compute',
75 STATUS_COMMAND, STATUS_FILTER)
76
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000077 # TODO: what if compute lacks these service unintentionally?
78 if not cs:
79 pytest.skip("Contrail services were not found on compute nodes")
80
81 actual_vrouter_count = 0
82 for node in cs:
83 for line in cs[node].split('\n'):
84 if 'contrail-vrouter-nodemgr' in line:
85 actual_vrouter_count += 1
86
87 assert actual_vrouter_count == len(cs.keys()),\
88 'The length of vRouters {} differs' \
89 ' from the length of compute nodes {}'.format(actual_vrouter_count,
90 len(cs.keys()))
Oleksii Zhurba25215d92019-01-31 16:35:57 -060091
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -050092@pytest.mark.smoke
Hanna Arhipova10e2db42019-05-02 13:17:00 +030093def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack):
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050094 IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
Oleksii Zhurba25215d92019-01-31 16:35:57 -060095 protocol = 'https'
96 port = '8143'
97 url = "{}://{}:{}".format(protocol, IP, port)
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050098 result = local_salt_client.cmd_any(
99 tgt=ctl_nodes_pillar,
100 param='curl -k {}/ 2>&1 | \
101 grep Contrail'.format(url))
102 assert len(result) != 0, \
Oleksii Zhurba25215d92019-01-31 16:35:57 -0600103 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url)