Skip to content

Commit c50c99b

Browse files
committed
Fixes issue #1524
- Adds proxies kwarg to allowed arguments on ManagementRoot - Adds unit test validating acceptance of kwarg - Requires f5-icontrol-rest min version 1.3.13 that was also updated to allow proxies kwarg from sdk Additional Fixes - updates pyOpenSSL min requirement to address security vulnerability in that package - updates for pycodestyle testing - updates for test requirements
1 parent 85f4866 commit c50c99b

13 files changed

Lines changed: 83 additions & 67 deletions

File tree

f5/bigip/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def parse_arguments(self, *args, **kwargs):
6262
result = dict(
6363
timeout=kwargs.pop('timeout', 30),
6464
port=kwargs.pop('port', 443),
65+
proxies=kwargs.pop('proxies', {}),
6566
icontrol_version=kwargs.pop('icontrol_version', ''),
6667
token=kwargs.pop('token', False),
6768
token_to_use=kwargs.pop('token_to_use', None),
@@ -83,6 +84,7 @@ def _get_icr_session(self, *args, **kwargs):
8384
username=kwargs['username'],
8485
password=kwargs['password'],
8586
timeout=kwargs['timeout'],
87+
proxies=kwargs['proxies'],
8688
verify=kwargs['verify'],
8789
token_to_use=kwargs['token_to_use']
8890
)
@@ -100,6 +102,7 @@ def configure_meta_data(self, *args, **kwargs):
100102
'allowed_lazy_attributes': [Tm, Cm, Shared],
101103
'hostname': kwargs['hostname'],
102104
'port': kwargs['port'],
105+
'proxies': kwargs['proxies'],
103106
'device_name': None,
104107
'local_ip': None,
105108
'bigip': self,

