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() |
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): |
| 41 | cs = local_salt_client.cmd( |
| 42 | 'opencontrail:client:analytics_node', 'cmd.run', |
Oleksii Zhurba | ad02010 | 2017-11-14 16:30:38 -0600 | [diff] [blame] | 43 | ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support|boot)\''], |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 44 | expr_form='pillar' |
| 45 | ) |
| 46 | cs.update(local_salt_client.cmd( |
| 47 | 'opencontrail:control', 'cmd.run', |
Oleksii Zhurba | ad02010 | 2017-11-14 16:30:38 -0600 | [diff] [blame] | 48 | ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support|boot)\''], |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 49 | expr_form='pillar') |
| 50 | ) |
| 51 | if not cs: |
Oleksii Zhurba | 06223b7 | 2017-10-02 20:25:45 +0000 | [diff] [blame] | 52 | pytest.skip("Contrail is not found on this environment") |
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): |
Oleksii Zhurba | 06223b7 | 2017-10-02 20:25:45 +0000 | [diff] [blame] | 72 | probe = local_salt_client.cmd( |
| 73 | 'opencontrail:control', 'cmd.run', |
| 74 | ['contrail-status | grep -Pv \'(==|^$|Disk|unix|support)\''], |
| 75 | expr_form='pillar' |
| 76 | ) |
| 77 | if not probe: |
| 78 | pytest.skip("Contrail is not found on this environment") |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 79 | cs = local_salt_client.cmd( |
| 80 | 'nova:compute', 'cmd.run', ['contrail-status | grep -Pv \'(==|^$)\''], |
| 81 | expr_form='pillar' |
| 82 | ) |
| 83 | # TODO: what if compute lacks these service unintentionally? |
| 84 | if not cs: |
| 85 | pytest.skip("Contrail services were not found on compute nodes") |
| 86 | |
| 87 | actual_vrouter_count = 0 |
| 88 | for node in cs: |
| 89 | for line in cs[node].split('\n'): |
| 90 | if 'contrail-vrouter-nodemgr' in line: |
| 91 | actual_vrouter_count += 1 |
| 92 | |
| 93 | assert actual_vrouter_count == len(cs.keys()),\ |
| 94 | 'The length of vRouters {} differs' \ |
| 95 | ' from the length of compute nodes {}'.format(actual_vrouter_count, |
| 96 | len(cs.keys())) |