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 | |
| 38 | assert not broken_services, 'Broken services: {}'.format(json.dumps( |
| 39 | broken_services, |
| 40 | indent=4)) |
| 41 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame^] | 42 | @pytest.mark.smoke |
Hanna Arhipova | 10e2db4 | 2019-05-02 13:17:00 +0300 | [diff] [blame] | 43 | def test_contrail_node_status(local_salt_client, check_openstack): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 44 | 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 54 | ) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 55 | 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 Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 62 | name, status = line, 'FATAL' |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 63 | 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 Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame^] | 72 | @pytest.mark.smoke |
Hanna Arhipova | 10e2db4 | 2019-05-02 13:17:00 +0300 | [diff] [blame] | 73 | def test_contrail_vrouter_count(local_salt_client, check_openstack): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 74 | cs = get_contrail_status(local_salt_client, 'nova:compute', |
| 75 | STATUS_COMMAND, STATUS_FILTER) |
| 76 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 77 | # 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 Zhurba | 25215d9 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 91 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame^] | 92 | @pytest.mark.smoke |
Hanna Arhipova | 10e2db4 | 2019-05-02 13:17:00 +0300 | [diff] [blame] | 93 | 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] | 94 | IP = local_salt_client.pillar_get(param='_param:cluster_public_host') |
Oleksii Zhurba | 25215d9 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 95 | protocol = 'https' |
| 96 | port = '8143' |
| 97 | url = "{}://{}:{}".format(protocol, IP, port) |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 98 | 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 Zhurba | 25215d9 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 103 | 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url) |