Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
Oleksii Zhurba | 943a093 | 2017-11-01 22:27:53 +0000 | [diff] [blame] | 3 | import os |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 4 | |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 5 | |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 6 | def test_k8s_get_cs_status(local_salt_client): |
| 7 | result = local_salt_client.cmd( |
| 8 | 'etcd:server', 'cmd.run', |
| 9 | ['kubectl get cs'], |
| 10 | expr_form='pillar' |
| 11 | ) |
| 12 | errors = [] |
| 13 | if not result: |
| 14 | pytest.skip("k8s is not found on this environment") |
| 15 | for node in result: |
| 16 | for line in result[node].split('\n'): |
| 17 | line = line.strip() |
Oleksii Zhurba | 943a093 | 2017-11-01 22:27:53 +0000 | [diff] [blame] | 18 | if 'MESSAGE' in line or 'proto' in line: |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 19 | continue |
| 20 | else: |
| 21 | if 'Healthy' not in line: |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 22 | errors.append(line) |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 23 | break |
| 24 | assert not errors, 'k8s is not healthy: {}'.format(json.dumps( |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 25 | errors, |
| 26 | indent=4)) |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def test_k8s_get_nodes_status(local_salt_client): |
| 30 | result = local_salt_client.cmd( |
| 31 | 'etcd:server', 'cmd.run', |
| 32 | ['kubectl get nodes'], |
| 33 | expr_form='pillar' |
| 34 | ) |
| 35 | errors = [] |
| 36 | if not result: |
| 37 | pytest.skip("k8s is not found on this environment") |
| 38 | for node in result: |
| 39 | for line in result[node].split('\n'): |
| 40 | line = line.strip() |
Oleksii Zhurba | 943a093 | 2017-11-01 22:27:53 +0000 | [diff] [blame] | 41 | if 'STATUS' in line or 'proto' in line: |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 42 | continue |
| 43 | else: |
Oleksii Zhurba | e592ed1 | 2018-06-21 18:01:09 -0500 | [diff] [blame] | 44 | if 'Ready' != line.split()[1]: |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 45 | errors.append(line) |
Oleksii Zhurba | 11de14e | 2017-10-23 19:13:00 +0000 | [diff] [blame] | 46 | break |
| 47 | assert not errors, 'k8s is not healthy: {}'.format(json.dumps( |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 48 | errors, |
| 49 | indent=4)) |
Oleksii Zhurba | 943a093 | 2017-11-01 22:27:53 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def test_k8s_get_calico_status(local_salt_client): |
| 53 | result = local_salt_client.cmd( |
| 54 | 'kubernetes:pool', 'cmd.run', |
| 55 | ['calicoctl node status'], |
| 56 | expr_form='pillar' |
| 57 | ) |
| 58 | errors = [] |
| 59 | if not result: |
| 60 | pytest.skip("k8s is not found on this environment") |
| 61 | for node in result: |
| 62 | for line in result[node].split('\n'): |
| 63 | line = line.strip('|') |
| 64 | if 'STATE' in line or '| ' not in line: |
| 65 | continue |
| 66 | else: |
| 67 | if 'up' not in line or 'Established' not in line: |
| 68 | errors.append(line) |
| 69 | assert not errors, 'Calico node status is not good: {}'.format(json.dumps( |
| 70 | errors, |
| 71 | indent=4)) |
| 72 | |
| 73 | |
| 74 | def test_k8s_cluster_status(local_salt_client): |
| 75 | result = local_salt_client.cmd( |
| 76 | 'kubernetes:pool', 'cmd.run', |
| 77 | ['kubectl cluster-info'], |
| 78 | expr_form='pillar' |
| 79 | ) |
| 80 | errors = [] |
| 81 | if not result: |
| 82 | pytest.skip("k8s is not found on this environment") |
| 83 | for node in result: |
| 84 | for line in result[node].split('\n'): |
| 85 | if 'proto' in line or 'further' in line or line == '': |
| 86 | continue |
| 87 | else: |
| 88 | if 'is running' not in line: |
| 89 | errors.append(line) |
| 90 | break |
| 91 | assert not errors, 'k8s cluster info is not good: {}'.format(json.dumps( |
| 92 | errors, |
| 93 | indent=4)) |
| 94 | |
| 95 | |
| 96 | def test_k8s_kubelet_status(local_salt_client): |
| 97 | result = local_salt_client.cmd( |
| 98 | 'kubernetes:pool', 'service.status', |
| 99 | ['kubelet'], |
| 100 | expr_form='pillar' |
| 101 | ) |
| 102 | errors = [] |
| 103 | if not result: |
| 104 | pytest.skip("k8s is not found on this environment") |
| 105 | for node in result: |
| 106 | if not result[node]: |
| 107 | errors.append(node) |
| 108 | assert not errors, 'Kublete is not running on these nodes: {}'.format( |
| 109 | errors) |
| 110 | |
| 111 | |
Oleksii Zhurba | 3eb5801 | 2017-11-02 22:01:06 +0000 | [diff] [blame] | 112 | def test_k8s_check_system_pods_status(local_salt_client): |
| 113 | result = local_salt_client.cmd( |
| 114 | 'etcd:server', 'cmd.run', |
| 115 | ['kubectl --namespace="kube-system" get pods'], |
| 116 | expr_form='pillar' |
| 117 | ) |
| 118 | errors = [] |
| 119 | if not result: |
| 120 | pytest.skip("k8s is not found on this environment") |
| 121 | for node in result: |
| 122 | for line in result[node].split('\n'): |
| 123 | line = line.strip('|') |
| 124 | if 'STATUS' in line or 'proto' in line: |
| 125 | continue |
| 126 | else: |
| 127 | if 'Running' not in line: |
| 128 | errors.append(line) |
| 129 | break |
| 130 | assert not errors, 'Some system pods are not running: {}'.format(json.dumps( |
| 131 | errors, |
| 132 | indent=4)) |
| 133 | |
| 134 | |
| 135 | def test_check_k8s_image_availability(local_salt_client): |
Oleksii Zhurba | 943a093 | 2017-11-01 22:27:53 +0000 | [diff] [blame] | 136 | # not a test actually |
Oleksii Zhurba | 3eb5801 | 2017-11-02 22:01:06 +0000 | [diff] [blame] | 137 | hostname = 'https://docker-dev-virtual.docker.mirantis.net/artifactory/webapp/' |
| 138 | response = os.system('curl -s --insecure {} > /dev/null'.format(hostname)) |
Oleksii Zhurba | 943a093 | 2017-11-01 22:27:53 +0000 | [diff] [blame] | 139 | if response == 0: |
| 140 | print '{} is AVAILABLE'.format(hostname) |
| 141 | else: |
| 142 | print '{} IS NOT AVAILABLE'.format(hostname) |