Skip to content

Commit 8c50cfa

Browse files
wojtek0806caphrim007
authored andcommitted
Add LTM Traffic Class Endpoint (#685)
* Fixes #409 Problem: LTM traffic-class endpoint was missing from the SDK Analysis: Added LTM traffic-class endpoint to SDK Tests: Flake8 Functional Tests Unit Tests Files Added/Changed: f5-common-python/f5/bigip/tm/ltm/init.py f5-common-python/f5/bigip/tm/ltm/traffic_class.py f5-common-python/f5/bigip/tm/ltm/test/test_traffic_class.py f5-common-python/test/functional/tm/ltm/test_traffic_class.py * python3 corrections
1 parent f5c954e commit 8c50cfa

4 files changed

Lines changed: 161 additions & 0 deletions

File tree

f5/bigip/tm/ltm/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from f5.bigip.tm.ltm.snat import Snats
4343
from f5.bigip.tm.ltm.snat_translation import Snat_Translations
4444
from f5.bigip.tm.ltm.snatpool import Snatpools
45+
from f5.bigip.tm.ltm.traffic_class import Traffic_Class_s
4546
from f5.bigip.tm.ltm.virtual import Virtuals
4647
from f5.bigip.tm.ltm.virtual_address import Virtual_Address_s
4748

@@ -64,6 +65,7 @@ def __init__(self, tm):
6465
Snats,
6566
Snatpools,
6667
Snat_Translations,
68+
Traffic_Class_s,
6769
Virtuals,
6870
Virtual_Address_s,
6971
]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 MissingRequiredCreationParameter
21+
from f5.bigip.tm.ltm.traffic_class import Traffic_Class
22+
23+
24+
@pytest.fixture
25+
def FakeTraffic():
26+
fake_traffic_class_s = mock.MagicMock()
27+
fake_traffic = Traffic_Class(fake_traffic_class_s)
28+
return fake_traffic
29+
30+
31+
class TestCreate(object):
32+
def test_create_two(self, fakeicontrolsession):
33+
mr = ManagementRoot('192.168.1.1', 'admin', 'admin')
34+
t1 = mr.tm.ltm.traffic_class_s.traffic_class
35+
t2 = mr.tm.ltm.traffic_class_s.traffic_class
36+
assert t1 is not t2
37+
38+
def test_create_no_args(self, FakeTraffic):
39+
with pytest.raises(MissingRequiredCreationParameter):
40+
FakeTraffic.create()
41+
42+
def test_create_name(self, FakeTraffic):
43+
with pytest.raises(MissingRequiredCreationParameter):
44+
FakeTraffic.create(name='myname')

f5/bigip/tm/ltm/traffic_class.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2014-2016 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) Traffic Class module.
19+
20+
REST URI
21+
``https://localhost/mgmt/tm/ltm/traffic-class``
22+
23+
GUI Path
24+
``Local Traffic --> Traffic Class``
25+
26+
REST Kind
27+
``tm:ltm:traffic-class:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import Resource
32+
33+
34+
class Traffic_Class_s(Collection):
35+
"""BIG-IP® LTM Traffic Class collection"""
36+
def __init__(self, ltm):
37+
super(Traffic_Class_s, self).__init__(ltm)
38+
self._meta_data['allowed_lazy_attributes'] = [Traffic_Class]
39+
self._meta_data['attribute_registry'] =\
40+
{'tm:ltm:traffic-class:traffic-classstate': Traffic_Class}
41+
42+
43+
class Traffic_Class(Resource):
44+
"""BIG-IP® LTM Traffic Class Resource"""
45+
def __init__(self, traffic_class_s):
46+
super(Traffic_Class, self).__init__(traffic_class_s)
47+
self._meta_data['required_json_kind'] = \
48+
'tm:ltm:traffic-class:traffic-classstate'
49+
self._meta_data['required_creation_parameters'].update((
50+
'classification',))
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2015-2016 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 copy
17+
from pprint import pprint as pp
18+
from six import iteritems
19+
20+
21+
TESTDESCRIPTION = "TESTDESCRIPTION"
22+
23+
24+
def delete_resource(resources):
25+
for resource in resources.get_collection():
26+
resource.delete()
27+
28+
29+
def setup_traffic_test(request, mgmt_root, name, classification):
30+
def teardown():
31+
delete_resource(tc1)
32+
request.addfinalizer(teardown)
33+
tc1 = mgmt_root.tm.ltm.traffic_class_s
34+
pp('****')
35+
traffic1 = tc1.traffic_class.create(name=name,
36+
classification=classification)
37+
return traffic1, tc1
38+
39+
40+
class TestTrafficClass(object):
41+
def test_trafficclass_create_refresh_update_delete_load(
42+
self, request, mgmt_root):
43+
traffic1, tc1 = setup_traffic_test(
44+
request, mgmt_root, 'fake_traffic1', 'fakeclasstag')
45+
assert traffic1.name == 'fake_traffic1'
46+
traffic1.description = TESTDESCRIPTION
47+
traffic1.update()
48+
assert traffic1.description == TESTDESCRIPTION
49+
traffic1.description = ''
50+
traffic1.refresh()
51+
assert traffic1.description == TESTDESCRIPTION
52+
traffic2 = tc1.traffic_class.load(name='fake_traffic1')
53+
assert traffic2.selfLink == traffic1.selfLink
54+
55+
def test_trafficclass_modify(self, request, mgmt_root):
56+
traffic1, tc1 = setup_traffic_test(
57+
request, mgmt_root, 'fake_traffic1', 'fakeclasstag')
58+
original_dict = copy.copy(traffic1.__dict__)
59+
desc = 'description'
60+
traffic1.modify(description='Cool mod test')
61+
for k, v in iteritems(traffic1.__dict__):
62+
if k != desc:
63+
original_dict[k] = traffic1.__dict__[k]
64+
elif k == desc:
65+
assert traffic1.__dict__[k] == 'Cool mod test'

0 commit comments

Comments
 (0)