3
3
from random import choice
4
4
import copy
5
5
import json
6
+ import re
6
7
import six
7
8
import string
8
9
23
24
from wrapanapi .containers .deployment_config import DeploymentConfig
24
25
25
26
27
+ # stolen from sprout
28
+ VERSION_REGEXPS = [
29
+ r"^cfme-(\d)(\d)(\d)(\d)(\d{2})" , # 1.2.3.4.11
30
+ # newer format
31
+ r"cfme-(\d)(\d)(\d)[.](\d{2})-" , # cfme-524.02- -> 5.2.4.2
32
+ r"cfme-(\d)(\d)(\d)[.](\d{2})[.](\d)-" , # cfme-524.02.1- -> 5.2.4.2.1
33
+ # 4 digits
34
+ r"cfme-(?:nightly-)?(\d)(\d)(\d)(\d)-" , # cfme-5242- -> 5.2.4.2
35
+ r"cfme-(\d)(\d)(\d)-(\d)-" , # cfme-520-1- -> 5.2.0.1
36
+ # 5 digits (not very intelligent but no better solution so far)
37
+ r"cfme-(?:nightly-)?(\d)(\d)(\d)(\d{2})-" , # cfme-53111- -> 5.3.1.11, cfme-53101 -> 5.3.1.1
38
+ ]
39
+ VERSION_REGEXPS = map (re .compile , VERSION_REGEXPS )
40
+ VERSION_REGEXP_UPSTREAM = re .compile (r'^miq-stable-([^-]+)-' )
41
+
42
+
43
+ def retrieve_cfme_appliance_version (template_name ):
44
+ """If possible, retrieve the appliance's version from template's name."""
45
+ for regexp in VERSION_REGEXPS :
46
+ match = regexp .search (template_name )
47
+ if match is not None :
48
+ return "." .join (map (str , map (int , match .groups ())))
49
+ else :
50
+ match = VERSION_REGEXP_UPSTREAM .search (template_name )
51
+ if match is not None :
52
+ return match .groups ()[0 ]
53
+
54
+
26
55
# this service allows to access db outside of openshift
27
56
common_service = """
28
57
{
@@ -217,14 +246,22 @@ def deploy_template(self, template, tags=None, password='smartvm', **kwargs):
217
246
self .create_project (name = proj_name )
218
247
progress_callback ("Created Project `{}`" .format (proj_name ))
219
248
249
+ version = retrieve_cfme_appliance_version (template )
250
+
220
251
# grant rights according to scc
221
252
self .logger .info ("granting rights to project %s sa" , proj_name )
222
- scc_user_mapping = (
223
- {'scc' : 'anyuid' , 'user' : 'cfme-anyuid' },
224
- {'scc' : 'anyuid' , 'user' : 'cfme-orchestrator' },
225
- {'scc' : 'anyuid' , 'user' : 'cfme-httpd' },
226
- {'scc' : 'privileged' , 'user' : 'cfme-privileged' },
227
- )
253
+ if version >= '5.9' :
254
+ scc_user_mapping = (
255
+ {'scc' : 'anyuid' , 'user' : 'cfme-anyuid' },
256
+ {'scc' : 'anyuid' , 'user' : 'cfme-orchestrator' },
257
+ {'scc' : 'anyuid' , 'user' : 'cfme-httpd' },
258
+ {'scc' : 'privileged' , 'user' : 'cfme-privileged' },
259
+ )
260
+ else :
261
+ scc_user_mapping = (
262
+ {'scc' : 'anyuid' , 'user' : 'cfme-anyuid' },
263
+ {'scc' : 'privileged' , 'user' : 'default' },
264
+ )
228
265
229
266
self .logger .info ("granting required rights to project's service accounts" )
230
267
security_api = self .ociclient .SecurityOpenshiftIoV1Api ()
@@ -238,30 +275,31 @@ def deploy_template(self, template, tags=None, password='smartvm', **kwargs):
238
275
body = {'users' : got_users })
239
276
progress_callback ("Added service accounts to appropriate scc" )
240
277
241
- # grant roles to orchestrator
242
- self .logger .info ("assigning additional roles to cfme-orchestrator" )
243
- auth_api = self .ociclient .AuthorizationOpenshiftIoV1Api ()
244
- orchestrator_sa = self .kclient .V1ObjectReference (name = 'cfme-orchestrator' ,
245
- kind = 'ServiceAccount' ,
246
- namespace = proj_name )
247
-
248
- view_role = self .kclient .V1ObjectReference (name = 'view' )
249
- view_role_binding_name = self .kclient .V1ObjectMeta (name = 'view' )
250
- view_role_binding = self .ociclient .V1RoleBinding (role_ref = view_role ,
251
- subjects = [orchestrator_sa ],
252
- metadata = view_role_binding_name )
253
- self .logger .debug ("creating 'view' role binding "
254
- "for cfme-orchestrator sa in project %s" , proj_name )
255
- auth_api .create_namespaced_role_binding (namespace = proj_name , body = view_role_binding )
256
-
257
- edit_role = self .kclient .V1ObjectReference (name = 'edit' )
258
- edit_role_binding_name = self .kclient .V1ObjectMeta (name = 'edit' )
259
- edit_role_binding = self .ociclient .V1RoleBinding (role_ref = edit_role ,
260
- subjects = [orchestrator_sa ],
261
- metadata = edit_role_binding_name )
262
- self .logger .debug ("creating 'edit' role binding "
263
- "for cfme-orchestrator sa in project %s" , proj_name )
264
- auth_api .create_namespaced_role_binding (namespace = proj_name , body = edit_role_binding )
278
+ if version >= '5.9' :
279
+ # grant roles to orchestrator
280
+ self .logger .info ("assigning additional roles to cfme-orchestrator" )
281
+ auth_api = self .ociclient .AuthorizationOpenshiftIoV1Api ()
282
+ orchestrator_sa = self .kclient .V1ObjectReference (name = 'cfme-orchestrator' ,
283
+ kind = 'ServiceAccount' ,
284
+ namespace = proj_name )
285
+
286
+ view_role = self .kclient .V1ObjectReference (name = 'view' )
287
+ view_role_binding_name = self .kclient .V1ObjectMeta (name = 'view' )
288
+ view_role_binding = self .ociclient .V1RoleBinding (role_ref = view_role ,
289
+ subjects = [orchestrator_sa ],
290
+ metadata = view_role_binding_name )
291
+ self .logger .debug ("creating 'view' role binding "
292
+ "for cfme-orchestrator sa in project %s" , proj_name )
293
+ auth_api .create_namespaced_role_binding (namespace = proj_name , body = view_role_binding )
294
+
295
+ edit_role = self .kclient .V1ObjectReference (name = 'edit' )
296
+ edit_role_binding_name = self .kclient .V1ObjectMeta (name = 'edit' )
297
+ edit_role_binding = self .ociclient .V1RoleBinding (role_ref = edit_role ,
298
+ subjects = [orchestrator_sa ],
299
+ metadata = edit_role_binding_name )
300
+ self .logger .debug ("creating 'edit' role binding "
301
+ "for cfme-orchestrator sa in project %s" , proj_name )
302
+ auth_api .create_namespaced_role_binding (namespace = proj_name , body = edit_role_binding )
265
303
266
304
self .logger .info ("project sa created via api have no some mandatory roles. adding them" )
267
305
self ._restore_missing_project_role_bindings (namespace = proj_name )
@@ -436,7 +474,7 @@ def rename_structure(self, struct):
436
474
if key == 'stringData' :
437
475
# this key has to be renamed but its contents should be left intact
438
476
struct [inflection .underscore (key )] = struct .pop (key )
439
- elif key in ('spec' , 'data' , 'string_data' ):
477
+ elif key in ('spec' , 'data' , 'string_data' , 'annotations' ):
440
478
# these keys and data should be left intact
441
479
pass
442
480
else :
@@ -884,13 +922,20 @@ def is_vm_running(self, vm_name):
884
922
"""Emulates check is vm(appliance) up and running
885
923
886
924
Args:
887
- vm_name: project(namespace) name
925
+ vm_name: (str) project(namespace) name
888
926
Return: True/False
889
927
"""
890
928
if not self .does_vm_exist (vm_name ):
891
929
return False
892
930
self .logger .info ("checking all pod statuses for vm name %s" , vm_name )
893
- for pod_name in self .required_project_pods :
931
+ version = retrieve_cfme_appliance_version (vm_name )
932
+
933
+ if version >= '5.9' :
934
+ pods_to_check = self .required_project_pods
935
+ else :
936
+ pods_to_check = self .required_project_pods58
937
+
938
+ for pod_name in pods_to_check :
894
939
if self .is_deployment_config (name = pod_name , namespace = vm_name ):
895
940
dc = self .o_api .read_namespaced_deployment_config (name = pod_name , namespace = vm_name )
896
941
status = dc .status .ready_replicas
0 commit comments