Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
Oleksii Zhurba | 2c2dc94 | 2019-01-31 16:35:57 -0600 | [diff] [blame^] | 3 | from cvp_checks import utils |
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( |
| 12 | pillar, 'cmd.run', |
| 13 | ['{} | {}'.format(command, processor)], |
| 14 | expr_form='pillar' |
| 15 | ) |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 16 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 17 | def test_contrail_compute_status(local_salt_client): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 18 | cs = get_contrail_status(local_salt_client, 'nova:compute', |
| 19 | STATUS_COMMAND, STATUS_FILTER) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 20 | broken_services = [] |
| 21 | |
| 22 | for node in cs: |
| 23 | for line in cs[node].split('\n'): |
| 24 | line = line.strip() |
Oleksii Zhurba | 2d06aca | 2017-11-20 15:20:14 -0600 | [diff] [blame] | 25 | if len (line.split(None, 1)) == 1: |
| 26 | err_msg = "{0}: {1}".format( |
| 27 | node, line) |
| 28 | broken_services.append(err_msg) |
| 29 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 30 | name, status = line.split(None, 1) |
| 31 | if status not in {'active'}: |
| 32 | err_msg = "{node}:{service} - {status}".format( |
| 33 | node=node, service=name, status=status) |
| 34 | broken_services.append(err_msg) |
| 35 | |
| 36 | assert not broken_services, 'Broken services: {}'.format(json.dumps( |
| 37 | broken_services, |
| 38 | indent=4)) |
| 39 | |
| 40 | |
| 41 | def test_contrail_node_status(local_salt_client): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 42 | command = STATUS_COMMAND |
| 43 | |
| 44 | # TODO: what will be in OpenContrail 5? |
| 45 | if pytest.contrail == '4': |
| 46 | command = "doctrail all " + command |
| 47 | cs = get_contrail_status(local_salt_client, |
| 48 | 'opencontrail:client:analytics_node', |
| 49 | command, STATUS_FILTER) |
| 50 | cs.update(get_contrail_status(local_salt_client, 'opencontrail:control', |
| 51 | command, STATUS_FILTER) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 52 | ) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 53 | broken_services = [] |
| 54 | for node in cs: |
| 55 | for line in cs[node].split('\n'): |
| 56 | line = line.strip() |
| 57 | if 'crashes/core.java.' not in line: |
| 58 | name, status = line.split(None, 1) |
| 59 | else: |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 60 | name, status = line, 'FATAL' |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 61 | if status not in {'active', 'backup'}: |
| 62 | err_msg = "{node}:{service} - {status}".format( |
| 63 | node=node, service=name, status=status) |
| 64 | broken_services.append(err_msg) |
| 65 | |
| 66 | assert not broken_services, 'Broken services: {}'.format(json.dumps( |
| 67 | broken_services, |
| 68 | indent=4)) |
| 69 | |
| 70 | |
| 71 | def test_contrail_vrouter_count(local_salt_client): |
Mikhail Chernik | e6d470f | 2018-08-08 18:29:57 +0200 | [diff] [blame] | 72 | cs = get_contrail_status(local_salt_client, 'nova:compute', |
| 73 | STATUS_COMMAND, STATUS_FILTER) |
| 74 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 75 | # TODO: what if compute lacks these service unintentionally? |
| 76 | if not cs: |
| 77 | pytest.skip("Contrail services were not found on compute nodes") |
| 78 | |
| 79 | actual_vrouter_count = 0 |
| 80 | for node in cs: |
| 81 | for line in cs[node].split('\n'): |
| 82 | if 'contrail-vrouter-nodemgr' in line: |
| 83 | actual_vrouter_count += 1 |
| 84 | |
| 85 | assert actual_vrouter_count == len(cs.keys()),\ |
| 86 | 'The length of vRouters {} differs' \ |
| 87 | ' from the length of compute nodes {}'.format(actual_vrouter_count, |
| 88 | len(cs.keys())) |
Oleksii Zhurba | 2c2dc94 | 2019-01-31 16:35:57 -0600 | [diff] [blame^] | 89 | |
| 90 | |
| 91 | def test_public_ui_contrail(local_salt_client, ctl_nodes_pillar): |
| 92 | IP = utils.get_monitoring_ip('cluster_public_host') |
| 93 | protocol = 'https' |
| 94 | port = '8143' |
| 95 | url = "{}://{}:{}".format(protocol, IP, port) |
| 96 | result = local_salt_client.cmd( |
| 97 | ctl_nodes_pillar, |
| 98 | 'cmd.run', |
| 99 | ['curl -k {}/ 2>&1 | \ |
| 100 | grep Contrail'.format(url)], |
| 101 | expr_form='pillar') |
| 102 | assert len(result[result.keys()[0]]) != 0, \ |
| 103 | 'Public Contrail UI is not reachable on {} from ctl nodes'.format(url) |