Skip to content

Commit 1489803

Browse files
wojtek0806caphrim007
authored andcommitted
Add Stats attribute to https profile endpoint (#1441)
Add HostInfo endpoint Add Disk endpoint Add corresponding unit and functional tests Corrected flake8 errors
1 parent 58a5733 commit 1489803

11 files changed

Lines changed: 337 additions & 3 deletions

File tree

f5/bigip/tm/ltm/profile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from f5.bigip.resource import Collection
3131
from f5.bigip.resource import OrganizingCollection
3232
from f5.bigip.resource import Resource
33+
from f5.bigip.resource import Stats
3334
from f5.sdk_exception import MissingUpdateParameter
3435
from f5.sdk_exception import UnsupportedOperation
3536

@@ -443,7 +444,7 @@ class Https(Collection):
443444
"""BIG-IP® Http profile collection."""
444445
def __init__(self, profile):
445446
super(Https, self).__init__(profile)
446-
self._meta_data['allowed_lazy_attributes'] = [Http]
447+
self._meta_data['allowed_lazy_attributes'] = [Http, Stats]
447448
self._meta_data['attribute_registry'] = \
448449
{'tm:ltm:profile:http:httpstate': Http}
449450

f5/bigip/tm/ltm/test/functional/test_lsnpool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def test_create_with_logProfile(self, request, mgmt_root):
125125
name='lsnlogpool1')
126126

