Skip to content

Commit 8a4e1b0

Browse files
authored
Merge pull request #667 from pjbreaux/feature.vcmp
VCMP endpoints need to be added
2 parents 0d94796 + 0d4e558 commit 8a4e1b0

8 files changed

Lines changed: 309 additions & 1 deletion

File tree

conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def pytest_addoption(parser):
4646
parser.addoption("--release", action="store",
4747
help="TMOS version, in dotted format, eg. 12.0.0",
4848
default='11.6.0')
49+
parser.addoption("--vcmp-host", action="store",
50+
help="IP address of VCMP enabled host.")
4951

5052

5153
@pytest.fixture
@@ -122,6 +124,11 @@ def opt_port(request):
122124
return request.config.getoption("--port")
123125

124126

127+
@pytest.fixture(scope='session')
128+
def opt_vcmp_host(request):
129+
return request.config.getoption("--vcmp-host")
130+
131+
125132
@pytest.fixture(scope='session')
126133
def bigip(opt_bigip, opt_username, opt_password, opt_port, scope="module"):
127134
'''bigip fixture'''
@@ -136,6 +143,14 @@ def mgmt_root(opt_bigip, opt_username, opt_password, opt_port, scope="module"):
136143
return m
137144

138145

146+
@pytest.fixture(scope='module')
147+
def vcmp_host(opt_vcmp_host, opt_username, opt_password, opt_port):
148+
'''vcmp fixture'''
149+
m = ManagementRoot(
150+
opt_vcmp_host, opt_username, opt_password, port=opt_port)
151+
return m
152+
153+
139154
@pytest.fixture(scope='session')
140155
def opt_release(request):
141156
return request.config.getoption("--release")

f5/bigip/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def _get_tmos_version(self):
8989
class BigIP(ManagementRoot):
9090
"""A shim class used to access the default config resources in 'mgmt/tm.'
9191
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+
9297
This class is solely implemented for backwards compatibility.
9398
"""
9499
def __init__(self, hostname, username, password, **kwargs):

f5/bigip/tm/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from f5.bigip.tm.shared import Shared
2727
from f5.bigip.tm.sys import Sys
2828
from f5.bigip.tm.transaction import Transactions
29+
from f5.bigip.tm.vcmp import Vcmp
2930

3031

3132
class Tm(OrganizingCollection):
@@ -40,5 +41,6 @@ def __init__(self, bigip):
4041
Net,
4142
Shared,
4243
Sys,
43-
Transactions
44+
Transactions,
45+
Vcmp
4446
]

f5/bigip/tm/vcmp/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2016 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
"""BIG-IP® VCMP (vcmp) module
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/vcmp/``
22+
23+
GUI Path
24+
``vCMP``
25+
26+
REST Kind
27+
``tm:vcmp:*``
28+
"""
29+
30+
from f5.bigip.resource import OrganizingCollection
31+
from f5.bigip.tm.vcmp.guest import Guests
32+
33+
34+
class Vcmp(OrganizingCollection):
35+
def __init__(self, tm):
36+
super(Vcmp, self).__init__(tm)
37+
self._meta_data['allowed_lazy_attributes'] = [Guests]

