Skip to content

Commit eaf0985

Browse files
committed
Added Protocol Inspection analytics
1 parent 6e29ba1 commit eaf0985

4 files changed

Lines changed: 296 additions & 0 deletions

File tree

f5/bigip/tm/analytics/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from f5.bigip.resource import OrganizingCollection
3131
from f5.bigip.tm.analytics.dos_vis_common import Dos_Vis_Common
32+
from f5.bigip.tm.analytics.protocol_inspection import Protocol_Inspection
3233

3334

3435
class Analytics(OrganizingCollection):
@@ -41,4 +42,5 @@ def __init__(self, tm):
4142
super(Analytics, self).__init__(tm)
4243
self._meta_data['allowed_lazy_attributes'] = [
4344
Dos_Vis_Common,
45+
Protocol_Inspection
4446
]
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
2+
# coding=utf-8
3+
#
4+
# Copyright 2018 F5 Networks Inc.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
""" BIG-IP® Application Visibility and Reporting™ (AVR®) Protocol Inspection sub-module.
20+
REST URI
21+
``http://localhost/mgmt/tm/analytics/protocol-inspection/``
22+
GUI Path
23+
``Security --> Reporting --> Protocol Inspection``
24+
REST Kind
25+
``tm:analytics:protocol-inspection:``
26+
"""
27+
from f5.bigip.resource import AsmResource as AvrResource
28+
from f5.bigip.resource import Collection
29+
from f5.bigip.resource import OrganizingCollection
30+
from f5.sdk_exception import UnsupportedOperation
31+
32+
33+
class Protocol_Inspection(OrganizingCollection):
34+
"""BIG-IP® AVR protocol inspection organizing collection."""
35+
def __init__(self, analytics):
36+
super(Protocol_Inspection, self).__init__(analytics)
37+
self._meta_data['object_has_stats'] = False
38+
self._meta_data['allowed_lazy_attributes'] = [
39+
Generate_Reports,
40+
Report_Results_s,
41+
]
42+
43+
44+
class Generate_Reports(Collection):
45+
"""BIG-IP® AVR Generate Report Collection."""
46+
def __init__(self, protocol_inspection):
47+
super(Generate_Reports, self).__init__(protocol_inspection)
48+
self._meta_data['object_has_stats'] = False
49+
self._meta_data['allowed_lazy_attributes'] = [Generate_Report]
50+
self._meta_data['attribute_registry'] = {
51+
'tm:analytics:protocol-inspection:generate-report:avrgeneratereporttaskitemstate': Generate_Report}
52+
53+
54+
class Generate_Report(AvrResource):
55+
"""BIG-IP® AVR Generate Report Resource."""
56+
def __init__(self, generate_reports):
57+
super(Generate_Report, self).__init__(generate_reports)
58+
self._meta_data['required_json_kind'] =\
59+
'tm:analytics:protocol-inspection:generate-report:avrgeneratereporttaskitemstate'
60+
self._meta_data['required_creation_parameters'] = {'viewDimensions',
61+
'reportFeatures',
62+
}
63+
64+
def modify(self, **kwargs):
65+
"""Modify is not supported for Generate Report resource :raises: UnsupportedOperation"""
66+
raise UnsupportedOperation(
67+
"%s does not support the modify method" % self.__class__.__name__
68+
)
69+
70+
71+
class Report_Results_s(Collection):
72+
"""BIG-IP® AVR Report Results Collection."""
73+
def __init__(self, protocol_inspection):
74+
super(Report_Results_s, self).__init__(protocol_inspection)
75+
self._meta_data['object_has_stats'] = False
76+
self._meta_data['allowed_lazy_attributes'] = [Report_Results]
77+
self._meta_data['attribute_registry'] = {
78+
'tm:analytics:protocol-inspection:report-results:avrreportresultitemstate':
79+
Report_Results}
80+
81+
82+
class Report_Results(AvrResource):
83+
"""BIG-IP® AVR Report Results Resource."""
84+
def __init__(self, report_results_s):
85+
super(Report_Results, self).__init__(report_results_s)
86+
self._meta_data['required_json_kind'] =\
87+
'tm:analytics:protocol-inspection:report-results:avrreportresultitemstate'
88+
89+
def create(self, **kwargs):
90+
"""Create is not supported for Report Results resource :raises: UnsupportedOperation"""
91+
raise UnsupportedOperation(
92+
"%s does not support the create method" % self.__class__.__name__
93+
)
94+
95+
def modify(self, **kwargs):
96+
"""Modify is not supported for Report Results resource :raises: UnsupportedOperation"""
97+
raise UnsupportedOperation(
98+
"%s does not support the modify method" % self.__class__.__name__
99+
)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
import pytest
17+
import time
18+
19+
from distutils.version import LooseVersion
20+
from f5.bigip.tm.analytics.protocol_inspection import Generate_Report
21+
from f5.bigip.tm.analytics.protocol_inspection import Report_Results
22+
23+
24+
@pytest.fixture(scope='function')
25+
def generate_report(mgmt_root):
26+
task = mgmt_root.tm.analytics.protocol_inspection.generate_reports.generate_report.create(
27+
reportFeatures=['entities-count'],
28+
viewDimensions=[{'dimensionName': 'profile'}],
29+
)
30+
while True:
31+
task.refresh()
32+
if task.status in ['FINISHED', 'FAILURE']:
33+
break
34+
time.sleep(1)
35+
yield task
36+
task.delete()
37+
38+
39+
@pytest.fixture(scope='function')
40+
def get_reports(mgmt_root):
41+
task = mgmt_root.tm.analytics.protocol_inspection.generate_reports.load()
42+
while True:
43+
task.refresh()
44+
if task.status in ['FINISHED', 'FAILURE']:
45+
break
46+
time.sleep(1)
47+
yield task
48+
task.delete()
49+
50+
51+
@pytest.mark.skipif(
52+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
53+
reason='Generating a report returns an unexpected error in 13.0.0.'
54+
)
55+
class TestGenerateReport(object):
56+
def test_create_rep_arg(self, generate_report):
57+
rep1 = generate_report
58+
endpoint = str(rep1.id)
59+
base_uri = 'https://localhost/mgmt/tm/analytics/protocol-inspection/generate-report/'
60+
final_uri = base_uri + endpoint
61+
assert rep1.selfLink.startswith(final_uri)
62+
assert rep1.kind == 'tm:analytics:protocol-inspection:generate-report:avrgeneratereporttaskitemstate'
63+
64+
65+
@pytest.mark.skipif(
66+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
67+
reason='Generating a report returns an unexpected error in 13.0.0.'
68+
)
69+
class TestGenerateReportCollection(object):
70+
def test_collection_gen_rep(self, generate_report, mgmt_root):
71+
rep1 = generate_report
72+
reports = mgmt_root.tm.analytics.protocol_inspection.generate_reports.get_collection()
73+
assert isinstance(reports[0], Generate_Report)
74+
assert rep1.id in [report.id for report in reports]
75+
76+
77+
@pytest.mark.skipif(
78+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
79+
reason='Generating a report returns an unexpected error in 13.0.0.'
80+
)
81+
class TestReportResults(object):
82+
def test_create_rep(self, generate_report, mgmt_root):
83+
rep = generate_report
84+
result_id = rep.reportResultsLink.split('/')[-1]
85+
result = mgmt_root.tm.analytics.protocol_inspection.report_results_s.report_results.load(id=result_id)
86+
assert result.kind == 'tm:analytics:protocol-inspection:report-results:avrreportresultitemstate'
87+
88+
89+
@pytest.mark.skipif(
90+
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
91+
reason='Generating a report returns an unexpected error in 13.0.0.'
92+
)
93+
class TestReportResultsCollection(object):
94+
def test_collection_rep_res(self, generate_report, mgmt_root):
95+
rep = generate_report
96+
result_id = rep.reportResultsLink.split('/')[-1]
97+
results = mgmt_root.tm.analytics.protocol_inspection.report_results_s.get_collection()
98+
assert isinstance(results[0], Report_Results)
99+
assert result_id in [result.id for result in results]
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 import ManagementRoot
17+
from f5.bigip.resource import OrganizingCollection
18+
from f5.bigip.tm.analytics.protocol_inspection import Generate_Report
19+
from f5.bigip.tm.analytics.protocol_inspection import Report_Results
20+
from f5.sdk_exception import MissingRequiredCreationParameter
21+
from f5.sdk_exception import UnsupportedOperation
22+
23+
24+
import mock
25+
import pytest
26+
from six import iterkeys
27+
28+
29+
@pytest.fixture
30+
def FakeGenerateReport():
31+
fake_analytics = mock.MagicMock()
32+
fake_genrep = Generate_Report(fake_analytics)
33+
fake_genrep._meta_data['bigip'].tmos_version = '13.1.0'
34+
return fake_genrep
35+
36+
37+
@pytest.fixture
38+
def FakeReportResults():
39+
fake_analytics = mock.MagicMock()
40+
fake_repres = Report_Results(fake_analytics)
41+
return fake_repres
42+
43+
44+
class TestProtocolInspection(object):
45+
def test_collection(self, fakeicontrolsession):
46+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
47+
t1 = b.tm.analytics.protocol_inspection
48+
assert isinstance(t1, OrganizingCollection)
49+
assert hasattr(t1, 'generate_reports')
50+
assert hasattr(t1, 'report_results_s')
51+
52+
53+
class TestGenerateReport(object):
54+
def test_modify_raises(self, FakeGenerateReport):
55+
with pytest.raises(UnsupportedOperation):
56+
FakeGenerateReport.modify()
57+
58+
def test_create_no_args(self, FakeGenerateReport):
59+
with pytest.raises(MissingRequiredCreationParameter):
60+
FakeGenerateReport.create()
61+
62+
def test_create_two(self, fakeicontrolsession):
63+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
64+
t1 = b.tm.analytics.protocol_inspection.generate_reports.generate_report
65+
t2 = b.tm.analytics.protocol_inspection.generate_reports.generate_report
66+
assert t1 is t2
67+
68+
def test_collection(self, fakeicontrolsession):
69+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
70+
t = b.tm.analytics.protocol_inspection.generate_reports
71+
test_meta = t._meta_data['attribute_registry']
72+
test_meta2 = t._meta_data['allowed_lazy_attributes']
73+
kind = 'tm:analytics:protocol-inspection:generate-report:avrgeneratereporttaskitemstate'
74+
assert kind in list(iterkeys(test_meta))
75+
assert Generate_Report in test_meta2
76+
assert t._meta_data['object_has_stats'] is False
77+
78+
79+
class TestReportResults(object):
80+
def test_create_raises(self, FakeReportResults):
81+
with pytest.raises(UnsupportedOperation):
82+
FakeReportResults.create()
83+
84+
def test_modify_raises(self, FakeReportResults):
85+
with pytest.raises(UnsupportedOperation):
86+
FakeReportResults.modify()
87+
88+
def test_collection(self, fakeicontrolsession):
89+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
90+
t = b.tm.analytics.protocol_inspection.report_results_s
91+
test_meta = t._meta_data['attribute_registry']
92+
test_meta2 = t._meta_data['allowed_lazy_attributes']
93+
kind = 'tm:analytics:protocol-inspection:report-results:avrreportresultitemstate'
94+
assert kind in list(iterkeys(test_meta))
95+
assert Report_Results in test_meta2
96+
assert t._meta_data['object_has_stats'] is False

0 commit comments

Comments
 (0)