127127
setup_create_test(request, mgmt_root, 'lsnpool1')
128+
128129
default_pub = '/Common/local-db-publisher'
129130
pool1 = mgmt_root.tm.ltm.lsn_pools.lsn_pool.create(name='lsnpool1',
130131
logProfile=logprofile1.name,

f5/bigip/tm/ltm/test/functional/test_profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626

2727
# Helper class to limit code repetition
2828
class HelperTest(object):
29-
def __init__(self, collection_name):
29+
def __init__(self, collection_name, **kwargs):
3030
self.partition = 'Common'
3131
self.lowered = collection_name.lower()
3232
self.test_name = 'test.' + self.urielementname()
33+
self.stats = kwargs.pop('stats', False)
3334

3435
def urielementname(self):
3536
if self.lowered[-2:] == '_s':
@@ -479,7 +480,6 @@ def test_MCURDL(self, request, mgmt_root):
479480
http = HelperTest('Https')
480481
http.test_MCURDL(request, mgmt_root)
481482

482-
483483
# End HTTP tests
484484

485485
# Begin HTTP Compression tests

f5/bigip/tm/sys/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
from f5.bigip.tm.sys.crypto import Crypto
3636
from f5.bigip.tm.sys.daemon_log_settings import Daemon_Log_Settings
3737
from f5.bigip.tm.sys.db import Dbs
38+
from f5.bigip.tm.sys.disk import Disk
3839
from f5.bigip.tm.sys.dns import Dns
3940
from f5.bigip.tm.sys.failover import Failover
4041
from f5.bigip.tm.sys.feature_module import Feature_Module
4142
from f5.bigip.tm.sys.file import File
4243
from f5.bigip.tm.sys.folder import Folders
4344
from f5.bigip.tm.sys.global_settings import Global_Settings
45+
from f5.bigip.tm.sys.host_info import Host_Info
4446
from f5.bigip.tm.sys.httpd import Httpd
4547
from f5.bigip.tm.sys.icall import Icall
4648
from f5.bigip.tm.sys.license import License
@@ -78,10 +80,12 @@ def __init__(self, tm):
7880
File,
7981
Folders,
8082
Global_Settings,
83+
Host_Info,
8184
Httpd,
8285
Icall,
8386
License,
8487
Log_Config,
88+
Disk,
8589
Management_Ips,
8690
Management_Routes,
8791
Ntp,

f5/bigip/tm/sys/disk.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 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® system disk module.
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/sys/disk/*``
22+
23+
GUI Path
24+
``System --> Disk Management --> *``
25+
26+
REST Kind
27+
``tm:sys:disk:*``
28+
"""
29+
30+
from f5.bigip.resource import Collection
31+
from f5.bigip.resource import OrganizingCollection
32+
from f5.bigip.resource import Resource
33+
from f5.sdk_exception import UnsupportedMethod
34+
35+
36+
class Disk(OrganizingCollection):
37+
def __init__(self, sys):
38+
super(Disk, self).__init__(sys)
39+
self._meta_data['allowed_lazy_attributes'] = [
40+
Logical_Disks,
41+
]
42+
43+
44+
class Directory(object):
45+
"""Directory stats class, has 2 endpoints producing the same output:
46+
47+
"https://localhost/mgmt/tm/sys/disk/directory" and
48+
49+
"https://localhost/mgmt/tm/sys/disk/directory/stats/"
50+
51+
This will require careful thought on the implementation. This is a placeholder for future
52+
"""
53+
pass
54+
55+
56+
class Application_Volume(object):
57+
"""Placeholder for another endpoint"""
58+
pass
59+
60+
61+
class Logical_Disks(Collection):
62+
"""BIG-IP® system logical disk collection"""
63+
def __init__(self, sys):
64+
super(Logical_Disks, self).__init__(sys)
65+
self._meta_data['object_has_stats'] = False
66+
self._meta_data['attribute_registry'] = \
67+
{'tm:sys:disk:logical-disk:logical-diskstate': Logical_Disk}
68+
self._meta_data['allowed_lazy_attributes'] = [Logical_Disk]
69+
70+
71+
class Logical_Disk(Resource):
72+
"""BIG-IP® system logical disk unnamed resource"""
73+
def __init__(self, logical_disks):
74+
super(Logical_Disk, self).__init__(logical_disks)
75+
self._meta_data['required_json_kind'] =\
76+
'tm:sys:disk:logical-disk:logical-diskstate'
77+
78+
def update(self, **kwargs):
79+
"""Update is not supported for logical disk.
80+
81+
:raises: :exc:`~f5.BIG-IP.resource.UnsupportedMethod`
82+
"""
83+
raise UnsupportedMethod("{0} does not support the update method, only load and refresh".format(self.__class__.__name__))
84+
85+
def create(self, **kwargs):
86+
"""Create is not supported for logical disk.
87+
88+
:raises: :exc:`~f5.BIG-IP.resource.UnsupportedMethod`
89+
"""
90+
raise UnsupportedMethod("{0} does not support the create method, only load and refresh".format(self.__class__.__name__))
91+
92+
def modify(self, **kwargs):
93+
"""Modify is not supported for logical disk.
94+
95+
:raises: :exc:`~f5.BIG-IP.resource.UnsupportedMethod`
96+
"""
97+
raise UnsupportedMethod("{0} does not support the modify method, only load and refresh".format(self.__class__.__name__))
98+
99+
def delete(self, **kwargs):
100+
"""Delete is not supported for logical disk.
101+
102+
:raises: :exc:`~f5.BIG-IP.resource.UnsupportedMethod``
103+
"""
104+
raise UnsupportedMethod("{0} does not support the delete method, only load and refresh".format(self.__class__.__name__))

f5/bigip/tm/sys/host_info.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# coding=utf-8
2+
#
3+
# Copyright 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® system host-info module
19+
20+
REST URI
21+
``http://localhost/mgmt/tm/sys/host-info``
22+
23+
REST Kind
24+
``tm:sys:host-info:host-infostats:*``
25+
"""
26+
27+
from f5.bigip.resource import UnnamedResource
28+
from f5.sdk_exception import UnsupportedMethod
29+
30+
31+
class Host_Info(UnnamedResource):
32+
"""BIG-IP® system host info unnamed resource"""
33+
def __init__(self, sys):
34+
super(Host_Info, self).__init__(sys)
35+
self._meta_data['object_has_stats'] = False
36+
self._meta_data['required_load_parameters'] = set()
37+
self._meta_data['required_json_kind'] =\
38+
'tm:sys:host-info:host-infostats'
39+
40+
def update(self, **kwargs):
41+
"""Update is not supported for host info
42+
43+
:raises: :exc:`~f5.BIG-IP.resource.UnsupportedMethod`
44+
"""
45+
raise UnsupportedMethod("{0} does not support the update method, only load and refresh".format(self.__class__.__name__))

f5/bigip/tm/sys/test/functional/test_application.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
'presentation': ''
3131
}
3232

33+
3334
definition = {'definition': sections}
3435

3536

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2018 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.bigip.tm.sys.disk import Logical_Disk
17+
18+
import pytest
19+
from requests import HTTPError
20+
21+
22+
class TestLogicalDisk(object):
23+
def test_load_refresh(self, mgmt_root):
24+
d1 = mgmt_root.tm.sys.disk.logical_disks.logical_disk.load(name='HD1')
25+
assert d1.name == 'HD1'
26+
assert d1.kind == 'tm:sys:disk:logical-disk:logical-diskstate'
27+
assert d1.mode == 'mixed'
28+
29+
d2 = mgmt_root.tm.sys.disk.logical_disks.logical_disk.load(name='HD1')
30+
assert d2.name == d1.name
31+
assert d2.kind == d1.kind
32+
assert d2.mode == d1.mode
33+
34+
d1.refresh()
35+
assert d1.name == d2.name
36+
assert d1.kind == d2.kind
37+
assert d1.mode == d2.mode
38+
39+
def test_load_no_object(self, mgmt_root):
40+
rc = mgmt_root.tm.sys.disk.logical_disks
41+
with pytest.raises(HTTPError) as err:
42+
rc.logical_disk.load(name='not_exists')
43+
assert err.value.response.status_code == 404
44+
45+
def test_logical_disks_collection(self, mgmt_root):
46+
rc = mgmt_root.tm.sys.disk.logical_disks.get_collection()
47+
assert isinstance(rc, list)
48+
assert len(rc)
49+
assert isinstance(rc[0], Logical_Disk)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2018 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.bigip.tm.sys.host_info import Host_Info
17+
18+
19+
class TestHostInfo(object):
20+
def test_load_refresh(self, mgmt_root):
21+
h1 = mgmt_root.tm.sys.host_info.load()
22+
assert isinstance(h1, Host_Info)
23+
assert hasattr(h1, 'entries')
24+
assert h1.kind == 'tm:sys:host-info:host-infostats'
25+
assert 'https://localhost/mgmt/tm/sys/host-info/0' in h1.entries.keys()
26+
27+
h2 = mgmt_root.tm.sys.host_info.load()
28+
29+
assert isinstance(h2, Host_Info)
30+
assert hasattr(h2, 'entries')
31+
assert h2.kind == 'tm:sys:host-info:host-infostats'
32+
assert 'https://localhost/mgmt/tm/sys/host-info/0' in h2.entries.keys()
33+
34+
h1.refresh()
35+
36+
assert h1.kind == h2.kind
37+
assert h1.entries.keys() == h2.entries.keys()
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2018 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+
17+
import mock
18+
import pytest
19+
20+
from f5.bigip import ManagementRoot
21+
from f5.bigip.resource import OrganizingCollection
22+
from f5.bigip.tm.sys.disk import Logical_Disk
23+
from f5.sdk_exception import UnsupportedMethod
24+
25+
26+
@pytest.fixture
27+
def fake_disk():
28+
fake_oc = mock.MagicMock()
29+
return Logical_Disk(fake_oc)
30+
31+
32+
class TestDiskOC(object):
33+
def test_oc(self, fakeicontrolsession):
34+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
35+
d1 = b.tm.sys.disk
36+
assert isinstance(d1, OrganizingCollection)
37+
assert hasattr(d1, 'logical_disks')
38+
39+
40+
class TestLogicalDisk(object):
41+
def test_logical_disk_update_raises(self, fake_disk):
42+
with pytest.raises(UnsupportedMethod) as EIO:
43+
fake_disk.update()
44+
assert str(EIO.value) == "Logical_Disk does not support the update method, only load and refresh"
45+
46+
def test_logical_disk_create_raises(self, fake_disk):
47+
with pytest.raises(UnsupportedMethod) as EIO:
48+
fake_disk.create()
49+
assert str(EIO.value) == "Logical_Disk does not support the create method, only load and refresh"
50+
51+
def test_logical_disk_modify_raises(self, fake_disk):
52+
with pytest.raises(UnsupportedMethod) as EIO:
53+
fake_disk.modify()
54+
assert str(EIO.value) == "Logical_Disk does not support the modify method, only load and refresh"
55+
56+
def test_logical_disk_delete_raises(self, fake_disk):
57+
with pytest.raises(UnsupportedMethod) as EIO:
58+
fake_disk.delete()
59+
assert str(EIO.value) == "Logical_Disk does not support the delete method, only load and refresh"

0 commit comments

Comments
 (0)