Skip to content

Commit a4551d5

Browse files
Sangram Reddy AlthurSangram Reddy Althur
authored andcommitted
Unable to restart big ip tmm service , Minimum version 13.0.0
Issues:Unable to restart big ip tmm service Fixes #<1481> Problem:sdk doesnt have the support to restart tmm service Analysis: added new file service along with support for tmm modified: f5/bigip/tm/sys/__init__.py new file: f5/bigip/tm/sys/service.py Tests: Ran the following tests new file: f5/bigip/tm/sys/test/functional/test_service.py new file: f5/bigip/tm/sys/test/unit/test_service.py
1 parent fb001e9 commit a4551d5

4 files changed

Lines changed: 177 additions & 0 deletions

File tree

f5/bigip/tm/sys/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from f5.bigip.tm.sys.ntp import Ntp
5656
from f5.bigip.tm.sys.performance import Performances
5757
from f5.bigip.tm.sys.provision import Provision
58+
from f5.bigip.tm.sys.service import Service
5859
from f5.bigip.tm.sys.sflow import Sflow
5960
from f5.bigip.tm.sys.smtp_server import Smtp_Servers
6061
from f5.bigip.tm.sys.snmp import Snmp
@@ -97,6 +98,7 @@ def __init__(self, tm):
9798
Ntp,
9899
Performances,
99100
Provision,
101+
Service,
100102
Sflow,
101103
Smtp_Servers,
102104
Snmp,

f5/bigip/tm/sys/service.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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/service``
22+
23+
GUI Path
24+
N/A
25+
26+
REST Kind
27+
``tm:sys:service:*``
28+
"""
29+
30+
from f5.bigip.mixins import CommandExecutionMixin
31+
from f5.bigip.resource import OrganizingCollection
32+
from f5.bigip.resource import UnnamedResource
33+
from f5.sdk_exception import UnsupportedMethod
34+
35+
36+
class Service(OrganizingCollection):
37+
def __init__(self, sys):
38+
super(Service, self).__init__(sys)
39+
self._meta_data['allowed_lazy_attributes'] = [Tmm]
40+
41+
42+
class Tmm(UnnamedResource,
43+
CommandExecutionMixin):
44+
"""BIG-IP® system tmm service
45+
46+
.. note::
47+
This is an unnamed resource so it has not ~Partition~Name pattern
48+
at the end of its URI.
49+
"""
50+
def __init__(self, service):
51+
super(Tmm, self).__init__(service)
52+
self._meta_data['allowed_commands'].append('restart')
53+
self._meta_data['minimum_version'] = '13.0.0'
54+
self._meta_data['required_json_kind'] =\
55+
'tm:sys:service:servicestate'
56+
57+
def update(self, **kwargs):
58+
"""Update is not supported
59+
60+
:raises: UnsupportedMethod
61+
"""
62+
raise UnsupportedMethod(
63+
"%s does not support the update method" % self.__class__.__name__
64+
)
65+
66+
def modify(self, **kwargs):
67+
"""Update is not supported
68+
69+
:raises: UnsupportedMethod
70+
"""
71+
raise UnsupportedMethod(
72+
"%s does not support the modify method" % self.__class__.__name__
73+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 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+
from f5.multi_device.utils import get_device_info
17+
from f5.multi_device.utils import pollster
18+
19+
import pytest
20+
21+
22+
def get_activation_state(device):
23+
'''Get the activation state for a device.'''
24+
25+
device_name = get_device_info(device).name
26+
act = device.tm.cm.devices.device.load(
27+
name=device_name,
28+
partition='Common'
29+
)
30+
return act.failoverState
31+
32+
33+
def check_device_state_as_expected(device, expected_state):
34+
assert get_activation_state(device).lower() == expected_state.lower()
35+
36+
37+
@pytest.mark.skipif(
38+
pytest.config.getoption('--release') < '13.0.0',
39+
reason='This test will fail below 13.0.0'
40+
)
41+
class TestServiceTmm(object):
42+
def test_restart_service_tmm(self, mgmt_root):
43+
# restart
44+
tmm = mgmt_root.tm.sys.service.tmm.load()
45+
tmm_restart = tmm.exec_cmd('restart')
46+
assert tmm_restart.command == 'restart'
47+
get_activation_state(mgmt_root)
48+
# Use the pollster to check for expected state. The pollster uses
49+
# a method which checks for any exception. If one is found, it keeps
50+
# trying.
51+
# Check if forced to offline
52+
pollster(check_device_state_as_expected)(mgmt_root, 'offline')
53+
# Check if device is active
54+
pollster(check_device_state_as_expected)(mgmt_root, 'active')
55+
56+
def test_load_service_tmm(self, mgmt_root):
57+
# Load
58+
tmm = mgmt_root.tm.sys.service.tmm.load()
59+
URI = 'https://localhost/mgmt/tm/sys/service/tmm'
60+
assert tmm.name == 'tmm'
61+
assert tmm.selfLink.startswith(URI)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 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+
from f5.bigip import ManagementRoot
17+
from f5.sdk_exception import InvalidCommand
18+
from f5.sdk_exception import UnsupportedMethod
19+
20+
21+
import pytest
22+
23+
24+
class TestServiceTmm(object):
25+
def test_update_raises(self, fakeicontrolsession):
26+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
27+
b._meta_data['tmos_version'] = '13.0.0'
28+
with pytest.raises(UnsupportedMethod):
29+
b.tm.sys.service.tmm.update()
30+
31+
def test_modify_raises(self, fakeicontrolsession):
32+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
33+
b._meta_data['tmos_version'] = '13.0.0'
34+
with pytest.raises(UnsupportedMethod):
35+
b.tm.sys.service.tmm.modify()
36+
37+
def test_invalid_cmd(self, fakeicontrolsession):
38+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
39+
b._meta_data['tmos_version'] = '13.0.0'
40+
with pytest.raises(InvalidCommand):
41+
b.tm.sys.service.tmm.exec_cmd('reset')

0 commit comments

Comments
 (0)