blob: ebfbfe323fc04478127c0482f2cb0b5e06538fb4 [file] [log] [blame]
Oleksii Zhurba11de14e2017-10-23 19:13:00 +00001import pytest
2import json
Oleksii Zhurba943a0932017-11-01 22:27:53 +00003import os
Oleksii Zhurba11de14e2017-10-23 19:13:00 +00004
Oleksii Zhurba3dbed242017-10-31 19:58:53 +00005
Oleksii Zhurba11de14e2017-10-23 19:13:00 +00006def 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 Zhurba943a0932017-11-01 22:27:53 +000018 if 'MESSAGE' in line or 'proto' in line:
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000019 continue
20 else:
21 if 'Healthy' not in line:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000022 errors.append(line)
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000023 break
24 assert not errors, 'k8s is not healthy: {}'.format(json.dumps(
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000025 errors,
26 indent=4))
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000027
28
Hanna Arhipovaa3c6a852019-03-28 09:30:20 +020029@pytest.mark.xfail
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000030def 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 Zhurba943a0932017-11-01 22:27:53 +000042 if 'STATUS' in line or 'proto' in line:
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000043 continue
44 else:
Oleksii Zhurbae592ed12018-06-21 18:01:09 -050045 if 'Ready' != line.split()[1]:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000046 errors.append(line)
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000047 break
48 assert not errors, 'k8s is not healthy: {}'.format(json.dumps(
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000049 errors,
50 indent=4))
Oleksii Zhurba943a0932017-11-01 22:27:53 +000051
52
53def 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
75def test_k8s_cluster_status(local_salt_client):
76 result = local_salt_client.cmd(
Hanna Arhipova0225bf12019-01-17 17:40:40 +020077 'kubernetes:master', 'cmd.run',
Oleksii Zhurba943a0932017-11-01 22:27:53 +000078 ['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
97def 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 Zhurba3eb58012017-11-02 22:01:06 +0000113def 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
136def test_check_k8s_image_availability(local_salt_client):
Oleksii Zhurba943a0932017-11-01 22:27:53 +0000137 # not a test actually
Oleksii Zhurba3eb58012017-11-02 22:01:06 +0000138 hostname = 'https://docker-dev-virtual.docker.mirantis.net/artifactory/webapp/'
139 response = os.system('curl -s --insecure {} > /dev/null'.format(hostname))
Oleksii Zhurba943a0932017-11-01 22:27:53 +0000140 if response == 0:
141 print '{} is AVAILABLE'.format(hostname)
142 else:
143 print '{} IS NOT AVAILABLE'.format(hostname)