Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
| 3 | |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 4 | pytestmark = pytest.mark.usefixtures("contrail") |
| 5 | |
| 6 | STATUS_FILTER = r'grep -Pv "(==|^$|Disk|unix|support|boot|\*\*|FOR NODE)"' |
dcech | 47a950a | 2018-09-18 10:14:58 +0200 | [diff] [blame] | 7 | STATUS_COMMAND = "contrail-status -t 10" |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 8 | |
| 9 | def get_contrail_status(salt_client, pillar, command, processor): |
| 10 | return salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 11 | tgt=pillar, |
| 12 | param='{} | {}'.format(command, processor), |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 13 | expr_form='pillar' |
| 14 | ) |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 15 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 16 | @pytest.mark.sl_dup |
| 17 | #ContrailApiDown, ContrailApiDownMinor |
| 18 | @pytest.mark.full |
Hanna Arhipova | 10e2db4 | 2019-05-02 13:17:00 +0300 | [diff] [blame] | 19 | def test_contrail_compute_status(local_salt_client, check_openstack): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 20 | cs = get_contrail_status(local_salt_client, 'nova:compute', |
| 21 | STATUS_COMMAND, STATUS_FILTER) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 22 | broken_services = [] |
| 23 | |
| 24 | for node in cs: |
| 25 | for line in cs[node].split('\n'): |
| 26 | line = line.strip() |
Oleksii Zhurba | 2d06aca | 2017-11-20 15:20:14 -0600 | [diff] [blame] | 27 | 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 32 | 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 Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 38 | assert not broken_services, ( |
| 39 | 'Some Contrail services are in wrong state on computes: {}'.format( |
| 40 | json.dumps(broken_services, indent=4)) |
| 41 | ) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 42 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 43 | @pytest.mark.smoke |
Hanna Arhipova | 10e2db4 | 2019-05-02 13:17:00 +0300 | [diff] [blame] | 44 | def test_contrail_node_status(local_salt_client, check_openstack): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 45 | 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 55 | ) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 56 | 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 Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 63 | name, status = line, 'FATAL' |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 64 | 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 Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 69 | 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 73 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 74 | @pytest.mark.smoke |
Hanna Arhipova | 10e2db4 | 2019-05-02 13:17:00 +0300 | [diff] [blame] | 75 | def test_contrail_vrouter_count(local_salt_client, check_openstack): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 76 | cs = get_contrail_status(local_salt_client, 'nova:compute', |
| 77 | STATUS_COMMAND, STATUS_FILTER) |
| 78 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 79 | # 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 Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 89 | assert actual_vrouter_count == len(list(cs.keys())),\ |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 90 | 'The length of vRouters {} differs' \ |
| 91 | ' from the length of compute nodes {}'.format(actual_vrouter_count, |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 92 | len(list(cs.keys()))) |
Oleksii Zhurba | 25215d9 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 93 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 94 | @pytest.mark.smoke |
Hanna Arhipova | 10e2db4 | 2019-05-02 13:17:00 +0300 | [diff] [blame] | 95 | def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack): |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 96 | IP = local_salt_client.pillar_get(param='_param:cluster_public_host') |
Oleksii Zhurba | 25215d9 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 97 | protocol = 'https' |
| 98 | port = '8143' |
| 99 | url = "{}://{}:{}".format(protocol, IP, port) |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 100 | 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 Zhurba | 25215d9 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 105 | 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url) |