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