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