/
test_values_nested_quotas.py
343 lines (317 loc) · 14.3 KB
/
test_values_nested_quotas.py
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
import utils
import sqlalchemy
import sys
def tear_down(token, projects, domain):
for project_id in projects:
utils.disable_project(token, project_id)
utils.delete_project(token, project_id)
utils.disable_domain(token, domain)
utils.delete_domain(token, domain)
def main():
f = open('log_test_values_cider.txt', 'w')
original = sys.stdout
sys.stdout = utils.Tee(sys.stdout, f)
token = 0
domain_id, production_project_id, cms_project_id, atlas_project_id = (0, )*4
computing_project_id, visualisation_project_id, services_project_id = (0, )*3
operations_project_id = 0
try:
token_json = utils.default_token_json('admin', 'demo')
token = utils.get_token(token_json)
print '======================================================================='
print 'This script will use the follow hierarchy to validate the quota values'
print 'related to Nested Quotas on Cinder'
print '======================================================================='
print 'Hierarchy:'
print ' Domain_X '
print ' |'
print ' ProductionIT - Mike'
print ' / \ '
print ' Jay - CMS ATLAS - John'
print ' / \ / \ '
print ' Computing Visualisation Operations Services '
print ' Walter Duncan Eric Xing'
print ''
print 'Actors:'
print ''
print 'Mike - Cloud Admin (i.e. role:cloud-admin) of ProductionIT'
print 'Jay - Manager (i.e. role: project-admin) of Project CMS'
print 'John - Manager (i.e. role: project-admin) of Project ATLAS'
print 'Eric - Manager (i.e. role: project-admin) of Project Operations'
print 'Xing - Manager (i.e. role: project-admin) of Project Services'
print 'Walter - Manager (i.e. role: project-admin) of Project Computing'
print 'Duncan - Manager (i.e. role: project-admin) of Project Visualisation'
print '======================================================================='
# Create a new domain
print 'Creating the domain...'
domain = utils.domain_json()
domain_id = utils.create_domain(domain, token)
print 'Domain created: %s' % domain_id
print '======================================================================='
print 'Creating the projects...'
# Create project ProductionIT
production_project_json = utils.project_json('ProductionIT', domain_id)
production_project_id = utils.create_project(production_project_json,
token)
print "ProductionIT created: %s" % production_project_id
print '======================================================================='
# Create Project CMS
cms_project_json = utils.project_json('CMS', domain_id,
production_project_id)
cms_project_id = utils.create_project(cms_project_json, token)
print "CMS created: %s" % cms_project_id
print '======================================================================='
# Create Project Atlas
atlas_project_json = utils.project_json('ATLAS',
domain_id,
production_project_id)
atlas_project_id = utils.create_project(atlas_project_json, token)
print "ATLAS created: %s" % atlas_project_id
print '======================================================================='
# Create Project computing
computing_project_json = utils.project_json('computing',
domain_id,
cms_project_id)
computing_project_id = utils.create_project(computing_project_json,
token)
print "Computing created: %s" % computing_project_id
print '======================================================================='
# Create Project visualisation
visual_project_json = utils.project_json('visualisation',
domain_id,
cms_project_id)
visualisation_project_id = utils.create_project(visual_project_json,
token)
print "Visualisation created: %s" % visualisation_project_id
print '======================================================================='
# Create Project services
services_project_json = utils.project_json('services',
domain_id,
atlas_project_id)
services_project_id = utils.create_project(services_project_json,
token)
print "Services created: %s" % services_project_id
print '======================================================================='
# Create Project operations
operations_project_json = utils.project_json('operations',
domain_id,
atlas_project_id)
operations_project_id = utils.create_project(operations_project_json,
token)
print "Operations created: %s" % operations_project_id
print '======================================================================='
admin_role = utils.get_role(token, 'admin')
# Creating users
# Creating and grant admin role to mike in production
print 'Creating the users...'
mike = utils.create_user(token, 'Mike', domain_id)
print "Mike: %s" % mike
utils.grant_user_role(token, mike,
admin_role, [production_project_id])
print '======================================================================='
# Creating and grant admin role to jay in cms
jay = utils.create_user(token, 'Jay', domain_id)
print "Jay: %s" % jay
utils.grant_user_role(token, jay,
admin_role, [cms_project_id])
print '======================================================================='
# Creating and grant admin role to john in atlas
john = utils.create_user(token, 'John', domain_id)
print "John: %s" % john
utils.grant_user_role(token, john,
admin_role, [atlas_project_id])
print '======================================================================='
# Creating and grant admin role to eric in operations
eric = utils.create_user(token, 'Eric', domain_id)
print "Eric: %s" % eric
utils.grant_user_role(token, eric,
admin_role, [operations_project_id])
print '======================================================================='
# Creating and grant admin role to xing in services
xing = utils.create_user(token, 'Xing', domain_id)
print "Xing: %s" % xing
utils.grant_user_role(token, xing,
admin_role, [services_project_id])
print '======================================================================='
# Creating and grant admin role to walter in computing
walter = utils.create_user(token, 'Walter', domain_id)
print "Walter: %s" % walter
utils.grant_user_role(token, walter,
admin_role, [computing_project_id])
print '======================================================================='
# Creating and grant admin role to duncan in visualisation
duncan = utils.create_user(token, 'Duncan', domain_id)
print "Ducnan: %s" % duncan
utils.grant_user_role(token, duncan,
admin_role, [visualisation_project_id])
print '======================================================================='
print 'Now, we will get a token for Mike in ProductionIT (root project)'
print 'and show that the quota calculation in the hierarchy works well.'
print '======================================================================='
# Get a token for Mike in ProductionIT
mike_token_json = utils.get_token_json('Mike',
production_project_id)
mike_token = utils.get_token(mike_token_json)
print 'Token for mike: %s' % mike_token
print '======================================================================='
# Update the Prduction Quota to 100
print 'Updating the ProductionIT quota for 100...'
quota_value = 100
production_quota = utils.update_quota(mike_token,
production_project_id,
production_project_id,
quota_value)
quota_show_production = utils.quota_show(mike_token,
production_project_id,
production_project_id)
print '======================================================================='
print "Production Quota: %s" % quota_show_production
print '======================================================================='
# Update the CMS Quota to 40
print 'Updating the CMS quota for 40...'
quota_value = 40
cms_quota = utils.update_quota(mike_token,
production_project_id,
cms_project_id,
quota_value)
quota_show_production = utils.quota_show(mike_token,
production_project_id,
production_project_id)
quota_show_cms = utils.quota_show(mike_token, production_project_id, cms_project_id)
print 'Verify that allocated ProductionIT quota was updated to 40'
print "Production Quota: %s" % quota_show_production
print "CMS Quota: %s" % quota_show_cms
print '======================================================================='
# Update the Atlas Quota to 30
print 'Updating the Atlas quota for 30...'
quota_value = 30
atlas_quota = utils.update_quota(mike_token,
production_project_id,
atlas_project_id,
quota_value)
quota_show_production = utils.quota_show(mike_token,
production_project_id,
production_project_id)
quota_show_atlas = utils.quota_show(mike_token,
production_project_id,
atlas_project_id)
print 'Verify that allocated ProductionIT quota was updated to 70'
print "Production Quota: %s" % quota_show_production
print "Atlas Quota: %s" % quota_show_atlas
print '======================================================================='
# Update the Computing Quota to 15
print 'Updating the Computing quota for 15...'
quota_value = 15
computing_quota = utils.update_quota(mike_token,
production_project_id,
computing_project_id,
quota_value)
quota_show_cms = utils.quota_show(mike_token,
production_project_id,
cms_project_id)
quota_show_computing = utils.quota_show(mike_token,
production_project_id,
computing_project_id)
print 'Verify that allocated CMS quota was updated to 15'
print "CMS Quota: %s" % quota_show_cms
print "Computing Quota: %s" % quota_show_computing
print '======================================================================='
# Update the visualisaton Quota to 15
print 'Updating the Visualisation quota for 15...'
quota_value = 15
visualisation_quota = utils.update_quota(mike_token,
production_project_id,
visualisation_project_id,
quota_value)
quota_show_cms = utils.quota_show(mike_token,
production_project_id,
cms_project_id)
quota_show_visualisation = utils.quota_show(mike_token,
production_project_id,
visualisation_project_id)
print 'Verify that allocated CMS quota was updated to 30'
print "CMS Quota: %s" % quota_show_cms
print "Visualisation Quota: %s" % quota_show_visualisation
print '======================================================================='
print 'Updating the Services quota for 10...'
# Update the services Quota to 10
quota_value = 10
services_quota = utils.update_quota(mike_token,
production_project_id,
services_project_id,
quota_value)
quota_show_atlas = utils.quota_show(mike_token,
production_project_id,
atlas_project_id)
quota_show_services = utils.quota_show(mike_token,
production_project_id,
services_project_id)
print 'Verify that allocated Atlas quota was updated to 10'
print "Atlas Quota: %s" % quota_show_atlas
print "Service Quota: %s" % quota_show_services
print '======================================================================='
# Update the operations Quota to 10
quota_value = 10
operations_quota = utils.update_quota(mike_token,
production_project_id,
operations_project_id,
quota_value)
quota_show_atlas = utils.quota_show(mike_token,
production_project_id,
atlas_project_id)
quota_show_operations = utils.quota_show(mike_token,
production_project_id,
operations_project_id)
print 'Verify that allocated Atlas quota was updated to 20'
print "Atlas Quota: %s" % quota_show_atlas
print "Operations Quota: %s" % quota_show_operations
print '======================================================================='
# Update the CMS Quota to 40
quota_value = 71
print 'Trying update the CMS quota for 71...'
cms_quota = utils.update_quota(mike_token,
production_project_id,
cms_project_id,
quota_value)
print "Error: %s" % cms_quota
print '======================================================================='
print "Creating 10 Volumes in CMS..."
# Get a token for Jay in CMS
jay_token_json = utils.get_token_json('Jay', cms_project_id)
jay_token = utils.get_token(jay_token_json)
for i in range(0,10):
utils.create_volume(jay_token, cms_project_id)
quota_show_cms = utils.quota_show(jay_token, cms_project_id, cms_project_id)
print "CMS Quota: %s" % quota_show_cms
print 'Now, we dont have free quota in CMS'
print '======================================================================='
print "Trying update the computing quota to 16 (subproject for CMS)..."
quota_value = 16
computing_quota = utils.update_quota(mike_token,
production_project_id,
computing_project_id,
quota_value)
print "Error: %s" % computing_quota
print '======================================================================='
print 'Clean up...'
except Exception as e:
print 'Error'
tear_down(token, [production_project_id,
cms_project_id,
atlas_project_id,
computing_project_id,
visualisation_project_id,
services_project_id,
operations_project_id], domain_id)
f.close()
print e
tear_down(token, [production_project_id,
cms_project_id,
atlas_project_id,
computing_project_id,
visualisation_project_id,
services_project_id,
operations_project_id], domain_id)
f.close()
if __name__ == "__main__":
main()