1313# limitations under the License.
1414#
1515
16+ from f5 .bigip .resource import MissingRequiredCreationParameter
17+ from f5 .bigip .resource import MissingRequiredReadParameter
18+
1619from distutils .version import LooseVersion
1720from pprint import pprint as pp
1821import pytest
@@ -25,19 +28,23 @@ def delete_resource(resources):
2528 resource .delete ()
2629
2730
28- def setup_virtual_test (request , bigip , partition , name ):
31+ def setup_virtual_test (request , mgmt_root , partition , name ):
2932 def teardown ():
3033 delete_resource (vc1 )
3134 request .addfinalizer (teardown )
32- vc1 = bigip .ltm .virtuals
35+ vc1 = mgmt_root . tm .ltm .virtuals
3336 pp ('****' )
3437 virtual1 = vc1 .virtual .create (name = name , partition = partition )
3538 return virtual1 , vc1
3639
3740
3841class TestVirtual (object ):
39- def test_virtual_create_refresh_update_delete_load (self , request , bigip ):
40- virtual1 , vc1 = setup_virtual_test (request , bigip , 'Common' , 'vstest1' )
42+ def test_virtual_create_refresh_update_delete_load (
43+ self , request , mgmt_root , setup_device_snapshot
44+ ):
45+ virtual1 , vc1 = setup_virtual_test (
46+ request , mgmt_root , 'Common' , 'vstest1'
47+ )
4148 assert virtual1 .name == 'vstest1'
4249 virtual1 .description = TESTDESCRIPTION
4350 virtual1 .update ()
@@ -49,19 +56,20 @@ def test_virtual_create_refresh_update_delete_load(self, request, bigip):
4956 assert virtual2 .selfLink == virtual1 .selfLink
5057
5158
52- @pytest .mark .skipif (LooseVersion (pytest .config .getoption ('--release' )) <
53- LooseVersion ('11.6.0' ),
54- reason = 'This test fails in 11.5.4. Will '
55- 'revert this change in next PR.'
56- )
57- def test_profiles_CE (bigip , opt_release ):
58- v1 = bigip .ltm .virtuals .virtual .create (name = "tv1" , partition = "Common" )
59+ @pytest .mark .skipif (
60+ LooseVersion (pytest .config .getoption ('--release' ))
61+ < LooseVersion ('11.6.0' ),
62+ reason = 'Profiles do not need a partition in 11.6.0 and up.'
63+ )
64+ def test_profiles_CE_and_greater (
65+ mgmt_root , opt_release , setup_device_snapshot
66+ ):
67+ v1 = mgmt_root .tm .ltm .virtuals .virtual .create (
68+ name = "tv1" , partition = "Common"
69+ )
5970 p1 = v1 .profiles_s .profiles .create (name = "http" )
60- pp (p1 .raw )
6171 test_profiles_s = v1 .profiles_s
62- pp (test_profiles_s .raw )
6372 test_profiles_s .context = 'all'
64- pp (test_profiles_s .raw )
6573 assert p1 .selfLink == \
6674 u"https://localhost/mgmt/tm/ltm/virtual/" \
6775 "~Common~tv1/profiles/http?ver=" + opt_release
@@ -70,3 +78,39 @@ def test_profiles_CE(bigip, opt_release):
7078 assert p2 .exists (name = 'http' )
7179
7280 v1 .delete ()
81+
82+
83+ @pytest .mark .skipif (
84+ LooseVersion (pytest .config .getoption ('--release' ))
85+ >= LooseVersion ('11.6.0' ),
86+ reason = 'Profiles are created with a partition in 11.5.4.'
87+ )
88+ def test_profiles_CE_11_5_4_and_less (
89+ mgmt_root , opt_release , setup_device_snapshot
90+ ):
91+ v1 = mgmt_root .tm .ltm .virtuals .virtual .create (
92+ name = "tv2" , partition = "Common"
93+ )
94+ # Ensure we cannot create a profile without partition in 11.5.4
95+ with pytest .raises (MissingRequiredCreationParameter ) as ex :
96+ v1 .profiles_s .profiles .create (name = "http" )
97+ assert "Missing required params: ['partition']" in ex .value .message
98+
99+ # Create the profile with the partition given
100+ p1 = v1 .profiles_s .profiles .create (name = "http" , partition = "Common" )
101+ test_profiles_s = v1 .profiles_s
102+ test_profiles_s .context = 'all'
103+ assert p1 .selfLink == \
104+ u"https://localhost/mgmt/tm/ltm/virtual/" \
105+ "~Common~tv2/profiles/~Common~http?ver=" + opt_release
106+
107+ p2 = v1 .profiles_s .profiles
108+ # Ensure we cannot check for existence without partition in 11.5.4
109+ with pytest .raises (MissingRequiredReadParameter ) as ex :
110+ assert p2 .exists (name = 'http' )
111+ assert "Missing required params: ['partition']" in ex .value .message
112+
113+ # Check for existence with partition given
114+ p2 .exists (name = 'http' , partition = 'Common' )
115+
116+ v1 .delete ()
0 commit comments