Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +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 | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 5 | def test_k8s_get_cs_status(local_salt_client): |
| 6 | result = local_salt_client.cmd( |
| 7 | 'etcd:server', 'cmd.run', |
| 8 | ['kubectl get cs'], |
| 9 | expr_form='pillar' |
| 10 | ) |
| 11 | errors = [] |
| 12 | if not result: |
| 13 | pytest.skip("k8s is not found on this environment") |
| 14 | for node in result: |
| 15 | for line in result[node].split('\n'): |
| 16 | line = line.strip() |
| 17 | if 'MESSAGE' in line: |
| 18 | continue |
| 19 | else: |
| 20 | if 'Healthy' not in line: |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame^] | 21 | errors.append(line) |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 22 | break |
| 23 | assert not errors, 'k8s is not healthy: {}'.format(json.dumps( |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame^] | 24 | errors, |
| 25 | indent=4)) |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 26 | |
| 27 | |
| 28 | def test_k8s_get_nodes_status(local_salt_client): |
| 29 | result = local_salt_client.cmd( |
| 30 | 'etcd:server', 'cmd.run', |
| 31 | ['kubectl get nodes'], |
| 32 | expr_form='pillar' |
| 33 | ) |
| 34 | errors = [] |
| 35 | if not result: |
| 36 | pytest.skip("k8s is not found on this environment") |
| 37 | for node in result: |
| 38 | for line in result[node].split('\n'): |
| 39 | line = line.strip() |
| 40 | if 'STATUS' in line: |
| 41 | continue |
| 42 | else: |
| 43 | if 'Ready' not in line: |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame^] | 44 | errors.append(line) |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 45 | break |
| 46 | assert not errors, 'k8s is not healthy: {}'.format(json.dumps( |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame^] | 47 | errors, |
| 48 | indent=4)) |