1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
import subprocess
import os
import json
import requests
import sys
import csv
import re
class PaaSSetupCheck():
def run_test(self, site_name):
try:
network_ok = False
namespace_ok = False
network_unreachable = False
cc_unreachable = False
url = 'https://middleware.vcpfe.vzwops.com/orchestration/remote-regions/' + site_name + '/site-details'
network_setup_url = 'https://middleware.vcpfe.vzwops.com/orchestration/remote-regions/' + site_name + '/setup-network'
namespace_setup_url = 'https://middleware.vcpfe.vzwops.com/orchestration/setup-cluster/' + site_name
#url = 'http://middleware.meter.vzwops.com:3080/orchestration/remote-regions/' + site_name + '/site-details'
#network_setup_url = 'http://middleware.meter.vzwops.com:3080/orchestration/remote-regions/' + site_name + '/setup-network'
#namespace_setup_url = 'http://middleware.meter.vzwops.com:3080/orchestration/setup-cluster/' + site_name
#namespace_setup_url_1 = 'https://middleware.vcpfe.vzwops.com/orchestration/setup-cluster/' + site_name + '?network_setup=false'
#url = 'http://localhost:8000/orchestration/remote-regions/' + site_name + '/site-details'
#network_setup_url = 'http://localhost:8000/orchestration/remote-regions/' + site_name + '/setup-network'
#namespace_setup_url = 'http://localhost:8000/orchestration/setup-cluster/' + site_name
auth = ('SVC-Far-Edge','QxbV44IU4P7t7rN44dxK4xyPB');
resp = requests.get(url, auth=auth, verify=False)
if resp.status_code == 500:
network_unreachable = True
print(site_name + ' ssh network unreachable')
else:
print(resp.json())
cc_status = resp.json()['setup_details']['online_status']
if not cc_status:
cc_unreachable = True
else:
namespaces = resp.json()['setup_details']['namespaces']
for namespace in namespaces:
print('namespace: ' + namespace)
if 'Unable to connect to the server' in namespace:
network_unreachable = True
print(site_name + ' k8s network unreachable')
break
else:
x = re.search("^wsbomagj-.*[0-9]$", namespace.split(' ')[0])
if x:
# check secrets
secrets = resp.json()['setup_details']['ns_secrets']
total_secrets = 0
for secret in secrets:
if 'admin-registry-secret' in secret:
total_secrets = total_secrets + 1
if 'ceph-pool-kube-rbd' in secret:
total_secrets = total_secrets + 1
if 'default-token' in secret:
total_secrets = total_secrets + 1
if 'vran-serviceaccount-token' in secret:
total_secrets = total_secrets + 1
if total_secrets == 4:
# check service accounts
total_sa = 0
serviceaccounts = resp.json()['setup_details']['ns_service_accounts']
for sa in serviceaccounts:
if 'default' in sa:
total_sa = total_sa + 1
if 'vran-serviceaccount' in sa:
total_sa = total_sa + 1
if total_sa == 2:
print(site_name + ': ' + namespace + ' namespace is created')
namespace_ok = True
if not network_unreachable and not cc_unreachable:
network_no = len(resp.json()['setup_details']['network_details'])
if network_no and network_no >= 15:
print(site_name + ' network setup succeeded')
network_ok = True;
if namespace_ok:
if network_ok:
print(site_name + " both namespace and network setup correct. yay.")
else:
print(site_name + ' namespace is okay, network setup failed.')
print('calling setup-network for: ' + site_name)
# call network_setup
network_setup_resp = requests.put(network_setup_url, auth=auth, verify=False)
else:
if network_ok:
print(site_name + " namespace setup failed, network okay.")
print('calling setup-cluster with network_setup=false query parameter.')
payload = {'network_setup': 'false'}
namespace_setup_resp = requests.get(namespace_setup_url, auth=auth, params=payload, verify=False)
else:
print(site_name + 'both namespace and network NOT setup')
namespace_setup_resp = requests.get(namespace_setup_url, auth=auth, verify=False)
print('called setup-cluster')
except Exception as e:
print(e)
return network_ok, namespace_ok, network_unreachable, cc_unreachable
if __name__ == '__main__':
if len(sys.argv) < 1:
print("Usage:")
print(" python paas-set-check.py <site_list_csv_file>")
exit(0)
site_list_file = sys.argv[1]
print("Input WR installed site list file:" + site_list_file)
paasSetupCheck = PaaSSetupCheck()
with open('network_setup_succeed.csv', mode='w') as succeed_file:
with open('network_setup_fail.csv', mode='w') as fail_file:
with open('namespace_setup_succeed.csv', mode='w') as namespace_succeed_file:
with open('namespace_setup_fail.csv', mode='w') as namespace_fail_file:
with open('network-namespace_setup_succeed.csv', mode='w') as network_namespace_succeed_file:
with open('network-unreachable.csv', mode='w') as network_unreachable_file:
with open('cc-unreachable.csv', mode='w') as cc_unreachable_file:
writer0 = csv.writer(succeed_file, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer1 = csv.writer(fail_file, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer2 = csv.writer(namespace_succeed_file, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer3 = csv.writer(namespace_fail_file, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer4 = csv.writer(network_namespace_succeed_file, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer5 = csv.writer(network_unreachable_file, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer6 = csv.writer(cc_unreachable_file, delimiter=' ', quotechar='"', quoting=csv.QUOTE_MINIMAL)
with open(site_list_file) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
ok_count = 0
bad_count = 0
network_ok_count = 0
network_not_ok_count = 0
namespace_ok_count = 0
namespace_not_ok_count= 0
cc_unreachable_count = 0
for row in csv_reader:
print(f'\t{row[0]}')
#site_name = 'wsbomagj-d325030-001';
site_name = row[0];
network_ok, namespace_ok, network_unreachable, cc_unreachable = paasSetupCheck.run_test(site_name)
print(network_ok, namespace_ok)
if network_ok and namespace_ok:
writer4.writerow({site_name})
ok_count += 1
if network_unreachable:
writer5.writerow({site_name})
bad_count += 1
if cc_unreachable:
writer6.writerow({site_name})
cc_unreachable_count += 1
if network_ok:
writer0.writerow({site_name})
network_ok_count += 1
elif not network_unreachable:
writer1.writerow({site_name})
network_not_ok_count += 1
print(site_name + ' network setup failed')
if namespace_ok:
writer2.writerow({site_name})
namespace_ok_count += 1
elif not network_unreachable:
writer3.writerow({site_name})
namespace_not_ok_count += 1
print(site_name + ' namespace setup failed')
line_count += 1
print(f'Processed {line_count} lines.')
print(f'{ok_count} of {line_count} ready-to-go sites. file: network-namespace_setup_succeed.csv')
print(f'{bad_count} of {line_count} bad sites. file: network-unreachable.csv')
print(f'{cc_unreachable_count} of {line_count} central controller unreachable sites. file: cc-unreachable.csv')
print(f'{network_ok_count} of {line_count} sites with no network problem. file: network_setup_succeed.csv')
print(f'{network_not_ok_count} of {line_count} sites with network problem. file: network_setup_fail.csv')
print(f'{namespace_ok_count} of {line_count} sites with no namespace problem. file:namespace_setup_succeed.csv')
print(f'{namespace_not_ok_count} of {line_count} sites with namespace problem. file: namespace_setup_fail.csv')
|