1- # Copyright 2015-2016 F5 Networks Inc.
1+ # Copyright 2019 F5 Networks Inc.
22#
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
@@ -93,6 +93,36 @@ def skip_module_missing(request, modules, opt_bigip, opt_username, opt_password,
9393}
9494
9595
96+ iapp_templ_data_subpath_v11 = {
97+ "name" : "test_templ_subpath" ,
98+ "partition" : "Common" ,
99+ "actions" : {
100+ "definition" :
101+ {
102+ "implementation" : '''tmsh::create { net vlan v102 }
103+ tmsh::create { net self self.v102 address 192.168.1.5/24 vlan v102 }
104+ tmsh::create { gtm datacenter dc1 }
105+ tmsh::create { auth partition part1 }
106+ tmsh::cd { /part1 }
107+ tmsh::create { ltm virtual v1 destination 192.168.1.100:80 }
108+ tmsh::cd { /Common }
109+ tmsh::create { gtm server ltm11 addresses add { 192.168.1.5 } datacenter dc1
110+ virtual-servers replace-all-with { /part1/v1 { destination 192.168.1.100:80 } } }
111+ tmsh::cd { /part1 }
112+ tmsh::create { gtm pool p1 members replace-all-with { /Common/ltm11:/part1/v1 } }''' ,
113+ "presentation" : ""
114+ }
115+ }
116+ }
117+
118+
119+ iapp_serv_data_subpath = {
120+ "name" : "test_serv_subpath" ,
121+ "partition" : "Common" ,
122+ "template" : "/Common/test_templ_subpath"
123+ }
124+
125+
96126@pytest .fixture
97127def setup_subpath (request , ICR , BASE_URL ):
98128 app_templ_url = BASE_URL + 'sys/application/template/'
@@ -127,6 +157,40 @@ def teardown_iapp():
127157 return app_serv_url
128158
129159
160+ @pytest .fixture
161+ def setup_subpath_alt (request , ICR , BASE_URL ):
162+ app_templ_url = BASE_URL + 'sys/application/template/'
163+ app_serv_url = BASE_URL + 'sys/application/service/'
164+
165+ def teardown_iapp ():
166+ try :
167+ ICR .delete (
168+ app_serv_url , uri_as_parts = True ,
169+ name = 'test_serv_subpath' , partition = 'Common' ,
170+ subPath = 'test_serv_subpath.app' )
171+ except Exception :
172+ pass
173+
174+ try :
175+ ICR .delete (
176+ app_templ_url , uri_as_parts = True ,
177+ name = 'test_templ_subpath' , partition = 'Common' )
178+ except Exception :
179+ pass
180+
181+ teardown_iapp ()
182+ ICR .post (app_templ_url , json = iapp_templ_data_subpath_v11 )
183+ try :
184+ ICR .post (app_serv_url , json = iapp_serv_data_subpath )
185+ except HTTPError as ex :
186+ # The creation of an iapp service does cause a 404 error in bigip
187+ # versions up to but excluding 12.0
188+ if ex .response .status_code == 404 :
189+ pass
190+ request .addfinalizer (teardown_iapp )
191+ return app_serv_url
192+
193+
130194def teardown_nat (request , icr , url , name , partition ):
131195 '''Remove the nat object that we create during a test '''
132196 def teardown ():
@@ -165,7 +229,7 @@ def invalid_token_credentials(user, password, url):
165229 with pytest .raises (HTTPError ) as err :
166230 icr .get (url )
167231 return (err .value .response .status_code == 401 and
168- 'Authentication required!' in err .value . message )
232+ 'Authentication required!' in str ( err .value ) )
169233
170234
171235def test_get_with_subpath (setup_subpath , ICR , BASE_URL ):
@@ -185,6 +249,25 @@ def test_get_with_subpath(setup_subpath, ICR, BASE_URL):
185249 assert data ['items' ][0 ]['name' ] == 'test_pool'
186250
187251
252+ @pytest .mark .skipif (
253+ LooseVersion (pytest .config .getoption ('--release' )) >= LooseVersion (
254+ '12.0.0' ),
255+ reason = 'No GTM Pool type, introduced in 12.0+'
256+ )
257+ def test_get_with_subpath_transform (setup_subpath_alt , ICR , BASE_URL ):
258+ app_serv_url = setup_subpath_alt
259+ res = ICR .get (
260+ app_serv_url , name = 'test_serv_subpath' ,
261+ partition = 'Common' , subPath = 'test_serv_subpath.app' )
262+ assert res .status_code == 200
263+ pool_uri = BASE_URL + 'gtm/pool/~part1~p1/members/'
264+ poolmem_res = ICR .get (pool_uri , name = 'v1' , partition = 'Common' , subPath = 'ltm11:/part1' )
265+ assert poolmem_res .status_code == 200
266+ data = poolmem_res .json ()
267+ assert data ['items' ][0 ]['name' ] == 'v1'
268+ assert data ['items' ][0 ]['subPath' ] == 'ltm11:/part1'
269+
270+
188271def test_get (ICR , GET_URL ):
189272 '''Test a GET request to a valid url
190273
0 commit comments