blob: 716c864f747d67fb189d07db2ac5ca421dd78de2 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Oleksii Zhurbab1c556e2019-05-22 15:48:25 -05003
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
Dmitriy Kruglovbc0a88b2019-08-20 11:45:35 +020039 assert not broken_services, (
40 'Some Contrail services are in wrong state on computes: {}'.format(
41 json.dumps(broken_services, indent=4))
42 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000043
Oleksii Zhurba23c18332019-05-09 18:53:40 -050044@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030045def test_contrail_node_status(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020046 command = STATUS_COMMAND
47
48 # TODO: what will be in OpenContrail 5?
49 if pytest.contrail == '4':
50 command = "doctrail all " + command
51 cs = get_contrail_status(local_salt_client,
52 'opencontrail:client:analytics_node',
53 command, STATUS_FILTER)
54 cs.update(get_contrail_status(local_salt_client, 'opencontrail:control',
55 command, STATUS_FILTER)
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000056 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000057 broken_services = []
58 for node in cs:
59 for line in cs[node].split('\n'):
60 line = line.strip()
61 if 'crashes/core.java.' not in line:
62 name, status = line.split(None, 1)
63 else:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000064 name, status = line, 'FATAL'
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000065 if status not in {'active', 'backup'}:
66 err_msg = "{node}:{service} - {status}".format(
67 node=node, service=name, status=status)
68 broken_services.append(err_msg)
69
Dmitriy Kruglovbc0a88b2019-08-20 11:45:35 +020070 assert not broken_services, (
71 'Some Contrail services are in wrong state on Contrail controllers: '
72 '{}'.format(json.dumps(broken_services, indent=4))
73 )
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000074
Oleksii Zhurba23c18332019-05-09 18:53:40 -050075@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030076def test_contrail_vrouter_count(local_salt_client, check_openstack):
Mikhail Chernike6d470f2018-08-08 18:29:57 +020077 cs = get_contrail_status(local_salt_client, 'nova:compute',
78 STATUS_COMMAND, STATUS_FILTER)
79
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000080 # TODO: what if compute lacks these service unintentionally?
81 if not cs:
82 pytest.skip("Contrail services were not found on compute nodes")
83
84 actual_vrouter_count = 0
85 for node in cs:
86 for line in cs[node].split('\n'):
87 if 'contrail-vrouter-nodemgr' in line:
88 actual_vrouter_count += 1
89
90 assert actual_vrouter_count == len(cs.keys()),\
91 'The length of vRouters {} differs' \
92 ' from the length of compute nodes {}'.format(actual_vrouter_count,
93 len(cs.keys()))
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -060094
Oleksii Zhurba23c18332019-05-09 18:53:40 -050095@pytest.mark.smoke
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030096def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack):
97 IP = local_salt_client.pillar_get(param='_param:cluster_public_host')
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -060098 protocol = 'https'
99 port = '8143'
100 url = "{}://{}:{}".format(protocol, IP, port)
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +0300101 result = local_salt_client.cmd_any(
102 tgt=ctl_nodes_pillar,
103 param='curl -k {}/ 2>&1 | \
104 grep Contrail'.format(url))
105 assert len(result) != 0, \
Oleksii Zhurba2c2dc942019-01-31 16:35:57 -0600106 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url)