Skip to content

Commit 70e1ec1

Browse files
Merge pull request #1599 from zhaoqin-github/cipher-3.0.11
Support LTM Cipher (v3.0.11-dev)
2 parents 1ed7164 + fb184be commit 70e1ec1

File tree

5 files changed

+256
-1
lines changed

5 files changed

+256
-1
lines changed

f5/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
#
15-
__version__ = '3.0.11.3'
15+
__version__ = '3.0.11.4'

f5/bigip/tm/ltm/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from f5.bigip.resource import OrganizingCollection
3232
from f5.bigip.tm.ltm.auth import Auth
33+
from f5.bigip.tm.ltm.cipher import Cipher
3334
from f5.bigip.tm.ltm.data_group import Data_Group
3435
from f5.bigip.tm.ltm.default_node_monitor import Default_Node_Monitor
3536
from f5.bigip.tm.ltm.ifile import Ifiles
@@ -57,6 +58,7 @@ def __init__(self, tm):
5758
super(Ltm, self).__init__(tm)
5859
self._meta_data['allowed_lazy_attributes'] = [
5960
Auth,
61+
Cipher,
6062
Data_Group,
6163
Default_Node_Monitor,
6264
Ifiles,

f5/bigip/tm/ltm/cipher.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2021 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® Local Traffic Manager™ (LTM®) cipher module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/ltm/cipher``
22+
23+
GUI Path
24+
``Local Traffic --> Ciphers``
25+
26+
REST Kind
27+
``tm:ltm:cipher:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import OrganizingCollection
32+
from f5.bigip.resource import Resource
33+
34+
35+
class Cipher(OrganizingCollection):
36+
"""BIG-IP® LTM cipher collection"""
37+
def __init__(self, ltm):
38+
super(Cipher, self).__init__(ltm)
39+
self._meta_data['allowed_lazy_attributes'] = [
40+
Rules,
41+
Groups
42+
]
43+
44+
45+
class Rules(Collection):
46+
"""BIG-IP® cipher rule sub-collection"""
47+
def __init__(self, cipher):
48+
super(Rules, self).__init__(cipher)
49+
self._meta_data['allowed_lazy_attributes'] = [Rule]
50+
self._meta_data['attribute_registry'] =\
51+
{'tm:ltm:cipher:rule:rulestate': Rule}
52+
53+
54+
class Rule(Resource):
55+
"""BIG-IP® cipher rule sub-collection resource"""
56+
def __init__(self, rule_s):
57+
super(Rule, self).__init__(rule_s)
58+
self._meta_data['required_creation_parameters'].update(('partition',))
59+
self._meta_data['required_json_kind'] =\
60+
'tm:ltm:cipher:rule:rulestate'
61+
62+
63+
class Groups(Collection):
64+
"""BIG-IP® cipher group sub-collection"""
65+
def __init__(self, cipher):
66+
super(Groups, self).__init__(cipher)
67+
self._meta_data['allowed_lazy_attributes'] = [Group]
68+
self._meta_data['attribute_registry'] =\
69+
{'tm:ltm:cipher:group:groupstate': Group}
70+
71+
72+
class Group(Resource):
73+
"""BIG-IP® cipher group sub-collection resource"""
74+
def __init__(self, group_s):
75+
super(Group, self).__init__(group_s)
76+
self._meta_data['required_creation_parameters'].update(('partition',))
77+
self._meta_data['required_json_kind'] =\
78+
'tm:ltm:cipher:group:groupstate'
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright 2021 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 requests.exceptions import HTTPError
17+
18+
19+
TEST_DESCR = "TEST DESCRIPTION"
20+
21+
22+
def delete_resource(resource):
23+
try:
24+
resource.delete()
25+
except HTTPError as err:
26+
if err.response.status_code != 404:
27+
raise
28+
29+
30+
def setup_cipher_rule_test(request, mgmt_root, name, partition, maxRate):
31+
def teardown():
32+
delete_resource(rule)
33+
request.addfinalizer(teardown)
34+
35+
rule = mgmt_root.tm.ltm.cipher.rules.rule.create(
36+
name=name, partition=partition, maxRate=maxRate)
37+
return rule
38+
39+
40+
def setup_cipher_group_test(request, mgmt_root, name, partition, maxRate):
41+
def teardown():
42+
delete_resource(group)
43+
request.addfinalizer(teardown)
44+
45+
group = mgmt_root.tm.ltm.cipher.groups.group.create(
46+
name=name, partition=partition, maxRate=maxRate)
47+
return group
48+
49+
50+
class TestCipherRules(object):
51+
def test_cipher_rule_list(self, mgmt_root):
52+
rules = mgmt_root.tm.ltm.cipher.rules.get_collection()
53+
assert len(rules)
54+
for rule in rules:
55+
assert rule.generation
56+
57+
58+
class TestCipherRule(object):
59+
def test_cipher_rule_CURDL(self, request, mgmt_root):
60+
# Create and Delete are tested by the setup/teardown
61+
r1 = setup_cipher_rule_test(
62+
request, mgmt_root, 'cipher-rule-test', 'Common', 1000000
63+
)
64+
65+
# Load
66+
r2 = mgmt_root.tm.ltm.cipher.rules.rule.load(
67+
name='cipher-rule-test', partition='Common')
68+
assert r1.name == 'cipher-rule-test'
69+
assert r1.name == r2.name
70+
assert r1.generation == r2.generation
71+
72+
# Update
73+
r1.description = TEST_DESCR
74+
r1.update()
75+
assert r1.description == TEST_DESCR
76+
assert r1.generation > r2.generation
77+
78+
# Refresh
79+
r2.refresh()
80+
assert r2.description == TEST_DESCR
81+
assert r1.generation == r2.generation
82+
83+
84+
class TestCipherGroups(object):
85+
def test_cipher_group_list(self, mgmt_root):
86+
groups = mgmt_root.tm.ltm.cipher.groups.get_collection()
87+
assert len(groups)
88+
for group in groups:
89+
assert group.generation
90+
91+
92+
class TestCipherGroup(object):
93+
def test_cipher_group_CURDL(self, request, mgmt_root):
94+
# Create and Delete are tested by the setup/teardown
95+
g1 = setup_cipher_group_test(
96+
request, mgmt_root, 'cipher-group-test', 'Common', 1000000
97+
)
98+
99+
# Load
100+
g2 = mgmt_root.tm.ltm.cipher.groups.group.load(
101+
name='cipher-group-test', partition='Common')
102+
assert g1.name == 'cipher-group-test'
103+
assert g1.name == g2.name
104+
assert g1.generation == g2.generation
105+
106+
# Update
107+
g1.description = TEST_DESCR
108+
g1.update()
109+
assert g1.description == TEST_DESCR
110+
assert g1.generation > g2.generation
111+
112+
# Refresh
113+
g2.refresh()
114+
assert g2.description == TEST_DESCR
115+
assert g1.generation == g2.generation
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2021 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 import ManagementRoot
20+
from f5.bigip.tm.ltm.cipher import Group
21+
from f5.bigip.tm.ltm.cipher import Rule
22+
from f5.sdk_exception import MissingRequiredCreationParameter
23+
24+
25+
@pytest.fixture
26+
def FakeCipherRule():
27+
fake_rule_s = mock.MagicMock()
28+
fake_rule = Rule(fake_rule_s)
29+
return fake_rule
30+
31+
32+
@pytest.fixture
33+
def FakeCipherGroup():
34+
fake_group_s = mock.MagicMock()
35+
fake_group = Group(fake_group_s)
36+
return fake_group
37+
38+
39+
class TestCipherRuleCreate(object):
40+
def test_create_two(self, fakeicontrolsession):
41+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
42+
r1 = b.tm.ltm.cipher.rules.rule
43+
r2 = b.tm.ltm.cipher.rules.rule
44+
assert r1 is not r2
45+
46+
def test_create_no_args(self, FakeCipherRule):
47+
with pytest.raises(MissingRequiredCreationParameter):
48+
FakeCipherRule.create()
49+
50+
51+
class TestCipherGroupCreate(object):
52+
def test_create_two(self, fakeicontrolsession):
53+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
54+
g1 = b.tm.ltm.cipher.groups.group
55+
g2 = b.tm.ltm.cipher.groups.group
56+
assert g1 is not g2
57+
58+
def test_create_no_args(self, FakeCipherGroup):
59+
with pytest.raises(MissingRequiredCreationParameter):
60+
FakeCipherGroup.create()

0 commit comments

Comments
 (0)