blob: f0cfd44b9d879c339e74f299168b9a02d3d2a41a [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
29def 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 Zhurba943a0932017-11-01 22:27:53 +000041 if 'STATUS' in line or 'proto' in line:
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000042 continue
43 else:
44 if 'Ready' not in line:
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000045 errors.append(line)
Oleksii Zhurba11de14e2017-10-23 19:13:00 +000046 break
47 assert not errors, 'k8s is not healthy: {}'.format(json.dumps(
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000048 errors,
49 indent=4))
Oleksii Zhurba943a0932017-11-01 22:27:53 +000050
51
52def 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
74def 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
96def 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 Zhurba3eb58012017-11-02 22:01:06 +0000112def 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
135def test_check_k8s_image_availability(local_salt_client):
Oleksii Zhurba943a0932017-11-01 22:27:53 +0000136 # not a test actually
Oleksii Zhurba3eb58012017-11-02 22:01:06 +0000137 hostname = 'https://docker-dev-virtual.docker.mirantis.net/artifactory/webapp/'
138 response = os.system('curl -s --insecure {} > /dev/null'.format(hostname))
Oleksii Zhurba943a0932017-11-01 22:27:53 +0000139 if response == 0:
140 print '{} is AVAILABLE'.format(hostname)
141 else:
142 print '{} IS NOT AVAILABLE'.format(hostname)