Skip to content

Commit 9381eb5

Browse files
authored
Merge pull request #1280 from caphrim007/feature.add-trunks-to-sdk
Adds trunk support to the SDK
2 parents fc0a305 + b7cf236 commit 9381eb5

5 files changed

Lines changed: 171 additions & 18 deletions

File tree

f5/bigip/tm/net/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from f5.bigip.tm.net.route import Routes
3636
from f5.bigip.tm.net.route_domain import Route_Domains
3737
from f5.bigip.tm.net.selfip import Selfips
38+
from f5.bigip.tm.net.trunk import Trunks
3839
from f5.bigip.tm.net.tunnels import TunnelS
3940
from f5.bigip.tm.net.vlan import Vlans
4041

@@ -50,6 +51,7 @@ def __init__(self, tm):
5051
Routes,
5152
Route_Domains,
5253
Selfips,
54+
Trunks,
5355
TunnelS,
5456
Vlans
5557
]
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Copyright 2017 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 f5.sdk_exception import MissingRequiredCreationParameter
17+
from pytest import symbols
18+
19+
import os
20+
import pytest
21+
import tempfile
22+
23+
24+
pytestmark = pytest.mark.skipif(
25+
not symbols or
26+
symbols and not hasattr(symbols, 'run_hardware_tests') or
27+
symbols and hasattr(symbols, 'run_hardware_tests') and symbols.modules['run_hardware_tests'] is False,
28+
reason='This series of tests requires a hardware BIG-IP be specified.'
29+
)
30+
31+
32+
@pytest.fixture
33+
def trunk(mgmt_root):
34+
file = tempfile.NamedTemporaryFile()
35+
name = os.path.basename(file.name)
36+
resource = mgmt_root.tm.net.trunks.trunk.create(
37+
name=name
38+
)
39+
yield resource
40+
resource.delete()
41+
42+
43+
@pytest.fixture
44+
def trunks(mgmt_root):
45+
collection = mgmt_root.tm.net.trunks
46+
return collection
47+
48+
49+
class TestResource(object):
50+
def test_get_collection(self, trunk, trunks):
51+
assert len(list(trunks.get_collection())) > 1
52+
53+
def test_create(self, mgmt_root):
54+
file = tempfile.NamedTemporaryFile()
55+
name = os.path.basename(file.name)
56+
resource = mgmt_root.tm.net.trunks.trunk.create(
57+
name=name
58+
)
59+
assert resource.name == name
60+
resource.delete()
61+
62+
def test_update(self, trunk):
63+
"""Test resource updates
64+
65+
Defaults asserted are taken from 13.1.0
66+
67+
:param trunk:
68+
:return:
69+
"""
70+
assert trunk.stp == 'enabled'
71+
assert trunk.lacp == 'disabled'
72+
trunk.lacp = 'enabled'
73+
trunk.stp = 'disabled'
74+
trunk.update()
75+
assert trunk.stp == 'disabled'
76+
assert trunk.lacp == 'enabled'
77+
78+
def test_refresh(self, trunk):
79+
"""Test resource refreshing
80+
81+
Defaults asserted are taken from 13.1.0
82+
83+
:param trunk:
84+
:return:
85+
"""
86+
assert trunk.stp == 'enabled'
87+
trunk.stp = 'disabled'
88+
89+
# A refresh without an update should show no change
90+
trunk.refresh()
91+
assert trunk.stp == 'enabled'
92+
93+
def test_guest_no_creation_args(self, mgmt_root):
94+
with pytest.raises(MissingRequiredCreationParameter) as ex:
95+
mgmt_root.tm.net.trunks.trunk.create()
96+
assert 'name' in str(ex.value)

