-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1599 from zhaoqin-github/cipher-3.0.11
Support LTM Cipher (v3.0.11-dev)
- Loading branch information
Showing
5 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# coding=utf-8 | ||
# | ||
# Copyright 2021 F5 Networks Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
"""BIG-IP® Local Traffic Manager™ (LTM®) cipher module. | ||
REST URI | ||
``http://localhost/mgmt/tm/ltm/cipher`` | ||
GUI Path | ||
``Local Traffic --> Ciphers`` | ||
REST Kind | ||
``tm:ltm:cipher:*`` | ||
""" | ||
|
||
from f5.bigip.resource import Collection | ||
from f5.bigip.resource import OrganizingCollection | ||
from f5.bigip.resource import Resource | ||
|
||
|
||
class Cipher(OrganizingCollection): | ||
"""BIG-IP® LTM cipher collection""" | ||
def __init__(self, ltm): | ||
super(Cipher, self).__init__(ltm) | ||
self._meta_data['allowed_lazy_attributes'] = [ | ||
Rules, | ||
Groups | ||
] | ||
|
||
|
||
class Rules(Collection): | ||
"""BIG-IP® cipher rule sub-collection""" | ||
def __init__(self, cipher): | ||
super(Rules, self).__init__(cipher) | ||
self._meta_data['allowed_lazy_attributes'] = [Rule] | ||
self._meta_data['attribute_registry'] =\ | ||
{'tm:ltm:cipher:rule:rulestate': Rule} | ||
|
||
|
||
class Rule(Resource): | ||
"""BIG-IP® cipher rule sub-collection resource""" | ||
def __init__(self, rule_s): | ||
super(Rule, self).__init__(rule_s) | ||
self._meta_data['required_creation_parameters'].update(('partition',)) | ||
self._meta_data['required_json_kind'] =\ | ||
'tm:ltm:cipher:rule:rulestate' | ||
|
||
|
||
class Groups(Collection): | ||
"""BIG-IP® cipher group sub-collection""" | ||
def __init__(self, cipher): | ||
super(Groups, self).__init__(cipher) | ||
self._meta_data['allowed_lazy_attributes'] = [Group] | ||
self._meta_data['attribute_registry'] =\ | ||
{'tm:ltm:cipher:group:groupstate': Group} | ||
|
||
|
||
class Group(Resource): | ||
"""BIG-IP® cipher group sub-collection resource""" | ||
def __init__(self, group_s): | ||
super(Group, self).__init__(group_s) | ||
self._meta_data['required_creation_parameters'].update(('partition',)) | ||
self._meta_data['required_json_kind'] =\ | ||
'tm:ltm:cipher:group:groupstate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Copyright 2021 F5 Networks Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from requests.exceptions import HTTPError | ||
|
||
|
||
TEST_DESCR = "TEST DESCRIPTION" | ||
|
||
|
||
def delete_resource(resource): | ||
try: | ||
resource.delete() | ||
except HTTPError as err: | ||
if err.response.status_code != 404: | ||
raise | ||
|
||
|
||
def setup_cipher_rule_test(request, mgmt_root, name, partition, maxRate): | ||
def teardown(): | ||
delete_resource(rule) | ||
request.addfinalizer(teardown) | ||
|
||
rule = mgmt_root.tm.ltm.cipher.rules.rule.create( | ||
name=name, partition=partition, maxRate=maxRate) | ||
return rule | ||
|
||
|
||
def setup_cipher_group_test(request, mgmt_root, name, partition, maxRate): | ||
def teardown(): | ||
delete_resource(group) | ||
request.addfinalizer(teardown) | ||
|
||
group = mgmt_root.tm.ltm.cipher.groups.group.create( | ||
name=name, partition=partition, maxRate=maxRate) | ||
return group | ||
|
||
|
||
class TestCipherRules(object): | ||
def test_cipher_rule_list(self, mgmt_root): | ||
rules = mgmt_root.tm.ltm.cipher.rules.get_collection() | ||
assert len(rules) | ||
for rule in rules: | ||
assert rule.generation | ||
|
||
|
||
class TestCipherRule(object): | ||
def test_cipher_rule_CURDL(self, request, mgmt_root): | ||
# Create and Delete are tested by the setup/teardown | ||
r1 = setup_cipher_rule_test( | ||
request, mgmt_root, 'cipher-rule-test', 'Common', 1000000 | ||
) | ||
|
||
# Load | ||
r2 = mgmt_root.tm.ltm.cipher.rules.rule.load( | ||
name='cipher-rule-test', partition='Common') | ||
assert r1.name == 'cipher-rule-test' | ||
assert r1.name == r2.name | ||
assert r1.generation == r2.generation | ||
|
||
# Update | ||
r1.description = TEST_DESCR | ||
r1.update() | ||
assert r1.description == TEST_DESCR | ||
assert r1.generation > r2.generation | ||
|
||
# Refresh | ||
r2.refresh() | ||
assert r2.description == TEST_DESCR | ||
assert r1.generation == r2.generation | ||
|
||
|
||
class TestCipherGroups(object): | ||
def test_cipher_group_list(self, mgmt_root): | ||
groups = mgmt_root.tm.ltm.cipher.groups.get_collection() | ||
assert len(groups) | ||
for group in groups: | ||
assert group.generation | ||
|
||
|
||
class TestCipherGroup(object): | ||
def test_cipher_group_CURDL(self, request, mgmt_root): | ||
# Create and Delete are tested by the setup/teardown | ||
g1 = setup_cipher_group_test( | ||
request, mgmt_root, 'cipher-group-test', 'Common', 1000000 | ||
) | ||
|
||
# Load | ||
g2 = mgmt_root.tm.ltm.cipher.groups.group.load( | ||
name='cipher-group-test', partition='Common') | ||
assert g1.name == 'cipher-group-test' | ||
assert g1.name == g2.name | ||
assert g1.generation == g2.generation | ||
|
||
# Update | ||
g1.description = TEST_DESCR | ||
g1.update() | ||
assert g1.description == TEST_DESCR | ||
assert g1.generation > g2.generation | ||
|
||
# Refresh | ||
g2.refresh() | ||
assert g2.description == TEST_DESCR | ||
assert g1.generation == g2.generation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2021 F5 Networks Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
import mock | ||
import pytest | ||
|
||
from f5.bigip import ManagementRoot | ||
from f5.bigip.tm.ltm.cipher import Group | ||
from f5.bigip.tm.ltm.cipher import Rule | ||
from f5.sdk_exception import MissingRequiredCreationParameter | ||
|
||
|
||
@pytest.fixture | ||
def FakeCipherRule(): | ||
fake_rule_s = mock.MagicMock() | ||
fake_rule = Rule(fake_rule_s) | ||
return fake_rule | ||
|
||
|
||
@pytest.fixture | ||
def FakeCipherGroup(): | ||
fake_group_s = mock.MagicMock() | ||
fake_group = Group(fake_group_s) | ||
return fake_group | ||
|
||
|
||
class TestCipherRuleCreate(object): | ||
def test_create_two(self, fakeicontrolsession): | ||
b = ManagementRoot('192.168.1.1', 'admin', 'admin') | ||
r1 = b.tm.ltm.cipher.rules.rule | ||
r2 = b.tm.ltm.cipher.rules.rule | ||
assert r1 is not r2 | ||
|
||
def test_create_no_args(self, FakeCipherRule): | ||
with pytest.raises(MissingRequiredCreationParameter): | ||
FakeCipherRule.create() | ||
|
||
|
||
class TestCipherGroupCreate(object): | ||
def test_create_two(self, fakeicontrolsession): | ||
b = ManagementRoot('192.168.1.1', 'admin', 'admin') | ||
g1 = b.tm.ltm.cipher.groups.group | ||
g2 = b.tm.ltm.cipher.groups.group | ||
assert g1 is not g2 | ||
|
||
def test_create_no_args(self, FakeCipherGroup): | ||
with pytest.raises(MissingRequiredCreationParameter): | ||
FakeCipherGroup.create() |