@@ -55,6 +55,26 @@ def file_read():
5555 return result
5656
5757
58+ def remove_policies (mgmt_root , policy = None ):
59+ policies = mgmt_root .tm .asm .policies_s .get_collection ()
60+ if policy is None :
61+ resources = policies
62+ else :
63+ resources = [p for p in policies if p .name == policy ]
64+ for resource in resources :
65+ resource .delete ()
66+
67+
68+ @pytest .fixture (scope = 'function' )
69+ def partition (mgmt_root ):
70+ file = tempfile .NamedTemporaryFile ()
71+ name = os .path .basename (file .name )
72+ partitions = mgmt_root .tm .auth .partitions .partition
73+ local = partitions .create (name = name )
74+ yield local
75+ local .delete ()
76+
77+
5878@pytest .fixture (scope = 'function' )
5979def check_sig (mgmt_root ):
6080 task = mgmt_root .tm .asm .tasks .check_signatures_s .check_signature .fetch ()
@@ -221,6 +241,43 @@ def import_policy(mgmt_root):
221241 task .delete ()
222242
223243
244+ @pytest .fixture (scope = 'function' )
245+ def import_partitioned_policy (mgmt_root , partition ):
246+ content = file_read ()
247+ file = tempfile .NamedTemporaryFile ()
248+ name = os .path .basename (file .name )
249+ task = mgmt_root .tm .asm .tasks .import_policy_s .import_policy .create (
250+ file = content ,
251+ fullPath = '/{0}/{1}' .format (partition .name , name )
252+ )
253+ while True :
254+ task .refresh ()
255+ if task .status in ['COMPLETED' , 'FAILURE' ]:
256+ break
257+ time .sleep (1 )
258+ yield task
259+ task .delete ()
260+
261+
262+ @pytest .fixture (scope = 'function' )
263+ def import_partitioned_policy2 (mgmt_root , partition ):
264+ content = file_read ()
265+ file = tempfile .NamedTemporaryFile ()
266+ name = os .path .basename (file .name )
267+ task = mgmt_root .tm .asm .tasks .import_policy_s .import_policy .create (
268+ file = content ,
269+ name = name ,
270+ partition = partition .name
271+ )
272+ while True :
273+ task .refresh ()
274+ if task .status in ['COMPLETED' , 'FAILURE' ]:
275+ break
276+ time .sleep (1 )
277+ yield task
278+ task .delete ()
279+
280+
224281@pytest .fixture (scope = 'function' )
225282def import_vuln (mgmt_root , set_policy ):
226283 reference = {'link' : set_policy }
@@ -423,6 +480,26 @@ def test_create_import_template(self, import_policy_template):
423480 assert imp1 .kind == 'tm:asm:tasks:import-policy:import-policy-taskstate'
424481 assert imp1 .isBase64 is False
425482
483+ def test_create_import_partitioned (self , mgmt_root , import_partitioned_policy ):
484+ imp1 = import_partitioned_policy
485+ endpoint = str (imp1 .id )
486+ base_uri = 'https://localhost/mgmt/tm/asm/tasks/import-policy/'
487+ final_uri = base_uri + endpoint
488+ assert imp1 .selfLink .startswith (final_uri )
489+ assert imp1 .kind == 'tm:asm:tasks:import-policy:import-policy-taskstate'
490+ assert imp1 .isBase64 is False
491+ remove_policies (mgmt_root , os .path .basename (imp1 .fullPath ))
492+
493+ def test_create_import_partitioned2 (self , mgmt_root , import_partitioned_policy2 ):
494+ imp1 = import_partitioned_policy2
495+ endpoint = str (imp1 .id )
496+ base_uri = 'https://localhost/mgmt/tm/asm/tasks/import-policy/'
497+ final_uri = base_uri + endpoint
498+ assert imp1 .selfLink .startswith (final_uri )
499+ assert imp1 .kind == 'tm:asm:tasks:import-policy:import-policy-taskstate'
500+ assert imp1 .isBase64 is False
501+ remove_policies (mgmt_root , os .path .basename (imp1 .fullPath ))
502+
426503 def test_create_import_fails (self , import_policy_base64 ):
427504 imp1 = import_policy_base64
428505 endpoint = str (imp1 .id )
0 commit comments