|
| 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 |
0 commit comments