f5/bigip/tm/vcmp/guest.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2016 F5 Networks Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
"""BIG-IP® Guest (vcmp) module
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/vcmp/guest/``
22+
23+
GUI Path
24+
``Guest List``
25+
26+
REST Kind
27+
``tm:vcmp:guest:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
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
43+
44+
45+
class Guests(Collection):
46+
"""BIG-IP® Guests collection."""
47+
def __init__(self, vcmp):
48+
super(Guests, self).__init__(vcmp)
49+
self._meta_data['allowed_lazy_attributes'] = [Guest]
50+
self._meta_data['required_json_kind'] =\
51+
'tm:vcmp:guest:guestcollectionstate'
52+
self._meta_data['attribute_registry'] =\
53+
{'tm:vcmp:guest:gueststate': Guest}
54+
55+
56+
class Guest(Resource):
57+
"""BIG-IP® Guest resource."""
58+
def __init__(self, guests):
59+
super(Guest, self).__init__(guests)
60+
self._meta_data['required_json_kind'] =\
61+
'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 parameter.
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 parameter.
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)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2016 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import mock
17+
import pytest
18+
19+
from f5.bigip.resource import MissingRequiredCreationParameter
20+
from f5.bigip.tm.vcmp.guest import DisallowedCreationParameter
21+
from f5.bigip.tm.vcmp.guest import DisallowedReadParameter
22+
from f5.bigip.tm.vcmp.guest import Guest
23+
24+
25+
@pytest.fixture
26+
def FakeGuest():
27+
fake_guests = mock.MagicMock()
28+
return Guest(fake_guests)
29+
30+
31+
def test_create_no_args(FakeGuest):
32+
with pytest.raises(MissingRequiredCreationParameter) as ex:
33+
FakeGuest.create()
34+
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/__init__.py

Whitespace-only changes.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Copyright 2016 F5 Networks Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
from f5.bigip.resource import MissingRequiredCreationParameter
17+
from f5.bigip.resource import MissingRequiredReadParameter
18+
from f5.bigip.tm.vcmp.guest import DisallowedCreationParameter
19+
from f5.bigip.tm.vcmp.guest import DisallowedReadParameter
20+
from icontrol.session import iControlUnexpectedHTTPError
21+
22+
import copy
23+
import pytest
24+
25+
26+
try:
27+
vcmp_host = pytest.config.getoption('--vcmp-host')
28+
except Exception as ex:
29+
vcmp_host = None
30+
31+
32+
@pytest.fixture
33+
def setup_guest_test(request, vcmp_host):
34+
def teardown():
35+
guest.delete()
36+
request.addfinalizer(teardown)
37+
guests = vcmp_host.tm.vcmp.guests
38+
guest = guests.guest.create(name='test')
39+
return guests, guest
40+
41+
42+
@pytest.mark.skipif(vcmp_host is None,
43+
reason='Provide --vcmp-host to run vcmp tests.')
44+
class TestGuest(object):
45+
def test_guests_get_collection(self, setup_guest_test):
46+
guests, guest1 = setup_guest_test
47+
gc = list(guests.get_collection())
48+
assert len(gc) > 1
49+
50+
def test_guest_create_refresh_update_delete_load_modify(
51+
self, setup_guest_test
52+
):
53+
guests, guest1 = setup_guest_test
54+
assert guest1.name == 'test'
55+
assert guest1.managementNetwork == 'bridged'
56+
guest1.managementGw = '10.190.0.1'
57+
guest1.update()
58+
assert guest1.managementGw == '10.190.0.1'
59+
old_sslmode = guest1.sslMode
60+
guest1.sslMode = 'testing ssl mode'
61+
guest1.refresh()
62+
assert guest1.sslMode == old_sslmode
63+
guest2 = guests.guest.load(name='test')
64+
assert guest1.selfLink == guest2.selfLink
65+
assert guest1.sslMode != 'dedicated'
66+
guest2.modify(sslMode='dedicated')
67+
guest1.refresh()
68+
assert guest2.sslMode == guest1.sslMode
69+
70+
def test_guest_modify(self, setup_guest_test):
71+
guests, guest1 = setup_guest_test
72+
original_dict = copy.copy(guest1.__dict__)
73+
assert guest1.managementGw != '10.190.0.1'
74+
gw = 'managementGw'
75+
guest1.modify(managementGw='10.190.0.1')
76+
for k, v in original_dict.items():
77+
if k != gw:
78+
original_dict[k] = guest1.__dict__[k]
79+
elif k == gw:
80+
guest1.__dict__[k] == '10.190.0.1'
81+
82+
def test_guest_no_creation_args(self, vcmp_host):
83+
with pytest.raises(MissingRequiredCreationParameter) as ex:
84+
vcmp_host.tm.vcmp.guests.guest.create()
85+
assert 'name' in ex.value.message
86+
87+
def test_guest_bad_creation_args(self, vcmp_host):
88+
with pytest.raises(DisallowedCreationParameter) as ex:
89+
vcmp_host.tm.vcmp.guests.guest.create(
90+
name='test', partition='Common')
91+
assert "'partition' is not allowed as a create parameter" in \
92+
ex.value.message
93+
94+
def test_guest_no_load_args(self, vcmp_host):
95+
with pytest.raises(MissingRequiredReadParameter) as ex:
96+
vcmp_host.tm.vcmp.guests.guest.load()
97+
assert 'name' in ex.value.message
98+
99+
def test_guest_bad_load_args(self, vcmp_host):
100+
with pytest.raises(DisallowedReadParameter) as ex:
101+
vcmp_host.tm.vcmp.guests.guest.load(
102+
name='test', partition='test-bad-arg')
103+
assert "'partition' is not allowed as a load parameter" in \
104+
ex.value.message
105+
106+
def test_guest_bad_modify(self, setup_guest_test):
107+
guests, guest1 = setup_guest_test
108+
with pytest.raises(iControlUnexpectedHTTPError) as ex:
109+
guest1.modify(generation=34)
110+
assert 'one or more properties must be specified' in ex.value.message

0 commit comments

Comments
 (0)