Skip to content

Commit

Permalink
Merge pull request #1599 from zhaoqin-github/cipher-3.0.11
Browse files Browse the repository at this point in the history
Support LTM Cipher (v3.0.11-dev)
  • Loading branch information
zhaoqin-github committed Jul 9, 2021
2 parents 1ed7164 + fb184be commit 70e1ec1
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 1 deletion.
2 changes: 1 addition & 1 deletion f5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = '3.0.11.3'
__version__ = '3.0.11.4'
2 changes: 2 additions & 0 deletions f5/bigip/tm/ltm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from f5.bigip.resource import OrganizingCollection
from f5.bigip.tm.ltm.auth import Auth
from f5.bigip.tm.ltm.cipher import Cipher
from f5.bigip.tm.ltm.data_group import Data_Group
from f5.bigip.tm.ltm.default_node_monitor import Default_Node_Monitor
from f5.bigip.tm.ltm.ifile import Ifiles
Expand Down Expand Up @@ -57,6 +58,7 @@ def __init__(self, tm):
super(Ltm, self).__init__(tm)
self._meta_data['allowed_lazy_attributes'] = [
Auth,
Cipher,
Data_Group,
Default_Node_Monitor,
Ifiles,
Expand Down
78 changes: 78 additions & 0 deletions f5/bigip/tm/ltm/cipher.py
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'
115 changes: 115 additions & 0 deletions f5/bigip/tm/ltm/test/functional/test_cipher.py
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
60 changes: 60 additions & 0 deletions f5/bigip/tm/ltm/test/unit/test_cipher.py
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()

0 comments on commit 70e1ec1

Please sign in to comment.