f5/bigip/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class AsmFileMixin(object):
369369
370370
"""
371371
def _download_file(self, filepathname):
372-
self._download(filepathname)
372+
self._download(filepathname)
373373

374374
def _download(self, filepathname):
375375
session = self._meta_data['icr_session']

f5/bigip/test/unit/test___init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ def FakeBigIPWithPort(fakeicontrolsession):
4747
return FBIP
4848

4949

50+
@pytest.fixture
51+
def FakeBigIPWithProxy(fakeicontrolsession):
52+
FBIP = ManagementRoot('FakeHostName', 'admin', 'admin', proxies={"https": "https://127.0.0.1:8080"})
53+
FBIP.icontrol = mock.MagicMock()
54+
return FBIP
55+
56+
5057
def test___get__attr(FakeBigIP):
5158
bigip_dot_asm = FakeBigIP.tm.asm
5259
assert isinstance(bigip_dot_asm, Asm)
@@ -86,3 +93,8 @@ def test_icontrol_version(FakeBigIPWithPort):
8693
def test_non_default_port_number(FakeBigIPWithPort):
8794
uri = urlparse.urlsplit(FakeBigIPWithPort._meta_data['uri'])
8895
assert uri.port == 10443
96+
97+
98+
def test_proxy(FakeBigIPWithProxy):
99+
proxy = FakeBigIPWithProxy._meta_data['proxies']
100+
assert proxy == {"https": "https://127.0.0.1:8080"}

f5/bigip/test/unit/test_mixins.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ def fake_http_server(uri, **kwargs):
174174

175175

176176
class FakeAsmFileMixin(AsmFileMixin):
177-
def __init__(self, uri, **kwargs):
178-
session = fake_http_server(uri, **kwargs)
179-
self._meta_data = {'icr_session': session}
180-
self.file_bound_uri = uri
177+
def __init__(self, uri, **kwargs):
178+
session = fake_http_server(uri, **kwargs)
179+
self._meta_data = {'icr_session': session}
180+
self.file_bound_uri = uri
181181

182182

183183
class TestAsmFileMixin(object):

f5/bigip/tm/gtm/test/unit/test_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_non_404_response__v12_1(self, fakeicontrolsession_v12):
285285
session.post.side_effect = error
286286
memres._meta_data['bigip']._meta_data['icr_session'] = session
287287
with pytest.raises(HTTPError) as err:
288-
memres.create(name='fake', partition='fakepart')
288+
memres.create(name='fake', partition='fakepart')
289289
assert err.value.response.status_code == 500
290290

291291
def test_404_response_v12_1(self, fakeicontrolsession_v12):

f5/bigip/tm/ltm/test/functional/test_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_get_collection(self, request, mgmt_root, opt_release):
7979
member1.refresh()
8080
except HTTPError as err:
8181
if err.response.status_code != 404:
82-
raise
82+
raise
8383
pre_del = set(iterkeys(pool1.__dict__))
8484
pool1.refresh()
8585
post_del = set(iterkeys(pool1.__dict__))

f5/bigip/tm/ltm/test/functional/test_virtual_address.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def teardown():
2626
def setup_virtual_address_test(request, mgmt_root, va_name, va_partition):
2727
vac = mgmt_root.tm.ltm.virtual_address_s
2828
if vac.virtual_address.exists(name=va_name, partition=va_partition):
29-
vac.virtual_address.load(
30-
name=va_name, partition=va_partition).delete()
29+
vac.virtual_address.load(
30+
name=va_name, partition=va_partition).delete()
3131
va = vac.virtual_address.create(name=va_name, partition=va_partition)
3232
request.addfinalizer(va.delete)
3333
return vac, va

f5/bigip/tm/security/test/unit/test_shared_objects.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,40 +39,40 @@ def FakePortLst():
3939

4040

4141
class TestAddresslist_sharedobjects(object):
42-
def test_create_two(self, fakeicontrolsession):
43-
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
44-
b._meta_data['tmos_version'] = '14.0.0'
45-
a1 = b.tm.security.shared_objects.address_lists.address_list
46-
a2 = b.tm.security.shared_objects.address_lists.address_list
47-
assert a1 is not a2
42+
def test_create_two(self, fakeicontrolsession):
43+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
44+
b._meta_data['tmos_version'] = '14.0.0'
45+
a1 = b.tm.security.shared_objects.address_lists.address_list
46+
a2 = b.tm.security.shared_objects.address_lists.address_list
47+
assert a1 is not a2
4848

49-
def test_create_no_args(self, FakeAddrLst):
50-
with pytest.raises(MissingRequiredCreationParameter):
51-
FakeAddrLst.create()
49+
def test_create_no_args(self, FakeAddrLst):
50+
with pytest.raises(MissingRequiredCreationParameter):
51+
FakeAddrLst.create()
5252

53-
def test_create_mandatory_args_missing(self, fakeicontrolsession):
54-
b = ManagementRoot('192.168.1.1.', 'admin', 'admin')
55-
b._meta_data['tmos_version'] = '14.0.0'
56-
with pytest.raises(MissingRequiredCreationParameter):
57-
b.tm.security.shared_objects.address_lists.address_list.create(
58-
name='destined_to_fail', partition='Common')
53+
def test_create_mandatory_args_missing(self, fakeicontrolsession):
54+
b = ManagementRoot('192.168.1.1.', 'admin', 'admin')
55+
b._meta_data['tmos_version'] = '14.0.0'
56+
with pytest.raises(MissingRequiredCreationParameter):
57+
b.tm.security.shared_objects.address_lists.address_list.create(
58+
name='destined_to_fail', partition='Common')
5959

6060

6161
class TestPortList_sharedobjects(object):
62-
def test_create_two(self, fakeicontrolsession):
63-
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
64-
b._meta_data['tmos_version'] = '14.0.0'
65-
r1 = b.tm.security.shared_objects.port_lists.port_list
66-
r2 = b.tm.security.shared_objects.port_lists.port_list
67-
assert r1 is not r2
62+
def test_create_two(self, fakeicontrolsession):
63+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
64+
b._meta_data['tmos_version'] = '14.0.0'
65+
r1 = b.tm.security.shared_objects.port_lists.port_list
66+
r2 = b.tm.security.shared_objects.port_lists.port_list
67+
assert r1 is not r2
6868

69-
def test_create_no_args(self, FakePortLst):
70-
with pytest.raises(MissingRequiredCreationParameter):
71-
FakePortLst.create()
69+
def test_create_no_args(self, FakePortLst):
70+
with pytest.raises(MissingRequiredCreationParameter):
71+
FakePortLst.create()
7272

73-
def test_create_mandatory_args_missing(self, fakeicontrolsession):
74-
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
75-
b._meta_data['tmos_version'] = '14.0.0'
76-
with pytest.raises(MissingRequiredCreationParameter):
77-
b.tm.security.shared_objects.port_lists.port_list.create(
78-
name='destined_to_fail', partition='Common')
73+
def test_create_mandatory_args_missing(self, fakeicontrolsession):
74+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
75+
b._meta_data['tmos_version'] = '14.0.0'
76+
with pytest.raises(MissingRequiredCreationParameter):
77+
b.tm.security.shared_objects.port_lists.port_list.create(
78+
name='destined_to_fail', partition='Common')

f5/bigip/tm/sys/test/functional/test_clock.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818

1919
def test_clock_load(request, mgmt_root):
20-
# Load
21-
bigipclock = str(Stats(mgmt_root.tm.sys.clock.load()).stat.fullDate['description'])
22-
bigipdate = bigipclock.split("T")[0]
20+
# Load
21+
bigipclock = str(Stats(mgmt_root.tm.sys.clock.load()).stat.fullDate['description'])
22+
bigipdate = bigipclock.split("T")[0]
2323

24-
assert bigipdate == datetime.strptime(bigipdate, "%Y-%m-%d").strftime('%Y-%m-%d')
24+
assert bigipdate == datetime.strptime(bigipdate, "%Y-%m-%d").strftime('%Y-%m-%d')

f5/bigip/tm/sys/test/functional/test_cluster.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@
1717

1818

1919
def test_cluster_load(request, mgmt_root):
20-
# Load will produce exception on non-cluster BIGIP.
21-
# iControlUnexpectedHTTPError: 404 Unexpected Error: Not Found for uri:
22-
try:
23-
assert str(mgmt_root.tm.sys.cluster.default.load().kind) == 'tm:sys:cluster:clusterstate'
24-
except iControlUnexpectedHTTPError as err:
25-
assert('01020036:3: The requested cluster (default) was not found.' in str(err))
20+
# Load will produce exception on non-cluster BIGIP.
21+
# iControlUnexpectedHTTPError: 404 Unexpected Error: Not Found for uri:
22+
try:
23+
assert str(mgmt_root.tm.sys.cluster.default.load().kind) == 'tm:sys:cluster:clusterstate'
24+
except iControlUnexpectedHTTPError as err:
25+
assert ('01020036:3: The requested cluster (default) was not found.' in str(err))
2626

2727

2828
def test_cluster_stats_load(request, mgmt_root):
29-
# Load will give the result even on non-cluster BIGIP. However, the payload will be almost empty
30-
assert str(mgmt_root.tm.sys.cluster.stats.load().kind) == 'tm:sys:cluster:clustercollectionstats'
29+
# Load will give the result even on non-cluster BIGIP. However, the payload will be almost empty
30+
assert str(mgmt_root.tm.sys.cluster.stats.load().kind) == 'tm:sys:cluster:clustercollectionstats'
3131

3232

3333
def test_cluster_default_stats_load(request, mgmt_root):
34-
# Load will produce exception on non-cluster BIGIP.
35-
# iControlUnexpectedHTTPError: 404 Unexpected Error: Not Found for uri:
36-
try:
37-
assert str(mgmt_root.tm.sys.cluster.default.stats.load().kind) == 'tm:sys:cluster:clusterstats'
38-
except iControlUnexpectedHTTPError as err:
39-
assert('01020036:3: The requested cluster (default) was not found.' in str(err))
34+
# Load will produce exception on non-cluster BIGIP.
35+
# iControlUnexpectedHTTPError: 404 Unexpected Error: Not Found for uri:
36+
try:
37+
assert str(mgmt_root.tm.sys.cluster.default.stats.load().kind) == 'tm:sys:cluster:clusterstats'
38+
except iControlUnexpectedHTTPError as err:
39+
assert ('01020036:3: The requested cluster (default) was not found.' in str(err))

0 commit comments

Comments
 (0)