Skip to content

Commit da6397e

Browse files
author
Paul Breaux
committed
Addressing code review comments from @zancas. Overriding _check_load_parameters and _check_create_parameters to raise if we see partition as a parameter to either load or create.
1 parent f1b09be commit da6397e

4 files changed

Lines changed: 73 additions & 7 deletions

File tree

f5/bigip/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from f5.bigip.tm.sys import Sys
3636
from f5.bigip.tm import Tm
3737
from f5.bigip.tm.transaction import Transactions
38-
from f5.bigip.tm.vcmp import Vcmp
3938

4039

4140
class ManagementRoot(PathElement):
@@ -90,10 +89,15 @@ def _get_tmos_version(self):
9089
class BigIP(ManagementRoot):
9190
"""A shim class used to access the default config resources in 'mgmt/tm.'
9291
92+
PLEASE DO NOT ADD ATTRIBUTES TO THIS CLASS.
93+
94+
This class is depcrated in favor of MangementRoot above. Do not add any
95+
more objects to the allowed_lazy_attributes list here!
96+
9397
This class is solely implemented for backwards compatibility.
9498
"""
9599
def __init__(self, hostname, username, password, **kwargs):
96100
super(BigIP, self).__init__(hostname, username, password, **kwargs)
97101
self._meta_data['uri'] = self._meta_data['uri'] + 'tm/'
98102
self._meta_data['allowed_lazy_attributes'] =\
99-
[TmAuth, TmCm, Ltm, Gtm, Net, TmShared, Sys, Transactions, Vcmp]
103+
[TmAuth, TmCm, Ltm, Gtm, Net, TmShared, Sys, Transactions]

f5/bigip/tm/vcmp/guest.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929

3030
from f5.bigip.resource import Collection
3131
from f5.bigip.resource import Resource
32+
from f5.sdk_exception import F5SDKError
33+
34+
35+
class DisallowedCreationParameter(F5SDKError):
36+
"""Exception when partition is passed to create for guest resource."""
37+
pass
38+
39+
40+
class DisallowedReadParameter(F5SDKError):
41+
"""Exception when partition is passed to load for guest resource."""
42+
pass
3243

3344

3445
class Guests(Collection):
@@ -48,3 +59,33 @@ def __init__(self, guests):
4859
super(Guest, self).__init__(guests)
4960
self._meta_data['required_json_kind'] =\
5061
'tm:vcmp:guest:gueststate'
62+
63+
def _check_load_parameters(self, **kwargs):
64+
"""Override method for one in resource.py to check partition
65+
66+
The partition cannot be included as a parameter to load a guest.
67+
Raise an exception if a consumer gives the partition.
68+
69+
:raises: DisallowedReadParameter
70+
"""
71+
72+
if 'partition' in kwargs:
73+
msg = "'partition' is not allowed as a load parameter. Vcmp " \
74+
"guests are accessed by name."
75+
raise DisallowedReadParameter(msg)
76+
super(Guest, self)._check_load_parameters(**kwargs)
77+
78+
def _check_create_parameters(self, **kwargs):
79+
"""Override method for one in resource.py to check partition
80+
81+
The partition cannot be included as a parameter to create a guest.
82+
Raise an exception if a consumer gives the partition.
83+
84+
:raises: DisallowedCreationParameter
85+
"""
86+
87+
if 'partition' in kwargs:
88+
msg = "'partition' is not allowed as a create parameter. Vcmp " \
89+
"guests are created with the 'name' at least."
90+
raise DisallowedCreationParameter(msg)
91+
super(Guest, self)._check_create_parameters(**kwargs)

f5/bigip/tm/vcmp/test/test_guest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import pytest
1818

1919
from f5.bigip.resource import MissingRequiredCreationParameter
20+
from f5.bigip.tm.vcmp.guest import DisallowedCreationParameter
21+
from f5.bigip.tm.vcmp.guest import DisallowedReadParameter
2022
from f5.bigip.tm.vcmp.guest import Guest
2123

