Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
| 3 | |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 4 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 5 | def test_contrail_compute_status(local_salt_client): |
Oleksii Zhurba | 06223b7 | 2017-10-02 20:25:45 +0000 | [diff] [blame] | 6 | probe = local_salt_client.cmd( |
| 7 | 'opencontrail:control', 'cmd.run', |
| 8 | ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''], |
| 9 | expr_form='pillar' |
| 10 | ) |
| 11 | if not probe: |
| 12 | pytest.skip("Contrail is not found on this environment") |
| 13 | |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 14 | cs = local_salt_client.cmd( |
| 15 | 'nova:compute', 'cmd.run', |
| 16 | ['contrail-status | grep -Pv \'(==|^$)\''], |
| 17 | expr_form='pillar' |
| 18 | ) |
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() |
| 24 | name, status = line.split(None, 1) |
| 25 | if status not in {'active'}: |
| 26 | err_msg = "{node}:{service} - {status}".format( |
| 27 | node=node, service=name, status=status) |
| 28 | broken_services.append(err_msg) |
| 29 | |
| 30 | assert not broken_services, 'Broken services: {}'.format(json.dumps( |
| 31 | broken_services, |
| 32 | indent=4)) |
| 33 | |
| 34 | |
| 35 | def test_contrail_node_status(local_salt_client): |
| 36 | cs = local_salt_client.cmd( |
| 37 | 'opencontrail:client:analytics_node', 'cmd.run', |
| 38 | ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''], |
| 39 | expr_form='pillar' |
| 40 | ) |
| 41 | cs.update(local_salt_client.cmd( |
| 42 | 'opencontrail:control', 'cmd.run', |
| 43 | ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''], |
| 44 | expr_form='pillar') |
| 45 | ) |
| 46 | if not cs: |
Oleksii Zhurba | 06223b7 | 2017-10-02 20:25:45 +0000 | [diff] [blame] | 47 | pytest.skip("Contrail is not found on this environment") |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 48 | broken_services = [] |
| 49 | for node in cs: |
| 50 | for line in cs[node].split('\n'): |
| 51 | line = line.strip() |
| 52 | if 'crashes/core.java.' not in line: |
| 53 | name, status = line.split(None, 1) |
| 54 | else: |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 55 | name, status = line, 'FATAL' |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 56 | if status not in {'active', 'backup'}: |
| 57 | err_msg = "{node}:{service} - {status}".format( |
| 58 | node=node, service=name, status=status) |
| 59 | broken_services.append(err_msg) |
| 60 | |
| 61 | assert not broken_services, 'Broken services: {}'.format(json.dumps( |
| 62 | broken_services, |
| 63 | indent=4)) |
| 64 | |
| 65 | |
| 66 | def test_contrail_vrouter_count(local_salt_client): |
Oleksii Zhurba | 06223b7 | 2017-10-02 20:25:45 +0000 | [diff] [blame] | 67 | probe = local_salt_client.cmd( |
| 68 | 'opencontrail:control', 'cmd.run', |
| 69 | ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''], |
| 70 | expr_form='pillar' |
| 71 | ) |
| 72 | if not probe: |
| 73 | pytest.skip("Contrail is not found on this environment") |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 74 | cs = local_salt_client.cmd( |
| 75 | 'nova:compute', 'cmd.run', ['contrail-status | grep -Pv \'(==|^$)\''], |
| 76 | expr_form='pillar' |
| 77 | ) |
| 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())) |