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