2224

@@ -30,3 +32,17 @@ def test_create_no_args(FakeGuest):
3032
with pytest.raises(MissingRequiredCreationParameter) as ex:
3133
FakeGuest.create()
3234
assert "Missing required params: ['name']" in ex.value.message
35+
36+
37+
def test_create_with_parition(FakeGuest):
38+
with pytest.raises(DisallowedCreationParameter) as ex:
39+
FakeGuest.create(name='test', partition='Common')
40+
assert "'partition' is not allowed as a create parameter" in \
41+
ex.value.message
42+
43+
44+
def test_load_with_partition(FakeGuest):
45+
with pytest.raises(DisallowedReadParameter) as ex:
46+
FakeGuest.load(name='test', partition='Common')
47+
assert "'partition' is not allowed as a load parameter" in \
48+
ex.value.message

test/functional/tm/vcmp/test_guest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from f5.bigip.resource import MissingRequiredCreationParameter
1717
from f5.bigip.resource import MissingRequiredReadParameter
18+
from f5.bigip.tm.vcmp.guest import DisallowedCreationParameter
19+
from f5.bigip.tm.vcmp.guest import DisallowedReadParameter
1820
from icontrol.session import iControlUnexpectedHTTPError
1921

2022
import copy
@@ -55,18 +57,20 @@ def test_guest_create_refresh_update_delete_load_modify(
5557
guest1.update()
5658
assert guest1.managementGw == '10.190.0.1'
5759
old_sslmode = guest1.sslMode
58-
guest1.sslMode = 'dedicated'
60+
guest1.sslMode = 'testing ssl mode'
5961
guest1.refresh()
6062
assert guest1.sslMode == old_sslmode
6163
guest2 = guests.guest.load(name='test')
6264
assert guest1.selfLink == guest2.selfLink
65+
assert guest1.sslMode != 'dedicated'
6366
guest2.modify(sslMode='dedicated')
6467
guest1.refresh()
6568
assert guest2.sslMode == guest1.sslMode
6669

6770
def test_guest_modify(self, setup_guest_test):
6871
guests, guest1 = setup_guest_test
6972
original_dict = copy.copy(guest1.__dict__)
73+
assert guest1.managementGw != '10.190.0.1'
7074
gw = 'managementGw'
7175
guest1.modify(managementGw='10.190.0.1')
7276
for k, v in original_dict.items():
@@ -81,21 +85,22 @@ def test_guest_no_creation_args(self, vcmp_host):
8185
assert 'name' in ex.value.message
8286

8387
def test_guest_bad_creation_args(self, vcmp_host):
84-
with pytest.raises(iControlUnexpectedHTTPError) as ex:
88+
with pytest.raises(DisallowedCreationParameter) as ex:
8589
vcmp_host.tm.vcmp.guests.guest.create(
8690
name='test', partition='Common')
87-
assert '(/Common/test) is invalid' in ex.value.message
91+
assert "'partition' is not allowed as a create parameter" in \
92+
ex.value.message
8893

8994
def test_guest_no_load_args(self, vcmp_host):
9095
with pytest.raises(MissingRequiredReadParameter) as ex:
9196
vcmp_host.tm.vcmp.guests.guest.load()
9297
assert 'name' in ex.value.message
9398

9499
def test_guest_bad_load_args(self, vcmp_host):
95-
with pytest.raises(iControlUnexpectedHTTPError) as ex:
100+
with pytest.raises(DisallowedReadParameter) as ex:
96101
vcmp_host.tm.vcmp.guests.guest.load(
97102
name='test', partition='test-bad-arg')
98-
assert 'The requested VCMP (/test-bad-arg/test) was not found' in \
103+
assert "'partition' is not allowed as a load parameter" in \
99104
ex.value.message
100105

101106
def test_guest_bad_modify(self, setup_guest_test):

0 commit comments

Comments
 (0)