Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
Oleksii Zhurba | b1c556e | 2019-05-22 15:48:25 -0500 | [diff] [blame] | 3 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 4 | |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 5 | pytestmark = pytest.mark.usefixtures("contrail") |
| 6 | |
| 7 | STATUS_FILTER = r'grep -Pv "(==|^$|Disk|unix|support|boot|\*\*|FOR NODE)"' |
dcech | 47a950a | 2018-09-18 10:14:58 +0200 | [diff] [blame] | 8 | STATUS_COMMAND = "contrail-status -t 10" |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 9 | |
| 10 | def get_contrail_status(salt_client, pillar, command, processor): |
| 11 | return salt_client.cmd( |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 12 | tgt=pillar, |
| 13 | param='{} | {}'.format(command, processor), |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 14 | expr_form='pillar' |
| 15 | ) |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 16 | |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 17 | @pytest.mark.sl_dup |
| 18 | #ContrailApiDown, ContrailApiDownMinor |
| 19 | @pytest.mark.full |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 20 | def test_contrail_compute_status(local_salt_client, check_openstack): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 21 | cs = get_contrail_status(local_salt_client, 'nova:compute', |
| 22 | STATUS_COMMAND, STATUS_FILTER) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 23 | broken_services = [] |
| 24 | |
| 25 | for node in cs: |
| 26 | for line in cs[node].split('\n'): |
| 27 | line = line.strip() |
Oleksii Zhurba | 2d06aca | 2017-11-20 15:20:14 -0600 | [diff] [blame] | 28 | 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 33 | 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 | |
| 39 | assert not broken_services, 'Broken services: {}'.format(json.dumps( |
| 40 | broken_services, |
| 41 | indent=4)) |
| 42 | |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 43 | @pytest.mark.smoke |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +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 | |
| 69 | assert not broken_services, 'Broken services: {}'.format(json.dumps( |
| 70 | broken_services, |
| 71 | indent=4)) |
| 72 | |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 73 | @pytest.mark.smoke |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 74 | def test_contrail_vrouter_count(local_salt_client, check_openstack): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 75 | cs = get_contrail_status(local_salt_client, 'nova:compute', |
| 76 | STATUS_COMMAND, STATUS_FILTER) |
| 77 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 78 | # TODO: what if compute lacks these service unintentionally? |
| 79 | if not cs: |
| 80 | pytest.skip("Contrail services were not found on compute nodes") |
| 81 | |
| 82 | actual_vrouter_count = 0 |
| 83 | for node in cs: |
| 84 | for line in cs[node].split('\n'): |
| 85 | if 'contrail-vrouter-nodemgr' in line: |
| 86 | actual_vrouter_count += 1 |
| 87 | |
| 88 | assert actual_vrouter_count == len(cs.keys()),\ |
| 89 | 'The length of vRouters {} differs' \ |
| 90 | ' from the length of compute nodes {}'.format(actual_vrouter_count, |
| 91 | len(cs.keys())) |
Oleksii Zhurba | 2c2dc94 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 92 | |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 93 | @pytest.mark.smoke |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 94 | def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar, check_openstack): |
| 95 | IP = local_salt_client.pillar_get(param='_param:cluster_public_host') |
Oleksii Zhurba | 2c2dc94 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 96 | protocol = 'https' |
| 97 | port = '8143' |
| 98 | url = "{}://{}:{}".format(protocol, IP, port) |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 99 | result = local_salt_client.cmd_any( |
| 100 | tgt=ctl_nodes_pillar, |
| 101 | param='curl -k {}/ 2>&1 | \ |
| 102 | grep Contrail'.format(url)) |
| 103 | assert len(result) != 0, \ |
Oleksii Zhurba | 2c2dc94 | 2019-01-31 16:35:57 -0600 | [diff] [blame] | 104 | 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url) |