f5/bigip/tm/net/trunk.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 2017 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® Network trunk module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/net/trunk``
22+
23+
GUI Path
24+
``Network --> Trunks``
25+
26+
REST Kind
27+
``tm:net:trunk:*``
28+
"""
29+
30+
from f5.bigip.mixins import ExclusiveAttributesMixin
31+
from f5.bigip.resource import Collection
32+
from f5.bigip.resource import Resource
33+
34+
35+
class Trunks(Collection):
36+
"""BIG-IP® network route collection"""
37+
def __init__(self, net):
38+
super(Trunks, self).__init__(net)
39+
self._meta_data['allowed_lazy_attributes'] = [Trunk]
40+
self._meta_data['attribute_registry'] = {
41+
'tm:net:trunk:trunkstate': Trunk
42+
}
43+
44+
45+
class Trunk(Resource, ExclusiveAttributesMixin):
46+
def __init__(self, trunks):
47+
super(Trunk, self).__init__(trunks)
48+
self._meta_data['required_json_kind'] = 'tm:net:trunk:trunkstate'
49+
self._meta_data['read_only_attributes'].append(
50+
('network', 'cfgMbrCount', 'workingMbrCount', 'macAddress',
51+
'bandwidth')
52+
)

symbols.example.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ biq_license_pool: XXXXX-XXXXX-XXXXX-XXXXX-XXXXXXX
1919
biq_license_utility: XXXXX-XXXXX-XXXXX-XXXXX-XXXXXXX
2020
biq_license_volume: XXXXX-XXXXX-XXXXX-XXXXX-XXXXXXX
2121

22-
# Tests related to VCMP guests
23-
run_vcmp_tests: true
22+
# Tests related to hardware and VCMP guests
23+
run_vcmp_tests: false
24+
vcmp_host: 1.1.1.1
25+
run_hardware_tests: false

tox.ini

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[tox]
22
envlist =
3-
py{27,35}-bip-v{11.5.4,11.6.0,11.6.1,12.0.0,12.1.0,12.1.1,12.1.2,13.0.0,13.1.0}
4-
py{27,35}-biq-v{5.1.0,5.2.0,5.3.0}
5-
py{27,35}-iwf-v{2.1.0}
3+
py{27,35,36}-bip-v{11.5.4,11.6.0,11.6.1,12.0.0,12.1.0,12.1.1,12.1.2,13.0.0,13.1.0}
4+
py{27,35,36}-biq-v{5.1.0,5.2.0,5.3.0}
5+
py{27,35,36}-iwf-v{2.1.0}
66
unit
77
flake
88
pycodestyle
@@ -14,6 +14,7 @@ envbindir = /Users/trupp/src/envs/pycharm/bin/
1414
basepython =
1515
py27: python2.7
1616
py35: python3.5
17+
py36: python3.6
1718
unit: python
1819
flake: python
1920
pycodestyle: python
@@ -30,23 +31,23 @@ whitelist_externals=*
3031

3132
commands =
3233
# BIG-IP tests
33-
py{27,35}-bip-v11.5.4: py.test --bigip localhost --port 10443 -s -vv --release 11.5.4 {posargs:f5/bigip}
34-
py{27,35}-bip-v11.6.0: py.test --bigip localhost --port 10443 -s -vv --release 11.6.0 {posargs:f5/bigip}
35-
py{27,35}-bip-v11.6.1: py.test --bigip localhost --port 10443 -s -vv --release 11.6.1 {posargs:f5/bigip}
36-
py{27,35}-bip-v12.0.0: py.test --bigip localhost --port 10443 -s -vv --release 12.0.0 {posargs:f5/bigip}
37-
py{27,35}-bip-v12.1.0: py.test --bigip localhost --port 10443 -s -vv --release 12.1.0 {posargs:f5/bigip}
38-
py{27,35}-bip-v12.1.1: py.test --bigip localhost --port 10443 -s -vv --release 12.1.1 {posargs:f5/bigip}
39-
py{27,35}-bip-v12.1.2: py.test --bigip localhost --port 10443 -s -vv --release 12.1.2 {posargs:f5/bigip}
40-
py{27,35}-bip-v13.0.0: py.test --bigip localhost --port 10443 -s -vv --release 13.0.0 {posargs:f5/bigip}
41-
py{27,35}-bip-v13.1.0: py.test --bigip localhost --port 10443 -s -vv --release 13.1.0 {posargs:f5/bigip}
34+
py{27,35,36}-bip-v11.5.4: py.test --bigip localhost --port 10443 -s -vv --release 11.5.4 {posargs:f5/bigip}
35+
py{27,35,36}-bip-v11.6.0: py.test --bigip localhost --port 10443 -s -vv --release 11.6.0 {posargs:f5/bigip}
36+
py{27,35,36}-bip-v11.6.1: py.test --bigip localhost --port 10443 -s -vv --release 11.6.1 {posargs:f5/bigip}
37+
py{27,35,36}-bip-v12.0.0: py.test --bigip localhost --port 10443 -s -vv --release 12.0.0 {posargs:f5/bigip}
38+
py{27,35,36}-bip-v12.1.0: py.test --bigip localhost --port 10443 -s -vv --release 12.1.0 {posargs:f5/bigip}
39+
py{27,35,36}-bip-v12.1.1: py.test --bigip localhost --port 10443 -s -vv --release 12.1.1 {posargs:f5/bigip}
40+
py{27,35,36}-bip-v12.1.2: py.test --bigip localhost --port 10443 -s -vv --release 12.1.2 {posargs:f5/bigip}
41+
py{27,35,36}-bip-v13.0.0: py.test --bigip localhost --port 10443 -s -vv --release 13.0.0 {posargs:f5/bigip}
42+
py{27,35,36}-bip-v13.1.0: py.test --bigip localhost --port 10443 -s -vv --release 13.1.0 {posargs:f5/bigip}
4243

4344
# BIG-IQ tests
44-
py{27,35}-biq-v5.1.0: py.test --bigip localhost --port 10443 -s -vv --release 5.1.0 {posargs:f5/bigiq}
45-
py{27,35}-biq-v5.2.0: py.test --bigip localhost --port 10443 -s -vv --release 5.2.0 {posargs:f5/bigiq}
46-
py{27,35}-biq-v5.3.0: py.test --bigip localhost --port 10443 -s -vv --release 5.3.0 {posargs:f5/bigiq}
45+
py{27,35,36}-biq-v5.1.0: py.test --bigip localhost --port 10443 -s -vv --release 5.1.0 {posargs:f5/bigiq}
46+
py{27,35,36}-biq-v5.2.0: py.test --bigip localhost --port 10443 -s -vv --release 5.2.0 {posargs:f5/bigiq}
47+
py{27,35,36}-biq-v5.3.0: py.test --bigip localhost --port 10443 -s -vv --release 5.3.0 {posargs:f5/bigiq}
4748

4849
# iWorkflow tests
49-
py{27,35}-iwf-v2.1.0: py.test --bigip localhost --port 10443 -s -vv --release 2.1.0 {posargs:f5/iworkflow}
50+
py{27,35,36}-iwf-v2.1.0: py.test --bigip localhost --port 10443 -s -vv --release 2.1.0 {posargs:f5/iworkflow}
5051

5152
# Misc tests
5253
unit: pytest -k "not /functional/" -vv --cov {posargs:f5/}

0 commit comments

Comments
 (0)