Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions f5/bigip/tm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from f5.bigip.resource import OrganizingCollection

from f5.bigip.tm.analytics import Analytics
from f5.bigip.tm.asm import Asm
from f5.bigip.tm.auth import Auth
from f5.bigip.tm.cm import Cm
Expand All @@ -37,6 +38,7 @@ class Tm(OrganizingCollection):
def __init__(self, bigip):
super(Tm, self).__init__(bigip)
self._meta_data['allowed_lazy_attributes'] = [
Analytics,
Asm,
Auth,
Cm,
Expand Down
44 changes: 44 additions & 0 deletions f5/bigip/tm/analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# coding=utf-8
#
# Copyright 2018 F5 Networks Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""BIG-IP® Application Visibility and Reporting™ (AVR®) module.

REST URI
``http://localhost/mgmt/tm/analytics/``

GUI Path
``Statistics --> Analytics``

REST Kind
``tm:analytics:*``
"""

from f5.bigip.resource import OrganizingCollection
from f5.bigip.tm.analytics.dos_vis_common import Dos_Vis_Common


class Analytics(OrganizingCollection):
"""BIG-IP® Application Visibility and Reporting (AVR) organizing

collection.
"""

def __init__(self, tm):
super(Analytics, self).__init__(tm)
self._meta_data['allowed_lazy_attributes'] = [
Dos_Vis_Common,
]
110 changes: 110 additions & 0 deletions f5/bigip/tm/analytics/dos_vis_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# coding=utf-8
#
# Copyright 2018 F5 Networks Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

""" BIG-IP® Application Visibility and Reporting™ (AVR®) DoS Visibility sub-module.

REST URI
``http://localhost/mgmt/tm/analytics/dos-vis-common/``

GUI Path
``Security --> Reporting --> DoS``

REST Kind
``tm:analytics:dos-vis-common:``
"""
from f5.bigip.resource import AsmResource as AvrResource
from f5.bigip.resource import Collection
from f5.bigip.resource import OrganizingCollection
from f5.sdk_exception import UnsupportedOperation


class Dos_Vis_Common(OrganizingCollection):
"""BIG-IP® AVR DoS Visibility organizing collection."""
def __init__(self, analytics):
super(Dos_Vis_Common, self).__init__(analytics)
self._meta_data['object_has_stats'] = False
self._meta_data['allowed_lazy_attributes'] = [
Generate_Reports,
Report_Results_s,
]


class Generate_Reports(Collection):
"""BIG-IP® AVR Generate Report Collection."""
def __init__(self, dos_vis_common):
super(Generate_Reports, self).__init__(dos_vis_common)
self._meta_data['object_has_stats'] = False
self._meta_data['allowed_lazy_attributes'] = [Generate_Report]
self._meta_data['attribute_registry'] = {
'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate': Generate_Report}


class Generate_Report(AvrResource):
"""BIG-IP® AVR Generate Report Resource."""
def __init__(self, generate_reports):
super(Generate_Report, self).__init__(generate_reports)
self._meta_data['required_json_kind'] =\
'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate'
self._meta_data['required_creation_parameters'] = {'viewDimensions',
'reportFeatures',
}

def modify(self, **kwargs):
"""Modify is not supported for Generate Report resource

:raises: UnsupportedOperation
"""
raise UnsupportedOperation(
"%s does not support the modify method" % self.__class__.__name__
)


class Report_Results_s(Collection):
"""BIG-IP® AVR Report Results Collection."""
def __init__(self, dos_vis_common):
super(Report_Results_s, self).__init__(dos_vis_common)
self._meta_data['object_has_stats'] = False
self._meta_data['allowed_lazy_attributes'] = [Report_Results]
self._meta_data['attribute_registry'] = {
'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate':
Report_Results}


class Report_Results(AvrResource):
"""BIG-IP® AVR Report Results Resource."""
def __init__(self, report_results_s):
super(Report_Results, self).__init__(report_results_s)
self._meta_data['required_json_kind'] =\
'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate'

def create(self, **kwargs):
"""Create is not supported for Report Results resource

:raises: UnsupportedOperation
"""
raise UnsupportedOperation(
"%s does not support the create method" % self.__class__.__name__
)

def modify(self, **kwargs):
"""Modify is not supported for Report Results resource

:raises: UnsupportedOperation
"""
raise UnsupportedOperation(
"%s does not support the modify method" % self.__class__.__name__
)
Empty file.
Empty file.
99 changes: 99 additions & 0 deletions f5/bigip/tm/analytics/test/functional/test_dos_vis_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Copyright 2018 F5 Networks Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import pytest
import time

from distutils.version import LooseVersion
from f5.bigip.tm.analytics.dos_vis_common import Generate_Report
from f5.bigip.tm.analytics.dos_vis_common import Report_Results


@pytest.fixture(scope='function')
def generate_report(mgmt_root):
task = mgmt_root.tm.analytics.dos_vis_common.generate_reports.generate_report.create(
reportFeatures=['entities-count'],
viewDimensions=[{'dimensionName': 'dos-profile'}],
)
while True:
task.refresh()
if task.status in ['FINISHED', 'FAILURE']:
break
time.sleep(1)
yield task
task.delete()


@pytest.fixture(scope='function')
def get_reports(mgmt_root):
task = mgmt_root.tm.analytics.dos_vis_common.generate_reports.load()
while True:
task.refresh()
if task.status in ['FINISHED', 'FAILURE']:
break
time.sleep(1)
yield task
task.delete()


@pytest.mark.skipif(
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
reason='Generating a report returns an unexpected error in 13.0.0.'
)
class TestGenerateReport(object):
def test_create_rep_arg(self, generate_report):
rep1 = generate_report
endpoint = str(rep1.id)
base_uri = 'https://localhost/mgmt/tm/analytics/dos-vis-common/generate-report/'
final_uri = base_uri + endpoint
assert rep1.selfLink.startswith(final_uri)
assert rep1.kind == 'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate'


@pytest.mark.skipif(
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
reason='Generating a report returns an unexpected error in 13.0.0.'
)
class TestGenerateReportCollection(object):
def test_collection_gen_rep(self, generate_report, mgmt_root):
rep1 = generate_report
reports = mgmt_root.tm.analytics.dos_vis_common.generate_reports.get_collection()
assert isinstance(reports[0], Generate_Report)
assert rep1.id in [report.id for report in reports]


@pytest.mark.skipif(
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
reason='Generating a report returns an unexpected error in 13.0.0.'
)
class TestReportResults(object):
def test_create_rep(self, generate_report, mgmt_root):
rep = generate_report
result_id = rep.reportResultsLink.split('/')[-1]
result = mgmt_root.tm.analytics.dos_vis_common.report_results_s.report_results.load(id=result_id)
assert result.kind == 'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate'


@pytest.mark.skipif(
LooseVersion(pytest.config.getoption('--release')) < LooseVersion('13.1.0'),
reason='Generating a report returns an unexpected error in 13.0.0.'
)
class TestReportResultsCollection(object):
def test_collection_rep_res(self, generate_report, mgmt_root):
rep = generate_report
result_id = rep.reportResultsLink.split('/')[-1]
results = mgmt_root.tm.analytics.dos_vis_common.report_results_s.get_collection()
assert isinstance(results[0], Report_Results)
assert result_id in [result.id for result in results]
Empty file.
96 changes: 96 additions & 0 deletions f5/bigip/tm/analytics/test/unit/test_dos_vis_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2018 F5 Networks Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from f5.bigip import ManagementRoot
from f5.bigip.resource import OrganizingCollection
from f5.bigip.tm.analytics.dos_vis_common import Generate_Report
from f5.bigip.tm.analytics.dos_vis_common import Report_Results
from f5.sdk_exception import MissingRequiredCreationParameter
from f5.sdk_exception import UnsupportedOperation


import mock
import pytest
from six import iterkeys


@pytest.fixture
def FakeGenerateReport():
fake_analytics = mock.MagicMock()
fake_genrep = Generate_Report(fake_analytics)
fake_genrep._meta_data['bigip'].tmos_version = '13.1.0'
return fake_genrep


@pytest.fixture
def FakeReportResults():
fake_analytics = mock.MagicMock()
fake_repres = Report_Results(fake_analytics)
return fake_repres


class TestDosVisCommonOC(object):
def test_collection(self, fakeicontrolsession):
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
t1 = b.tm.analytics.dos_vis_common
assert isinstance(t1, OrganizingCollection)
assert hasattr(t1, 'generate_reports')
assert hasattr(t1, 'report_results_s')


class TestGenerateReport(object):
def test_modify_raises(self, FakeGenerateReport):
with pytest.raises(UnsupportedOperation):
FakeGenerateReport.modify()

def test_create_no_args(self, FakeGenerateReport):
with pytest.raises(MissingRequiredCreationParameter):
FakeGenerateReport.create()

def test_create_two(self, fakeicontrolsession):
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
t1 = b.tm.analytics.dos_vis_common.generate_reports.generate_report
t2 = b.tm.analytics.dos_vis_common.generate_reports.generate_report
assert t1 is t2

def test_collection(self, fakeicontrolsession):
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
t = b.tm.analytics.dos_vis_common.generate_reports
test_meta = t._meta_data['attribute_registry']
test_meta2 = t._meta_data['allowed_lazy_attributes']
kind = 'tm:analytics:dos-vis-common:generate-report:avrgeneratereporttaskitemstate'
assert kind in list(iterkeys(test_meta))
assert Generate_Report in test_meta2
assert t._meta_data['object_has_stats'] is False


class TestReportResults(object):
def test_create_raises(self, FakeReportResults):
with pytest.raises(UnsupportedOperation):
FakeReportResults.create()

def test_modify_raises(self, FakeReportResults):
with pytest.raises(UnsupportedOperation):
FakeReportResults.modify()

def test_collection(self, fakeicontrolsession):
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
t = b.tm.analytics.dos_vis_common.report_results_s
test_meta = t._meta_data['attribute_registry']
test_meta2 = t._meta_data['allowed_lazy_attributes']
kind = 'tm:analytics:dos-vis-common:report-results:avrreportresultitemstate'
assert kind in list(iterkeys(test_meta))
assert Report_Results in test_meta2
assert t._meta_data['object_has_stats'] is False