Skip to content

Commit 15bf328

Browse files
authored
Merge pull request #1489 from sangramaltur/resetstats
Unable to reset nat translation stats
2 parents 89428a4 + 3099424 commit 15bf328

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

f5/bigip/tm/security/nat.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
``tm:security:nat:*``
2828
"""
2929
from f5.bigip.mixins import CheckExistenceMixin
30+
from f5.bigip.mixins import CommandExecutionMixin
3031
from f5.bigip.resource import Collection
3132
from f5.bigip.resource import OrganizingCollection
3233
from f5.bigip.resource import Resource
@@ -99,7 +100,7 @@ def exists(self, **kwargs):
99100
return super(Rule, self)._load(**kwargs)
100101

101102

102-
class Source_Translations(Collection):
103+
class Source_Translations(Collection, CommandExecutionMixin):
103104
"""BIG-IP® AFM® Nat Source Translation collection"""
104105

105106
def __init__(self, nat):
@@ -108,9 +109,10 @@ def __init__(self, nat):
108109
self._meta_data['attribute_registry'] = \
109110
{'tm:security:nat:source-translation:source-translationstate':
110111
Source_Translation}
112+
self._meta_data['allowed_commands'].append('reset-stats')
111113

112114

113-
class Source_Translation(Resource):
115+
class Source_Translation(Resource, CommandExecutionMixin):
114116
def __init__(self, source_translations):
115117
super(Source_Translation, self).__init__(source_translations)
116118
self._meta_data['required_json_kind'] = \
@@ -119,9 +121,10 @@ def __init__(self, source_translations):
119121
('partition',))
120122
self._meta_data['required_load_parameters'].update(
121123
('partition',))
124+
self._meta_data['allowed_commands'].append('reset-stats')
122125

123126

124-
class Destination_Translations(Collection):
127+
class Destination_Translations(Collection, CommandExecutionMixin):
125128
"""BIG-IP® AFM® Nat Destination Translation collection"""
126129

127130
def __init__(self, nat):
@@ -130,9 +133,10 @@ def __init__(self, nat):
130133
self._meta_data['attribute_registry'] = \
131134
{'tm:security:nat:destination-translation:destination-translationstate':
132135
Destination_Translation}
136+
self._meta_data['allowed_commands'].append('reset-stats')
133137

134138

135-
class Destination_Translation(Resource):
139+
class Destination_Translation(Resource, CommandExecutionMixin):
136140
def __init__(self, destination_translations):
137141
super(Destination_Translation, self).__init__(destination_translations)
138142
self._meta_data['required_json_kind'] = \
@@ -141,6 +145,7 @@ def __init__(self, destination_translations):
141145
('partition',))
142146
self._meta_data['required_load_parameters'].update(
143147
('partition',))
148+
self._meta_data['allowed_commands'].append('reset-stats')
144149

145150

146151
class Policy_s(Collection):

f5/bigip/tm/security/test/functional/test_nat.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ def test_src_translation_collection(self, mgmt_root, srctranslation):
158158
assert len(src)
159159
assert isinstance(src[0], Source_Translation)
160160

161+
def test_src_translation_collection_reset_stats(self, mgmt_root):
162+
src_coll = mgmt_root.tm.security.nat.source_translations
163+
src_coll_reset_stats = src_coll.exec_cmd('reset-stats')
164+
assert src_coll_reset_stats.command == 'reset-stats'
165+
assert src_coll_reset_stats.kind == 'tm:security:nat:source-translation:reset-statsstate'
166+
167+
def test_src_translation_reset_stats(self, mgmt_root, srctranslation):
168+
s1 = srctranslation
169+
assert s1.name == 'fake_src'
170+
assert s1.partition == 'Common'
171+
src_coll = mgmt_root.tm.security.nat.source_translations
172+
src_coll_reset_stats = src_coll.exec_cmd('reset-stats', name='fake_src')
173+
assert src_coll_reset_stats.command == 'reset-stats'
174+
assert src_coll_reset_stats.kind == 'tm:security:nat:source-translation:reset-statsstate'
175+
assert src_coll_reset_stats.name == s1.name
176+
161177

162178
@pytest.mark.skipif(
163179
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('12.1.0'),
@@ -264,6 +280,22 @@ def test_dst_translation_collection(self, mgmt_root, dsttranslation):
264280
assert len(dst)
265281
assert isinstance(dst[0], Destination_Translation)
266282

283+
def test_dst_translation_collection_reset_stats(self, mgmt_root):
284+
dst_coll = mgmt_root.tm.security.nat.destination_translations
285+
dst_coll_reset_stats = dst_coll.exec_cmd('reset-stats')
286+
assert dst_coll_reset_stats.command == 'reset-stats'
287+
assert dst_coll_reset_stats.kind == 'tm:security:nat:destination-translation:reset-statsstate'
288+
289+
def test_dst_translation_reset_stats(self, mgmt_root, dsttranslation):
290+
d1 = dsttranslation
291+
assert d1.name == 'fake_dst'
292+
assert d1.partition == 'Common'
293+
dst_coll = mgmt_root.tm.security.nat.destination_translations
294+
dst_coll_reset_stats = dst_coll.exec_cmd('reset-stats', name='fake_dst')
295+
assert dst_coll_reset_stats.command == 'reset-stats'
296+
assert dst_coll_reset_stats.kind == 'tm:security:nat:destination-translation:reset-statsstate'
297+
assert dst_coll_reset_stats.name == d1.name
298+
267299

268300
@pytest.mark.skipif(
269301
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('12.1.0'),

f5/bigip/tm/security/test/unit/test_nat.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from f5.bigip.tm.security.nat import Rule
2323
from f5.bigip.tm.security.nat import Rules_s
2424
from f5.bigip.tm.security.nat import Source_Translation
25+
from f5.sdk_exception import InvalidCommand
2526
from f5.sdk_exception import MissingRequiredCreationParameter
2627

2728
from six import iterkeys
@@ -60,7 +61,7 @@ def MakeSrcTranslation(fakeicontrolsession):
6061
p = a.tm.security.nat.source_translations.source_translation
6162
p._meta_data['uri'] = \
6263
'https://192.168.1.1:443/mgmt/tm/security/nat/source-translation/~Common' \
63-
'~testsrctranslatiom/'
64+
'~testsrctranslation/'
6465
return p
6566

6667

@@ -102,6 +103,11 @@ def test_create_mandatory_args_missing(self, fakeicontrolsession):
102103
b.tm.security.nat.source_translations.source_translation.create(
103104
name='destined_to_fail')
104105

106+
def test_invalid_cmd(self, FakeSrcTranslation):
107+
FakeSrcTranslation._meta_data['tmos_version'] = '12.1.0'
108+
with pytest.raises(InvalidCommand):
109+
FakeSrcTranslation.exec_cmd('restart', name='fake_src')
110+
105111

106112
class TestDstTranslation(object):
107113
def test_create_two(self, fakeicontrolsession):
@@ -122,6 +128,11 @@ def test_create_mandatory_args_missing(self, fakeicontrolsession):
122128
b.tm.security.nat.destination_translations.destination_translation.create(
123129
name='destined_to_fail')
124130

131+
def test_invalid_cmd(self, FakeDstTranslation):
132+
FakeDstTranslation._meta_data['tmos_version'] = '12.1.0'
133+
with pytest.raises(InvalidCommand):
134+
FakeDstTranslation.exec_cmd('restart', name='fake_dst')
135+
125136

126137
class TestPolicy(object):
127138
def test_create_two(self, fakeicontrolsession):

0 commit comments

Comments
 (0)