|
| 1 | +# Copyright 2015 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.resource import Collection |
| 21 | +from f5.bigip.resource import MissingRequiredCreationParameter |
| 22 | +from f5.bigip.resource import OrganizingCollection |
| 23 | +from f5.bigip.tm.gtm.wideip import A |
| 24 | +from f5.bigip.tm.gtm.wideip import Aaaa |
| 25 | +from f5.bigip.tm.gtm.wideip import Cname |
| 26 | +from f5.bigip.tm.gtm.wideip import Mx |
| 27 | +from f5.bigip.tm.gtm.wideip import Naptr |
| 28 | +from f5.bigip.tm.gtm.wideip import Srv |
| 29 | +from f5.bigip.tm.gtm.wideip import Wideip |
| 30 | +from f5.bigip.tm.gtm.wideip import WideipCollection |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +def FakeWideipv11(): |
| 35 | + fake_gtm = mock.MagicMock() |
| 36 | + fake_wideip = WideipCollection(fake_gtm) |
| 37 | + fake_wideip._meta_data['bigip'].tmos_version = '11.6.0' |
| 38 | + return fake_wideip |
| 39 | + |
| 40 | + |
| 41 | +class TestWideips(object): |
| 42 | + def test_new_method_v11(self, fakeicontrolsession): |
| 43 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 44 | + w1 = b.tm.gtm.wideips |
| 45 | + assert isinstance(w1, Collection) |
| 46 | + assert hasattr(w1, 'wideip') |
| 47 | + assert not hasattr(w1, 'a_s') |
| 48 | + assert not hasattr(w1, 'aaaas') |
| 49 | + assert not hasattr(w1, 'cnames') |
| 50 | + assert not hasattr(w1, 'mxs') |
| 51 | + assert not hasattr(w1, 'naptrs') |
| 52 | + assert not hasattr(w1, 'srvs') |
| 53 | + |
| 54 | + def test_new_method_v12(self, fakeicontrolsession_v12): |
| 55 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 56 | + w1 = b.tm.gtm.wideips |
| 57 | + assert isinstance(w1, OrganizingCollection) |
| 58 | + assert hasattr(w1, 'a_s') |
| 59 | + assert hasattr(w1, 'aaaas') |
| 60 | + assert hasattr(w1, 'cnames') |
| 61 | + assert hasattr(w1, 'mxs') |
| 62 | + assert hasattr(w1, 'naptrs') |
| 63 | + assert hasattr(w1, 'srvs') |
| 64 | + assert not hasattr(w1, 'wideip') |
| 65 | + |
| 66 | + |
| 67 | +class TestCreatev11(object): |
| 68 | + def test_create_two_v11(self, fakeicontrolsession): |
| 69 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 70 | + w1 = b.tm.gtm.wideips.wideip |
| 71 | + w2 = b.tm.gtm.wideips.wideip |
| 72 | + assert w1 is not w2 |
| 73 | + |
| 74 | + def test_create_no_args_v11(self, FakeWideipv11): |
| 75 | + with pytest.raises(MissingRequiredCreationParameter): |
| 76 | + FakeWideipv11.wideip.create() |
| 77 | + |
| 78 | + |
| 79 | +class TestCollectionv11(object): |
| 80 | + def test_wideip_attr_exists(self, fakeicontrolsession): |
| 81 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 82 | + w = b.tm.gtm.wideips |
| 83 | + test_meta = w._meta_data['attribute_registry'] |
| 84 | + test_meta2 = w._meta_data['allowed_lazy_attributes'] |
| 85 | + kind = 'tm:gtm:wideip:wideipstate' |
| 86 | + assert kind in test_meta.keys() |
| 87 | + assert Wideip in test_meta2 |
| 88 | + |
| 89 | + |
| 90 | +# Start v12.x Tests |
| 91 | +# Helper class to limit code repetition |
| 92 | +class HelperTest(object): |
| 93 | + def __init__(self, collection_name): |
| 94 | + self.lowered = collection_name.lower() |
| 95 | + self.kinds = {'a': 'tm:gtm:wideip:a:astate', |
| 96 | + 'aaaa': 'tm:gtm:wideip:aaaa:aaaastate', |
| 97 | + 'cname': 'tm:gtm:wideip:cname:cnamestate', |
| 98 | + 'mx': 'tm:gtm:wideip:mx:mxstate', |
| 99 | + 'naptr': 'tm:gtm:wideip:naptr:naptrstate', |
| 100 | + 'srv': 'tm:gtm:wideip:srv:srvstate'} |
| 101 | + |
| 102 | + def urielementname(self): |
| 103 | + if self.lowered[-2:] == '_s': |
| 104 | + endind = 2 |
| 105 | + else: |
| 106 | + endind = 1 |
| 107 | + return self.lowered[:-endind] |
| 108 | + |
| 109 | + def set_resources(self, fakeicontrolsession_v12): |
| 110 | + mr = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 111 | + b = mr.tm |
| 112 | + resourcecollection =\ |
| 113 | + getattr(getattr(getattr(b, 'gtm'), 'wideips'), |
| 114 | + self.lowered) |
| 115 | + resource1 = getattr(resourcecollection, self.urielementname()) |
| 116 | + resource2 = getattr(resourcecollection, self.urielementname()) |
| 117 | + return resource1, resource2 |
| 118 | + |
| 119 | + def set_collections(self, fakeicontrolsession_v12): |
| 120 | + mr = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 121 | + b = mr.tm |
| 122 | + resourcecollection =\ |
| 123 | + getattr(getattr(getattr(b, 'gtm'), 'wideips'), |
| 124 | + self.lowered) |
| 125 | + return resourcecollection |
| 126 | + |
| 127 | + def test_collections(self, fakeicontrolsession_v12, klass): |
| 128 | + rc = self.set_collections(fakeicontrolsession_v12) |
| 129 | + test_meta = rc._meta_data['attribute_registry'] |
| 130 | + test_meta2 = rc._meta_data['allowed_lazy_attributes'] |
| 131 | + kind = self.kinds[self.urielementname()] |
| 132 | + assert kind in test_meta.keys() |
| 133 | + assert klass in test_meta2 |
| 134 | + |
| 135 | + def test_create_two_v12(self, fakeicontrolsession_v12): |
| 136 | + r1, r2, = self.set_resources(fakeicontrolsession_v12) |
| 137 | + assert r1 is not r2 |
| 138 | + |
| 139 | + def test_create_no_args_v12(self, fakeicontrolsession_v12): |
| 140 | + r1, r2, = self.set_resources(fakeicontrolsession_v12) |
| 141 | + del r2 |
| 142 | + with pytest.raises(MissingRequiredCreationParameter): |
| 143 | + r1.create() |
| 144 | + |
| 145 | + |
| 146 | +class Testv12(object): |
| 147 | + def test_wideip_type_a(self, fakeicontrolsession_v12): |
| 148 | + w = HelperTest('a_s') |
| 149 | + w.test_collections(fakeicontrolsession_v12, A) |
| 150 | + w.test_create_two_v12(fakeicontrolsession_v12) |
| 151 | + w.test_create_no_args_v12(fakeicontrolsession_v12) |
| 152 | + |
| 153 | + def test_wideip_type_aaaa(self, fakeicontrolsession_v12): |
| 154 | + w = HelperTest('aaaas') |
| 155 | + w.test_collections(fakeicontrolsession_v12, Aaaa) |
| 156 | + w.test_create_two_v12(fakeicontrolsession_v12) |
| 157 | + w.test_create_no_args_v12(fakeicontrolsession_v12) |
| 158 | + |
| 159 | + def test_wideip_type_cname(self, fakeicontrolsession_v12): |
| 160 | + w = HelperTest('cnames') |
| 161 | + w.test_collections(fakeicontrolsession_v12, Cname) |
| 162 | + w.test_create_two_v12(fakeicontrolsession_v12) |
| 163 | + w.test_create_no_args_v12(fakeicontrolsession_v12) |
| 164 | + |
| 165 | + def test_wideip_type_mx(self, fakeicontrolsession_v12): |
| 166 | + w = HelperTest('Mxs') |
| 167 | + w.test_collections(fakeicontrolsession_v12, Mx) |
| 168 | + w.test_create_two_v12(fakeicontrolsession_v12) |
| 169 | + w.test_create_no_args_v12(fakeicontrolsession_v12) |
| 170 | + |
| 171 | + def test_wideip_type_naptr(self, fakeicontrolsession_v12): |
| 172 | + w = HelperTest('Naptrs') |
| 173 | + w.test_collections(fakeicontrolsession_v12, Naptr) |
| 174 | + w.test_create_two_v12(fakeicontrolsession_v12) |
| 175 | + w.test_create_no_args_v12(fakeicontrolsession_v12) |
| 176 | + |
| 177 | + def test_wideip_type_srv(self, fakeicontrolsession_v12): |
| 178 | + w = HelperTest('Srvs') |
| 179 | + w.test_collections(fakeicontrolsession_v12, Srv) |
| 180 | + w.test_create_two_v12(fakeicontrolsession_v12) |
| 181 | + w.test_create_no_args_v12(fakeicontrolsession_v12) |
0 commit comments