mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 8 (#61308)
* FortiOS modules for 2.9 - 8 * Add missing files * Fix trailing spacespull/61322/head
parent
f3f30c146b
commit
69fcd771e0
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,329 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_report_layout
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_report_layout.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_layout_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_layout': {'cutoff_option': 'run-time',
|
||||||
|
'cutoff_time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email_recipients': 'test_value_7',
|
||||||
|
'email_send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max_pdf_report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule_type': 'demand',
|
||||||
|
'style_theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_layout.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'cutoff-option': 'run-time',
|
||||||
|
'cutoff-time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email-recipients': 'test_value_7',
|
||||||
|
'email-send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max-pdf-report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule-type': 'demand',
|
||||||
|
'style-theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'layout', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_layout_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_layout': {'cutoff_option': 'run-time',
|
||||||
|
'cutoff_time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email_recipients': 'test_value_7',
|
||||||
|
'email_send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max_pdf_report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule_type': 'demand',
|
||||||
|
'style_theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_layout.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'cutoff-option': 'run-time',
|
||||||
|
'cutoff-time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email-recipients': 'test_value_7',
|
||||||
|
'email-send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max-pdf-report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule-type': 'demand',
|
||||||
|
'style-theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'layout', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_layout_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_layout': {'cutoff_option': 'run-time',
|
||||||
|
'cutoff_time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email_recipients': 'test_value_7',
|
||||||
|
'email_send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max_pdf_report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule_type': 'demand',
|
||||||
|
'style_theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_layout.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'layout', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_layout_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_layout': {'cutoff_option': 'run-time',
|
||||||
|
'cutoff_time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email_recipients': 'test_value_7',
|
||||||
|
'email_send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max_pdf_report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule_type': 'demand',
|
||||||
|
'style_theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_layout.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'layout', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_layout_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_layout': {'cutoff_option': 'run-time',
|
||||||
|
'cutoff_time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email_recipients': 'test_value_7',
|
||||||
|
'email_send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max_pdf_report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule_type': 'demand',
|
||||||
|
'style_theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_layout.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'cutoff-option': 'run-time',
|
||||||
|
'cutoff-time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email-recipients': 'test_value_7',
|
||||||
|
'email-send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max-pdf-report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule-type': 'demand',
|
||||||
|
'style-theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'layout', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_layout_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_layout': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'cutoff_option': 'run-time',
|
||||||
|
'cutoff_time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email_recipients': 'test_value_7',
|
||||||
|
'email_send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max_pdf_report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule_type': 'demand',
|
||||||
|
'style_theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_layout.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'cutoff-option': 'run-time',
|
||||||
|
'cutoff-time': 'test_value_4',
|
||||||
|
'day': 'sunday',
|
||||||
|
'description': 'test_value_6',
|
||||||
|
'email-recipients': 'test_value_7',
|
||||||
|
'email-send': 'enable',
|
||||||
|
'format': 'pdf',
|
||||||
|
'max-pdf-report': '10',
|
||||||
|
'name': 'default_name_11',
|
||||||
|
'options': 'include-table-of-content',
|
||||||
|
'schedule-type': 'demand',
|
||||||
|
'style-theme': 'test_value_14',
|
||||||
|
'subtitle': 'test_value_15',
|
||||||
|
'time': 'test_value_16',
|
||||||
|
'title': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'layout', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,183 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_report_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_report_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_setting': {
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf_report': 'enable',
|
||||||
|
'report_source': 'forward-traffic',
|
||||||
|
'top_n': '6',
|
||||||
|
'web_browsing_threshold': '7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_setting.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf-report': 'enable',
|
||||||
|
'report-source': 'forward-traffic',
|
||||||
|
'top-n': '6',
|
||||||
|
'web-browsing-threshold': '7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_setting': {
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf_report': 'enable',
|
||||||
|
'report_source': 'forward-traffic',
|
||||||
|
'top_n': '6',
|
||||||
|
'web_browsing_threshold': '7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_setting.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf-report': 'enable',
|
||||||
|
'report-source': 'forward-traffic',
|
||||||
|
'top-n': '6',
|
||||||
|
'web-browsing-threshold': '7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_setting': {
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf_report': 'enable',
|
||||||
|
'report_source': 'forward-traffic',
|
||||||
|
'top_n': '6',
|
||||||
|
'web_browsing_threshold': '7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_setting.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf-report': 'enable',
|
||||||
|
'report-source': 'forward-traffic',
|
||||||
|
'top-n': '6',
|
||||||
|
'web-browsing-threshold': '7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf_report': 'enable',
|
||||||
|
'report_source': 'forward-traffic',
|
||||||
|
'top_n': '6',
|
||||||
|
'web_browsing_threshold': '7'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_setting.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'fortiview': 'enable',
|
||||||
|
'pdf-report': 'enable',
|
||||||
|
'report-source': 'forward-traffic',
|
||||||
|
'top-n': '6',
|
||||||
|
'web-browsing-threshold': '7'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,449 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_report_style
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_report_style.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_style_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_style': {
|
||||||
|
'align': 'left',
|
||||||
|
'bg_color': 'test_value_4',
|
||||||
|
'border_bottom': 'test_value_5',
|
||||||
|
'border_left': 'test_value_6',
|
||||||
|
'border_right': 'test_value_7',
|
||||||
|
'border_top': 'test_value_8',
|
||||||
|
'column_gap': 'test_value_9',
|
||||||
|
'column_span': 'none',
|
||||||
|
'fg_color': 'test_value_11',
|
||||||
|
'font_family': 'Verdana',
|
||||||
|
'font_size': 'test_value_13',
|
||||||
|
'font_style': 'normal',
|
||||||
|
'font_weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line_height': 'test_value_17',
|
||||||
|
'margin_bottom': 'test_value_18',
|
||||||
|
'margin_left': 'test_value_19',
|
||||||
|
'margin_right': 'test_value_20',
|
||||||
|
'margin_top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding_bottom': 'test_value_24',
|
||||||
|
'padding_left': 'test_value_25',
|
||||||
|
'padding_right': 'test_value_26',
|
||||||
|
'padding_top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_style.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'align': 'left',
|
||||||
|
'bg-color': 'test_value_4',
|
||||||
|
'border-bottom': 'test_value_5',
|
||||||
|
'border-left': 'test_value_6',
|
||||||
|
'border-right': 'test_value_7',
|
||||||
|
'border-top': 'test_value_8',
|
||||||
|
'column-gap': 'test_value_9',
|
||||||
|
'column-span': 'none',
|
||||||
|
'fg-color': 'test_value_11',
|
||||||
|
'font-family': 'Verdana',
|
||||||
|
'font-size': 'test_value_13',
|
||||||
|
'font-style': 'normal',
|
||||||
|
'font-weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line-height': 'test_value_17',
|
||||||
|
'margin-bottom': 'test_value_18',
|
||||||
|
'margin-left': 'test_value_19',
|
||||||
|
'margin-right': 'test_value_20',
|
||||||
|
'margin-top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding-bottom': 'test_value_24',
|
||||||
|
'padding-left': 'test_value_25',
|
||||||
|
'padding-right': 'test_value_26',
|
||||||
|
'padding-top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'style', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_style_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_style': {
|
||||||
|
'align': 'left',
|
||||||
|
'bg_color': 'test_value_4',
|
||||||
|
'border_bottom': 'test_value_5',
|
||||||
|
'border_left': 'test_value_6',
|
||||||
|
'border_right': 'test_value_7',
|
||||||
|
'border_top': 'test_value_8',
|
||||||
|
'column_gap': 'test_value_9',
|
||||||
|
'column_span': 'none',
|
||||||
|
'fg_color': 'test_value_11',
|
||||||
|
'font_family': 'Verdana',
|
||||||
|
'font_size': 'test_value_13',
|
||||||
|
'font_style': 'normal',
|
||||||
|
'font_weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line_height': 'test_value_17',
|
||||||
|
'margin_bottom': 'test_value_18',
|
||||||
|
'margin_left': 'test_value_19',
|
||||||
|
'margin_right': 'test_value_20',
|
||||||
|
'margin_top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding_bottom': 'test_value_24',
|
||||||
|
'padding_left': 'test_value_25',
|
||||||
|
'padding_right': 'test_value_26',
|
||||||
|
'padding_top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_style.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'align': 'left',
|
||||||
|
'bg-color': 'test_value_4',
|
||||||
|
'border-bottom': 'test_value_5',
|
||||||
|
'border-left': 'test_value_6',
|
||||||
|
'border-right': 'test_value_7',
|
||||||
|
'border-top': 'test_value_8',
|
||||||
|
'column-gap': 'test_value_9',
|
||||||
|
'column-span': 'none',
|
||||||
|
'fg-color': 'test_value_11',
|
||||||
|
'font-family': 'Verdana',
|
||||||
|
'font-size': 'test_value_13',
|
||||||
|
'font-style': 'normal',
|
||||||
|
'font-weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line-height': 'test_value_17',
|
||||||
|
'margin-bottom': 'test_value_18',
|
||||||
|
'margin-left': 'test_value_19',
|
||||||
|
'margin-right': 'test_value_20',
|
||||||
|
'margin-top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding-bottom': 'test_value_24',
|
||||||
|
'padding-left': 'test_value_25',
|
||||||
|
'padding-right': 'test_value_26',
|
||||||
|
'padding-top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'style', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_style_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_style': {
|
||||||
|
'align': 'left',
|
||||||
|
'bg_color': 'test_value_4',
|
||||||
|
'border_bottom': 'test_value_5',
|
||||||
|
'border_left': 'test_value_6',
|
||||||
|
'border_right': 'test_value_7',
|
||||||
|
'border_top': 'test_value_8',
|
||||||
|
'column_gap': 'test_value_9',
|
||||||
|
'column_span': 'none',
|
||||||
|
'fg_color': 'test_value_11',
|
||||||
|
'font_family': 'Verdana',
|
||||||
|
'font_size': 'test_value_13',
|
||||||
|
'font_style': 'normal',
|
||||||
|
'font_weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line_height': 'test_value_17',
|
||||||
|
'margin_bottom': 'test_value_18',
|
||||||
|
'margin_left': 'test_value_19',
|
||||||
|
'margin_right': 'test_value_20',
|
||||||
|
'margin_top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding_bottom': 'test_value_24',
|
||||||
|
'padding_left': 'test_value_25',
|
||||||
|
'padding_right': 'test_value_26',
|
||||||
|
'padding_top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_style.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'style', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_style_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_style': {
|
||||||
|
'align': 'left',
|
||||||
|
'bg_color': 'test_value_4',
|
||||||
|
'border_bottom': 'test_value_5',
|
||||||
|
'border_left': 'test_value_6',
|
||||||
|
'border_right': 'test_value_7',
|
||||||
|
'border_top': 'test_value_8',
|
||||||
|
'column_gap': 'test_value_9',
|
||||||
|
'column_span': 'none',
|
||||||
|
'fg_color': 'test_value_11',
|
||||||
|
'font_family': 'Verdana',
|
||||||
|
'font_size': 'test_value_13',
|
||||||
|
'font_style': 'normal',
|
||||||
|
'font_weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line_height': 'test_value_17',
|
||||||
|
'margin_bottom': 'test_value_18',
|
||||||
|
'margin_left': 'test_value_19',
|
||||||
|
'margin_right': 'test_value_20',
|
||||||
|
'margin_top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding_bottom': 'test_value_24',
|
||||||
|
'padding_left': 'test_value_25',
|
||||||
|
'padding_right': 'test_value_26',
|
||||||
|
'padding_top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_style.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'style', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_style_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_style': {
|
||||||
|
'align': 'left',
|
||||||
|
'bg_color': 'test_value_4',
|
||||||
|
'border_bottom': 'test_value_5',
|
||||||
|
'border_left': 'test_value_6',
|
||||||
|
'border_right': 'test_value_7',
|
||||||
|
'border_top': 'test_value_8',
|
||||||
|
'column_gap': 'test_value_9',
|
||||||
|
'column_span': 'none',
|
||||||
|
'fg_color': 'test_value_11',
|
||||||
|
'font_family': 'Verdana',
|
||||||
|
'font_size': 'test_value_13',
|
||||||
|
'font_style': 'normal',
|
||||||
|
'font_weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line_height': 'test_value_17',
|
||||||
|
'margin_bottom': 'test_value_18',
|
||||||
|
'margin_left': 'test_value_19',
|
||||||
|
'margin_right': 'test_value_20',
|
||||||
|
'margin_top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding_bottom': 'test_value_24',
|
||||||
|
'padding_left': 'test_value_25',
|
||||||
|
'padding_right': 'test_value_26',
|
||||||
|
'padding_top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_style.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'align': 'left',
|
||||||
|
'bg-color': 'test_value_4',
|
||||||
|
'border-bottom': 'test_value_5',
|
||||||
|
'border-left': 'test_value_6',
|
||||||
|
'border-right': 'test_value_7',
|
||||||
|
'border-top': 'test_value_8',
|
||||||
|
'column-gap': 'test_value_9',
|
||||||
|
'column-span': 'none',
|
||||||
|
'fg-color': 'test_value_11',
|
||||||
|
'font-family': 'Verdana',
|
||||||
|
'font-size': 'test_value_13',
|
||||||
|
'font-style': 'normal',
|
||||||
|
'font-weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line-height': 'test_value_17',
|
||||||
|
'margin-bottom': 'test_value_18',
|
||||||
|
'margin-left': 'test_value_19',
|
||||||
|
'margin-right': 'test_value_20',
|
||||||
|
'margin-top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding-bottom': 'test_value_24',
|
||||||
|
'padding-left': 'test_value_25',
|
||||||
|
'padding-right': 'test_value_26',
|
||||||
|
'padding-top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'style', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_style_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_style': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'align': 'left',
|
||||||
|
'bg_color': 'test_value_4',
|
||||||
|
'border_bottom': 'test_value_5',
|
||||||
|
'border_left': 'test_value_6',
|
||||||
|
'border_right': 'test_value_7',
|
||||||
|
'border_top': 'test_value_8',
|
||||||
|
'column_gap': 'test_value_9',
|
||||||
|
'column_span': 'none',
|
||||||
|
'fg_color': 'test_value_11',
|
||||||
|
'font_family': 'Verdana',
|
||||||
|
'font_size': 'test_value_13',
|
||||||
|
'font_style': 'normal',
|
||||||
|
'font_weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line_height': 'test_value_17',
|
||||||
|
'margin_bottom': 'test_value_18',
|
||||||
|
'margin_left': 'test_value_19',
|
||||||
|
'margin_right': 'test_value_20',
|
||||||
|
'margin_top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding_bottom': 'test_value_24',
|
||||||
|
'padding_left': 'test_value_25',
|
||||||
|
'padding_right': 'test_value_26',
|
||||||
|
'padding_top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_style.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'align': 'left',
|
||||||
|
'bg-color': 'test_value_4',
|
||||||
|
'border-bottom': 'test_value_5',
|
||||||
|
'border-left': 'test_value_6',
|
||||||
|
'border-right': 'test_value_7',
|
||||||
|
'border-top': 'test_value_8',
|
||||||
|
'column-gap': 'test_value_9',
|
||||||
|
'column-span': 'none',
|
||||||
|
'fg-color': 'test_value_11',
|
||||||
|
'font-family': 'Verdana',
|
||||||
|
'font-size': 'test_value_13',
|
||||||
|
'font-style': 'normal',
|
||||||
|
'font-weight': 'normal',
|
||||||
|
'height': 'test_value_16',
|
||||||
|
'line-height': 'test_value_17',
|
||||||
|
'margin-bottom': 'test_value_18',
|
||||||
|
'margin-left': 'test_value_19',
|
||||||
|
'margin-right': 'test_value_20',
|
||||||
|
'margin-top': 'test_value_21',
|
||||||
|
'name': 'default_name_22',
|
||||||
|
'options': 'font',
|
||||||
|
'padding-bottom': 'test_value_24',
|
||||||
|
'padding-left': 'test_value_25',
|
||||||
|
'padding-right': 'test_value_26',
|
||||||
|
'padding-top': 'test_value_27',
|
||||||
|
'width': 'test_value_28'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'style', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,489 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_report_theme
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_report_theme.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_theme_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_theme': {
|
||||||
|
'bullet_list_style': 'test_value_3',
|
||||||
|
'column_count': '1',
|
||||||
|
'default_html_style': 'test_value_5',
|
||||||
|
'default_pdf_style': 'test_value_6',
|
||||||
|
'graph_chart_style': 'test_value_7',
|
||||||
|
'heading1_style': 'test_value_8',
|
||||||
|
'heading2_style': 'test_value_9',
|
||||||
|
'heading3_style': 'test_value_10',
|
||||||
|
'heading4_style': 'test_value_11',
|
||||||
|
'hline_style': 'test_value_12',
|
||||||
|
'image_style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal_text_style': 'test_value_15',
|
||||||
|
'numbered_list_style': 'test_value_16',
|
||||||
|
'page_footer_style': 'test_value_17',
|
||||||
|
'page_header_style': 'test_value_18',
|
||||||
|
'page_orient': 'portrait',
|
||||||
|
'page_style': 'test_value_20',
|
||||||
|
'report_subtitle_style': 'test_value_21',
|
||||||
|
'report_title_style': 'test_value_22',
|
||||||
|
'table_chart_caption_style': 'test_value_23',
|
||||||
|
'table_chart_even_row_style': 'test_value_24',
|
||||||
|
'table_chart_head_style': 'test_value_25',
|
||||||
|
'table_chart_odd_row_style': 'test_value_26',
|
||||||
|
'table_chart_style': 'test_value_27',
|
||||||
|
'toc_heading1_style': 'test_value_28',
|
||||||
|
'toc_heading2_style': 'test_value_29',
|
||||||
|
'toc_heading3_style': 'test_value_30',
|
||||||
|
'toc_heading4_style': 'test_value_31',
|
||||||
|
'toc_title_style': 'test_value_32'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_theme.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bullet-list-style': 'test_value_3',
|
||||||
|
'column-count': '1',
|
||||||
|
'default-html-style': 'test_value_5',
|
||||||
|
'default-pdf-style': 'test_value_6',
|
||||||
|
'graph-chart-style': 'test_value_7',
|
||||||
|
'heading1-style': 'test_value_8',
|
||||||
|
'heading2-style': 'test_value_9',
|
||||||
|
'heading3-style': 'test_value_10',
|
||||||
|
'heading4-style': 'test_value_11',
|
||||||
|
'hline-style': 'test_value_12',
|
||||||
|
'image-style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal-text-style': 'test_value_15',
|
||||||
|
'numbered-list-style': 'test_value_16',
|
||||||
|
'page-footer-style': 'test_value_17',
|
||||||
|
'page-header-style': 'test_value_18',
|
||||||
|
'page-orient': 'portrait',
|
||||||
|
'page-style': 'test_value_20',
|
||||||
|
'report-subtitle-style': 'test_value_21',
|
||||||
|
'report-title-style': 'test_value_22',
|
||||||
|
'table-chart-caption-style': 'test_value_23',
|
||||||
|
'table-chart-even-row-style': 'test_value_24',
|
||||||
|
'table-chart-head-style': 'test_value_25',
|
||||||
|
'table-chart-odd-row-style': 'test_value_26',
|
||||||
|
'table-chart-style': 'test_value_27',
|
||||||
|
'toc-heading1-style': 'test_value_28',
|
||||||
|
'toc-heading2-style': 'test_value_29',
|
||||||
|
'toc-heading3-style': 'test_value_30',
|
||||||
|
'toc-heading4-style': 'test_value_31',
|
||||||
|
'toc-title-style': 'test_value_32'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'theme', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_theme_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_theme': {
|
||||||
|
'bullet_list_style': 'test_value_3',
|
||||||
|
'column_count': '1',
|
||||||
|
'default_html_style': 'test_value_5',
|
||||||
|
'default_pdf_style': 'test_value_6',
|
||||||
|
'graph_chart_style': 'test_value_7',
|
||||||
|
'heading1_style': 'test_value_8',
|
||||||
|
'heading2_style': 'test_value_9',
|
||||||
|
'heading3_style': 'test_value_10',
|
||||||
|
'heading4_style': 'test_value_11',
|
||||||
|
'hline_style': 'test_value_12',
|
||||||
|
'image_style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal_text_style': 'test_value_15',
|
||||||
|
'numbered_list_style': 'test_value_16',
|
||||||
|
'page_footer_style': 'test_value_17',
|
||||||
|
'page_header_style': 'test_value_18',
|
||||||
|
'page_orient': 'portrait',
|
||||||
|
'page_style': 'test_value_20',
|
||||||
|
'report_subtitle_style': 'test_value_21',
|
||||||
|
'report_title_style': 'test_value_22',
|
||||||
|
'table_chart_caption_style': 'test_value_23',
|
||||||
|
'table_chart_even_row_style': 'test_value_24',
|
||||||
|
'table_chart_head_style': 'test_value_25',
|
||||||
|
'table_chart_odd_row_style': 'test_value_26',
|
||||||
|
'table_chart_style': 'test_value_27',
|
||||||
|
'toc_heading1_style': 'test_value_28',
|
||||||
|
'toc_heading2_style': 'test_value_29',
|
||||||
|
'toc_heading3_style': 'test_value_30',
|
||||||
|
'toc_heading4_style': 'test_value_31',
|
||||||
|
'toc_title_style': 'test_value_32'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_theme.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bullet-list-style': 'test_value_3',
|
||||||
|
'column-count': '1',
|
||||||
|
'default-html-style': 'test_value_5',
|
||||||
|
'default-pdf-style': 'test_value_6',
|
||||||
|
'graph-chart-style': 'test_value_7',
|
||||||
|
'heading1-style': 'test_value_8',
|
||||||
|
'heading2-style': 'test_value_9',
|
||||||
|
'heading3-style': 'test_value_10',
|
||||||
|
'heading4-style': 'test_value_11',
|
||||||
|
'hline-style': 'test_value_12',
|
||||||
|
'image-style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal-text-style': 'test_value_15',
|
||||||
|
'numbered-list-style': 'test_value_16',
|
||||||
|
'page-footer-style': 'test_value_17',
|
||||||
|
'page-header-style': 'test_value_18',
|
||||||
|
'page-orient': 'portrait',
|
||||||
|
'page-style': 'test_value_20',
|
||||||
|
'report-subtitle-style': 'test_value_21',
|
||||||
|
'report-title-style': 'test_value_22',
|
||||||
|
'table-chart-caption-style': 'test_value_23',
|
||||||
|
'table-chart-even-row-style': 'test_value_24',
|
||||||
|
'table-chart-head-style': 'test_value_25',
|
||||||
|
'table-chart-odd-row-style': 'test_value_26',
|
||||||
|
'table-chart-style': 'test_value_27',
|
||||||
|
'toc-heading1-style': 'test_value_28',
|
||||||
|
'toc-heading2-style': 'test_value_29',
|
||||||
|
'toc-heading3-style': 'test_value_30',
|
||||||
|
'toc-heading4-style': 'test_value_31',
|
||||||
|
'toc-title-style': 'test_value_32'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'theme', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_theme_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_theme': {
|
||||||
|
'bullet_list_style': 'test_value_3',
|
||||||
|
'column_count': '1',
|
||||||
|
'default_html_style': 'test_value_5',
|
||||||
|
'default_pdf_style': 'test_value_6',
|
||||||
|
'graph_chart_style': 'test_value_7',
|
||||||
|
'heading1_style': 'test_value_8',
|
||||||
|
'heading2_style': 'test_value_9',
|
||||||
|
'heading3_style': 'test_value_10',
|
||||||
|
'heading4_style': 'test_value_11',
|
||||||
|
'hline_style': 'test_value_12',
|
||||||
|
'image_style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal_text_style': 'test_value_15',
|
||||||
|
'numbered_list_style': 'test_value_16',
|
||||||
|
'page_footer_style': 'test_value_17',
|
||||||
|
'page_header_style': 'test_value_18',
|
||||||
|
'page_orient': 'portrait',
|
||||||
|
'page_style': 'test_value_20',
|
||||||
|
'report_subtitle_style': 'test_value_21',
|
||||||
|
'report_title_style': 'test_value_22',
|
||||||
|
'table_chart_caption_style': 'test_value_23',
|
||||||
|
'table_chart_even_row_style': 'test_value_24',
|
||||||
|
'table_chart_head_style': 'test_value_25',
|
||||||
|
'table_chart_odd_row_style': 'test_value_26',
|
||||||
|
'table_chart_style': 'test_value_27',
|
||||||
|
'toc_heading1_style': 'test_value_28',
|
||||||
|
'toc_heading2_style': 'test_value_29',
|
||||||
|
'toc_heading3_style': 'test_value_30',
|
||||||
|
'toc_heading4_style': 'test_value_31',
|
||||||
|
'toc_title_style': 'test_value_32'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_theme.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'theme', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_theme_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'report_theme': {
|
||||||
|
'bullet_list_style': 'test_value_3',
|
||||||
|
'column_count': '1',
|
||||||
|
'default_html_style': 'test_value_5',
|
||||||
|
'default_pdf_style': 'test_value_6',
|
||||||
|
'graph_chart_style': 'test_value_7',
|
||||||
|
'heading1_style': 'test_value_8',
|
||||||
|
'heading2_style': 'test_value_9',
|
||||||
|
'heading3_style': 'test_value_10',
|
||||||
|
'heading4_style': 'test_value_11',
|
||||||
|
'hline_style': 'test_value_12',
|
||||||
|
'image_style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal_text_style': 'test_value_15',
|
||||||
|
'numbered_list_style': 'test_value_16',
|
||||||
|
'page_footer_style': 'test_value_17',
|
||||||
|
'page_header_style': 'test_value_18',
|
||||||
|
'page_orient': 'portrait',
|
||||||
|
'page_style': 'test_value_20',
|
||||||
|
'report_subtitle_style': 'test_value_21',
|
||||||
|
'report_title_style': 'test_value_22',
|
||||||
|
'table_chart_caption_style': 'test_value_23',
|
||||||
|
'table_chart_even_row_style': 'test_value_24',
|
||||||
|
'table_chart_head_style': 'test_value_25',
|
||||||
|
'table_chart_odd_row_style': 'test_value_26',
|
||||||
|
'table_chart_style': 'test_value_27',
|
||||||
|
'toc_heading1_style': 'test_value_28',
|
||||||
|
'toc_heading2_style': 'test_value_29',
|
||||||
|
'toc_heading3_style': 'test_value_30',
|
||||||
|
'toc_heading4_style': 'test_value_31',
|
||||||
|
'toc_title_style': 'test_value_32'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_theme.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('report', 'theme', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_theme_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_theme': {
|
||||||
|
'bullet_list_style': 'test_value_3',
|
||||||
|
'column_count': '1',
|
||||||
|
'default_html_style': 'test_value_5',
|
||||||
|
'default_pdf_style': 'test_value_6',
|
||||||
|
'graph_chart_style': 'test_value_7',
|
||||||
|
'heading1_style': 'test_value_8',
|
||||||
|
'heading2_style': 'test_value_9',
|
||||||
|
'heading3_style': 'test_value_10',
|
||||||
|
'heading4_style': 'test_value_11',
|
||||||
|
'hline_style': 'test_value_12',
|
||||||
|
'image_style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal_text_style': 'test_value_15',
|
||||||
|
'numbered_list_style': 'test_value_16',
|
||||||
|
'page_footer_style': 'test_value_17',
|
||||||
|
'page_header_style': 'test_value_18',
|
||||||
|
'page_orient': 'portrait',
|
||||||
|
'page_style': 'test_value_20',
|
||||||
|
'report_subtitle_style': 'test_value_21',
|
||||||
|
'report_title_style': 'test_value_22',
|
||||||
|
'table_chart_caption_style': 'test_value_23',
|
||||||
|
'table_chart_even_row_style': 'test_value_24',
|
||||||
|
'table_chart_head_style': 'test_value_25',
|
||||||
|
'table_chart_odd_row_style': 'test_value_26',
|
||||||
|
'table_chart_style': 'test_value_27',
|
||||||
|
'toc_heading1_style': 'test_value_28',
|
||||||
|
'toc_heading2_style': 'test_value_29',
|
||||||
|
'toc_heading3_style': 'test_value_30',
|
||||||
|
'toc_heading4_style': 'test_value_31',
|
||||||
|
'toc_title_style': 'test_value_32'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_theme.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bullet-list-style': 'test_value_3',
|
||||||
|
'column-count': '1',
|
||||||
|
'default-html-style': 'test_value_5',
|
||||||
|
'default-pdf-style': 'test_value_6',
|
||||||
|
'graph-chart-style': 'test_value_7',
|
||||||
|
'heading1-style': 'test_value_8',
|
||||||
|
'heading2-style': 'test_value_9',
|
||||||
|
'heading3-style': 'test_value_10',
|
||||||
|
'heading4-style': 'test_value_11',
|
||||||
|
'hline-style': 'test_value_12',
|
||||||
|
'image-style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal-text-style': 'test_value_15',
|
||||||
|
'numbered-list-style': 'test_value_16',
|
||||||
|
'page-footer-style': 'test_value_17',
|
||||||
|
'page-header-style': 'test_value_18',
|
||||||
|
'page-orient': 'portrait',
|
||||||
|
'page-style': 'test_value_20',
|
||||||
|
'report-subtitle-style': 'test_value_21',
|
||||||
|
'report-title-style': 'test_value_22',
|
||||||
|
'table-chart-caption-style': 'test_value_23',
|
||||||
|
'table-chart-even-row-style': 'test_value_24',
|
||||||
|
'table-chart-head-style': 'test_value_25',
|
||||||
|
'table-chart-odd-row-style': 'test_value_26',
|
||||||
|
'table-chart-style': 'test_value_27',
|
||||||
|
'toc-heading1-style': 'test_value_28',
|
||||||
|
'toc-heading2-style': 'test_value_29',
|
||||||
|
'toc-heading3-style': 'test_value_30',
|
||||||
|
'toc-heading4-style': 'test_value_31',
|
||||||
|
'toc-title-style': 'test_value_32'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'theme', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_report_theme_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'report_theme': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'bullet_list_style': 'test_value_3',
|
||||||
|
'column_count': '1',
|
||||||
|
'default_html_style': 'test_value_5',
|
||||||
|
'default_pdf_style': 'test_value_6',
|
||||||
|
'graph_chart_style': 'test_value_7',
|
||||||
|
'heading1_style': 'test_value_8',
|
||||||
|
'heading2_style': 'test_value_9',
|
||||||
|
'heading3_style': 'test_value_10',
|
||||||
|
'heading4_style': 'test_value_11',
|
||||||
|
'hline_style': 'test_value_12',
|
||||||
|
'image_style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal_text_style': 'test_value_15',
|
||||||
|
'numbered_list_style': 'test_value_16',
|
||||||
|
'page_footer_style': 'test_value_17',
|
||||||
|
'page_header_style': 'test_value_18',
|
||||||
|
'page_orient': 'portrait',
|
||||||
|
'page_style': 'test_value_20',
|
||||||
|
'report_subtitle_style': 'test_value_21',
|
||||||
|
'report_title_style': 'test_value_22',
|
||||||
|
'table_chart_caption_style': 'test_value_23',
|
||||||
|
'table_chart_even_row_style': 'test_value_24',
|
||||||
|
'table_chart_head_style': 'test_value_25',
|
||||||
|
'table_chart_odd_row_style': 'test_value_26',
|
||||||
|
'table_chart_style': 'test_value_27',
|
||||||
|
'toc_heading1_style': 'test_value_28',
|
||||||
|
'toc_heading2_style': 'test_value_29',
|
||||||
|
'toc_heading3_style': 'test_value_30',
|
||||||
|
'toc_heading4_style': 'test_value_31',
|
||||||
|
'toc_title_style': 'test_value_32'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_report_theme.fortios_report(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bullet-list-style': 'test_value_3',
|
||||||
|
'column-count': '1',
|
||||||
|
'default-html-style': 'test_value_5',
|
||||||
|
'default-pdf-style': 'test_value_6',
|
||||||
|
'graph-chart-style': 'test_value_7',
|
||||||
|
'heading1-style': 'test_value_8',
|
||||||
|
'heading2-style': 'test_value_9',
|
||||||
|
'heading3-style': 'test_value_10',
|
||||||
|
'heading4-style': 'test_value_11',
|
||||||
|
'hline-style': 'test_value_12',
|
||||||
|
'image-style': 'test_value_13',
|
||||||
|
'name': 'default_name_14',
|
||||||
|
'normal-text-style': 'test_value_15',
|
||||||
|
'numbered-list-style': 'test_value_16',
|
||||||
|
'page-footer-style': 'test_value_17',
|
||||||
|
'page-header-style': 'test_value_18',
|
||||||
|
'page-orient': 'portrait',
|
||||||
|
'page-style': 'test_value_20',
|
||||||
|
'report-subtitle-style': 'test_value_21',
|
||||||
|
'report-title-style': 'test_value_22',
|
||||||
|
'table-chart-caption-style': 'test_value_23',
|
||||||
|
'table-chart-even-row-style': 'test_value_24',
|
||||||
|
'table-chart-head-style': 'test_value_25',
|
||||||
|
'table-chart-odd-row-style': 'test_value_26',
|
||||||
|
'table-chart-style': 'test_value_27',
|
||||||
|
'toc-heading1-style': 'test_value_28',
|
||||||
|
'toc-heading2-style': 'test_value_29',
|
||||||
|
'toc-heading3-style': 'test_value_30',
|
||||||
|
'toc-heading4-style': 'test_value_31',
|
||||||
|
'toc-title-style': 'test_value_32'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('report', 'theme', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,219 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_access_list
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_access_list.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_access_list_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_access_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_access_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'access-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_access_list_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_access_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_access_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'access-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_access_list_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_access_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_access_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'access-list', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_access_list_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_access_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_access_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'access-list', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_access_list_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_access_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_access_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'access-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_access_list_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_access_list': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_access_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'access-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,219 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_auth_path
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_auth_path.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_auth_path_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_auth_path': {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_auth_path.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'auth-path', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_auth_path_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_auth_path': {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_auth_path.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'auth-path', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_auth_path_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_auth_path': {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_auth_path.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'auth-path', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_auth_path_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_auth_path': {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_auth_path.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'auth-path', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_auth_path_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_auth_path': {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_auth_path.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'auth-path', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_auth_path_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_auth_path': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_auth_path.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'device': 'test_value_3',
|
||||||
|
'gateway': 'test_value_4',
|
||||||
|
'name': 'default_name_5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'auth-path', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,143 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_bfd
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_bfd.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd': {
|
||||||
|
'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd': {
|
||||||
|
'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd': {
|
||||||
|
'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,143 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_bfd6
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_bfd6.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd6_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd6': {
|
||||||
|
'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd6_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd6': {
|
||||||
|
'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd6_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd6': {
|
||||||
|
'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'neighbor': [{'interface': 'if1', 'ip': '10.20.10.10'}]}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bfd6_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bfd6': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bfd6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bfd6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,447 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_bgp
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_bgp.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bgp_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bgp': {'always_compare_med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath_as_path_ignore': 'enable',
|
||||||
|
'bestpath_cmp_confed_aspath': 'enable',
|
||||||
|
'bestpath_cmp_routerid': 'enable',
|
||||||
|
'bestpath_med_confed': 'enable',
|
||||||
|
'bestpath_med_missing_as_worst': 'enable',
|
||||||
|
'client_to_client_reflection': 'enable',
|
||||||
|
'cluster_id': 'test_value_11',
|
||||||
|
'confederation_identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening_max_suppress_time': '14',
|
||||||
|
'dampening_reachability_half_life': '15',
|
||||||
|
'dampening_reuse': '16',
|
||||||
|
'dampening_route_map': 'test_value_17',
|
||||||
|
'dampening_suppress': '18',
|
||||||
|
'dampening_unreachability_half_life': '19',
|
||||||
|
'default_local_preference': '20',
|
||||||
|
'deterministic_med': 'enable',
|
||||||
|
'distance_external': '22',
|
||||||
|
'distance_internal': '23',
|
||||||
|
'distance_local': '24',
|
||||||
|
'ebgp_multipath': 'enable',
|
||||||
|
'enforce_first_as': 'enable',
|
||||||
|
'fast_external_failover': 'enable',
|
||||||
|
'graceful_end_on_timer': 'enable',
|
||||||
|
'graceful_restart': 'enable',
|
||||||
|
'graceful_restart_time': '30',
|
||||||
|
'graceful_stalepath_time': '31',
|
||||||
|
'graceful_update_delay': '32',
|
||||||
|
'holdtime_timer': '33',
|
||||||
|
'ibgp_multipath': 'enable',
|
||||||
|
'ignore_optional_capability': 'enable',
|
||||||
|
'keepalive_timer': '36',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'network_import_check': 'enable',
|
||||||
|
'router_id': 'test_value_39',
|
||||||
|
'scan_time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bgp.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'always-compare-med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath-as-path-ignore': 'enable',
|
||||||
|
'bestpath-cmp-confed-aspath': 'enable',
|
||||||
|
'bestpath-cmp-routerid': 'enable',
|
||||||
|
'bestpath-med-confed': 'enable',
|
||||||
|
'bestpath-med-missing-as-worst': 'enable',
|
||||||
|
'client-to-client-reflection': 'enable',
|
||||||
|
'cluster-id': 'test_value_11',
|
||||||
|
'confederation-identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening-max-suppress-time': '14',
|
||||||
|
'dampening-reachability-half-life': '15',
|
||||||
|
'dampening-reuse': '16',
|
||||||
|
'dampening-route-map': 'test_value_17',
|
||||||
|
'dampening-suppress': '18',
|
||||||
|
'dampening-unreachability-half-life': '19',
|
||||||
|
'default-local-preference': '20',
|
||||||
|
'deterministic-med': 'enable',
|
||||||
|
'distance-external': '22',
|
||||||
|
'distance-internal': '23',
|
||||||
|
'distance-local': '24',
|
||||||
|
'ebgp-multipath': 'enable',
|
||||||
|
'enforce-first-as': 'enable',
|
||||||
|
'fast-external-failover': 'enable',
|
||||||
|
'graceful-end-on-timer': 'enable',
|
||||||
|
'graceful-restart': 'enable',
|
||||||
|
'graceful-restart-time': '30',
|
||||||
|
'graceful-stalepath-time': '31',
|
||||||
|
'graceful-update-delay': '32',
|
||||||
|
'holdtime-timer': '33',
|
||||||
|
'ibgp-multipath': 'enable',
|
||||||
|
'ignore-optional-capability': 'enable',
|
||||||
|
'keepalive-timer': '36',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'network-import-check': 'enable',
|
||||||
|
'router-id': 'test_value_39',
|
||||||
|
'scan-time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bgp', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bgp_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bgp': {'always_compare_med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath_as_path_ignore': 'enable',
|
||||||
|
'bestpath_cmp_confed_aspath': 'enable',
|
||||||
|
'bestpath_cmp_routerid': 'enable',
|
||||||
|
'bestpath_med_confed': 'enable',
|
||||||
|
'bestpath_med_missing_as_worst': 'enable',
|
||||||
|
'client_to_client_reflection': 'enable',
|
||||||
|
'cluster_id': 'test_value_11',
|
||||||
|
'confederation_identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening_max_suppress_time': '14',
|
||||||
|
'dampening_reachability_half_life': '15',
|
||||||
|
'dampening_reuse': '16',
|
||||||
|
'dampening_route_map': 'test_value_17',
|
||||||
|
'dampening_suppress': '18',
|
||||||
|
'dampening_unreachability_half_life': '19',
|
||||||
|
'default_local_preference': '20',
|
||||||
|
'deterministic_med': 'enable',
|
||||||
|
'distance_external': '22',
|
||||||
|
'distance_internal': '23',
|
||||||
|
'distance_local': '24',
|
||||||
|
'ebgp_multipath': 'enable',
|
||||||
|
'enforce_first_as': 'enable',
|
||||||
|
'fast_external_failover': 'enable',
|
||||||
|
'graceful_end_on_timer': 'enable',
|
||||||
|
'graceful_restart': 'enable',
|
||||||
|
'graceful_restart_time': '30',
|
||||||
|
'graceful_stalepath_time': '31',
|
||||||
|
'graceful_update_delay': '32',
|
||||||
|
'holdtime_timer': '33',
|
||||||
|
'ibgp_multipath': 'enable',
|
||||||
|
'ignore_optional_capability': 'enable',
|
||||||
|
'keepalive_timer': '36',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'network_import_check': 'enable',
|
||||||
|
'router_id': 'test_value_39',
|
||||||
|
'scan_time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bgp.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'always-compare-med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath-as-path-ignore': 'enable',
|
||||||
|
'bestpath-cmp-confed-aspath': 'enable',
|
||||||
|
'bestpath-cmp-routerid': 'enable',
|
||||||
|
'bestpath-med-confed': 'enable',
|
||||||
|
'bestpath-med-missing-as-worst': 'enable',
|
||||||
|
'client-to-client-reflection': 'enable',
|
||||||
|
'cluster-id': 'test_value_11',
|
||||||
|
'confederation-identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening-max-suppress-time': '14',
|
||||||
|
'dampening-reachability-half-life': '15',
|
||||||
|
'dampening-reuse': '16',
|
||||||
|
'dampening-route-map': 'test_value_17',
|
||||||
|
'dampening-suppress': '18',
|
||||||
|
'dampening-unreachability-half-life': '19',
|
||||||
|
'default-local-preference': '20',
|
||||||
|
'deterministic-med': 'enable',
|
||||||
|
'distance-external': '22',
|
||||||
|
'distance-internal': '23',
|
||||||
|
'distance-local': '24',
|
||||||
|
'ebgp-multipath': 'enable',
|
||||||
|
'enforce-first-as': 'enable',
|
||||||
|
'fast-external-failover': 'enable',
|
||||||
|
'graceful-end-on-timer': 'enable',
|
||||||
|
'graceful-restart': 'enable',
|
||||||
|
'graceful-restart-time': '30',
|
||||||
|
'graceful-stalepath-time': '31',
|
||||||
|
'graceful-update-delay': '32',
|
||||||
|
'holdtime-timer': '33',
|
||||||
|
'ibgp-multipath': 'enable',
|
||||||
|
'ignore-optional-capability': 'enable',
|
||||||
|
'keepalive-timer': '36',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'network-import-check': 'enable',
|
||||||
|
'router-id': 'test_value_39',
|
||||||
|
'scan-time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bgp', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bgp_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bgp': {'always_compare_med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath_as_path_ignore': 'enable',
|
||||||
|
'bestpath_cmp_confed_aspath': 'enable',
|
||||||
|
'bestpath_cmp_routerid': 'enable',
|
||||||
|
'bestpath_med_confed': 'enable',
|
||||||
|
'bestpath_med_missing_as_worst': 'enable',
|
||||||
|
'client_to_client_reflection': 'enable',
|
||||||
|
'cluster_id': 'test_value_11',
|
||||||
|
'confederation_identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening_max_suppress_time': '14',
|
||||||
|
'dampening_reachability_half_life': '15',
|
||||||
|
'dampening_reuse': '16',
|
||||||
|
'dampening_route_map': 'test_value_17',
|
||||||
|
'dampening_suppress': '18',
|
||||||
|
'dampening_unreachability_half_life': '19',
|
||||||
|
'default_local_preference': '20',
|
||||||
|
'deterministic_med': 'enable',
|
||||||
|
'distance_external': '22',
|
||||||
|
'distance_internal': '23',
|
||||||
|
'distance_local': '24',
|
||||||
|
'ebgp_multipath': 'enable',
|
||||||
|
'enforce_first_as': 'enable',
|
||||||
|
'fast_external_failover': 'enable',
|
||||||
|
'graceful_end_on_timer': 'enable',
|
||||||
|
'graceful_restart': 'enable',
|
||||||
|
'graceful_restart_time': '30',
|
||||||
|
'graceful_stalepath_time': '31',
|
||||||
|
'graceful_update_delay': '32',
|
||||||
|
'holdtime_timer': '33',
|
||||||
|
'ibgp_multipath': 'enable',
|
||||||
|
'ignore_optional_capability': 'enable',
|
||||||
|
'keepalive_timer': '36',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'network_import_check': 'enable',
|
||||||
|
'router_id': 'test_value_39',
|
||||||
|
'scan_time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bgp.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'always-compare-med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath-as-path-ignore': 'enable',
|
||||||
|
'bestpath-cmp-confed-aspath': 'enable',
|
||||||
|
'bestpath-cmp-routerid': 'enable',
|
||||||
|
'bestpath-med-confed': 'enable',
|
||||||
|
'bestpath-med-missing-as-worst': 'enable',
|
||||||
|
'client-to-client-reflection': 'enable',
|
||||||
|
'cluster-id': 'test_value_11',
|
||||||
|
'confederation-identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening-max-suppress-time': '14',
|
||||||
|
'dampening-reachability-half-life': '15',
|
||||||
|
'dampening-reuse': '16',
|
||||||
|
'dampening-route-map': 'test_value_17',
|
||||||
|
'dampening-suppress': '18',
|
||||||
|
'dampening-unreachability-half-life': '19',
|
||||||
|
'default-local-preference': '20',
|
||||||
|
'deterministic-med': 'enable',
|
||||||
|
'distance-external': '22',
|
||||||
|
'distance-internal': '23',
|
||||||
|
'distance-local': '24',
|
||||||
|
'ebgp-multipath': 'enable',
|
||||||
|
'enforce-first-as': 'enable',
|
||||||
|
'fast-external-failover': 'enable',
|
||||||
|
'graceful-end-on-timer': 'enable',
|
||||||
|
'graceful-restart': 'enable',
|
||||||
|
'graceful-restart-time': '30',
|
||||||
|
'graceful-stalepath-time': '31',
|
||||||
|
'graceful-update-delay': '32',
|
||||||
|
'holdtime-timer': '33',
|
||||||
|
'ibgp-multipath': 'enable',
|
||||||
|
'ignore-optional-capability': 'enable',
|
||||||
|
'keepalive-timer': '36',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'network-import-check': 'enable',
|
||||||
|
'router-id': 'test_value_39',
|
||||||
|
'scan-time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bgp', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_bgp_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_bgp': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'always_compare_med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath_as_path_ignore': 'enable',
|
||||||
|
'bestpath_cmp_confed_aspath': 'enable',
|
||||||
|
'bestpath_cmp_routerid': 'enable',
|
||||||
|
'bestpath_med_confed': 'enable',
|
||||||
|
'bestpath_med_missing_as_worst': 'enable',
|
||||||
|
'client_to_client_reflection': 'enable',
|
||||||
|
'cluster_id': 'test_value_11',
|
||||||
|
'confederation_identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening_max_suppress_time': '14',
|
||||||
|
'dampening_reachability_half_life': '15',
|
||||||
|
'dampening_reuse': '16',
|
||||||
|
'dampening_route_map': 'test_value_17',
|
||||||
|
'dampening_suppress': '18',
|
||||||
|
'dampening_unreachability_half_life': '19',
|
||||||
|
'default_local_preference': '20',
|
||||||
|
'deterministic_med': 'enable',
|
||||||
|
'distance_external': '22',
|
||||||
|
'distance_internal': '23',
|
||||||
|
'distance_local': '24',
|
||||||
|
'ebgp_multipath': 'enable',
|
||||||
|
'enforce_first_as': 'enable',
|
||||||
|
'fast_external_failover': 'enable',
|
||||||
|
'graceful_end_on_timer': 'enable',
|
||||||
|
'graceful_restart': 'enable',
|
||||||
|
'graceful_restart_time': '30',
|
||||||
|
'graceful_stalepath_time': '31',
|
||||||
|
'graceful_update_delay': '32',
|
||||||
|
'holdtime_timer': '33',
|
||||||
|
'ibgp_multipath': 'enable',
|
||||||
|
'ignore_optional_capability': 'enable',
|
||||||
|
'keepalive_timer': '36',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'network_import_check': 'enable',
|
||||||
|
'router_id': 'test_value_39',
|
||||||
|
'scan_time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_bgp.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'always-compare-med': 'enable',
|
||||||
|
'as': '4',
|
||||||
|
'bestpath-as-path-ignore': 'enable',
|
||||||
|
'bestpath-cmp-confed-aspath': 'enable',
|
||||||
|
'bestpath-cmp-routerid': 'enable',
|
||||||
|
'bestpath-med-confed': 'enable',
|
||||||
|
'bestpath-med-missing-as-worst': 'enable',
|
||||||
|
'client-to-client-reflection': 'enable',
|
||||||
|
'cluster-id': 'test_value_11',
|
||||||
|
'confederation-identifier': '12',
|
||||||
|
'dampening': 'enable',
|
||||||
|
'dampening-max-suppress-time': '14',
|
||||||
|
'dampening-reachability-half-life': '15',
|
||||||
|
'dampening-reuse': '16',
|
||||||
|
'dampening-route-map': 'test_value_17',
|
||||||
|
'dampening-suppress': '18',
|
||||||
|
'dampening-unreachability-half-life': '19',
|
||||||
|
'default-local-preference': '20',
|
||||||
|
'deterministic-med': 'enable',
|
||||||
|
'distance-external': '22',
|
||||||
|
'distance-internal': '23',
|
||||||
|
'distance-local': '24',
|
||||||
|
'ebgp-multipath': 'enable',
|
||||||
|
'enforce-first-as': 'enable',
|
||||||
|
'fast-external-failover': 'enable',
|
||||||
|
'graceful-end-on-timer': 'enable',
|
||||||
|
'graceful-restart': 'enable',
|
||||||
|
'graceful-restart-time': '30',
|
||||||
|
'graceful-stalepath-time': '31',
|
||||||
|
'graceful-update-delay': '32',
|
||||||
|
'holdtime-timer': '33',
|
||||||
|
'ibgp-multipath': 'enable',
|
||||||
|
'ignore-optional-capability': 'enable',
|
||||||
|
'keepalive-timer': '36',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'network-import-check': 'enable',
|
||||||
|
'router-id': 'test_value_39',
|
||||||
|
'scan-time': '40',
|
||||||
|
'synchronization': 'enable'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'bgp', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,159 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_multicast
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_multicast.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast': {'multicast_routing': 'enable',
|
||||||
|
'route_limit': '4',
|
||||||
|
'route_threshold': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-routing': 'enable',
|
||||||
|
'route-limit': '4',
|
||||||
|
'route-threshold': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast': {'multicast_routing': 'enable',
|
||||||
|
'route_limit': '4',
|
||||||
|
'route_threshold': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-routing': 'enable',
|
||||||
|
'route-limit': '4',
|
||||||
|
'route-threshold': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast': {'multicast_routing': 'enable',
|
||||||
|
'route_limit': '4',
|
||||||
|
'route_threshold': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-routing': 'enable',
|
||||||
|
'route-limit': '4',
|
||||||
|
'route-threshold': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'multicast_routing': 'enable',
|
||||||
|
'route_limit': '4',
|
||||||
|
'route_threshold': '5'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-routing': 'enable',
|
||||||
|
'route-limit': '4',
|
||||||
|
'route-threshold': '5'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,159 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_multicast6
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_multicast6.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast6_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast6': {'multicast_pmtu': 'enable',
|
||||||
|
'multicast_routing': 'enable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-pmtu': 'enable',
|
||||||
|
'multicast-routing': 'enable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast6_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast6': {'multicast_pmtu': 'enable',
|
||||||
|
'multicast_routing': 'enable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-pmtu': 'enable',
|
||||||
|
'multicast-routing': 'enable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast6_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast6': {'multicast_pmtu': 'enable',
|
||||||
|
'multicast_routing': 'enable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-pmtu': 'enable',
|
||||||
|
'multicast-routing': 'enable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast6_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast6': {
|
||||||
|
'random_attribute_not_valid': 'tag', 'multicast_pmtu': 'enable',
|
||||||
|
'multicast_routing': 'enable',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {'multicast-pmtu': 'enable',
|
||||||
|
'multicast-routing': 'enable',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,209 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_multicast_flow
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_multicast_flow.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_flow_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast_flow': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast_flow.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast-flow', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_flow_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast_flow': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast_flow.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast-flow', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_flow_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_multicast_flow': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast_flow.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'multicast-flow', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_flow_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_multicast_flow': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast_flow.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'multicast-flow', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_flow_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast_flow': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast_flow.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast-flow', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_multicast_flow_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_multicast_flow': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_multicast_flow.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'multicast-flow', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,335 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_ospf
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_ospf.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf': {
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database_overflow': 'enable',
|
||||||
|
'database_overflow_max_lsas': '7',
|
||||||
|
'database_overflow_time_to_recover': '8',
|
||||||
|
'default_information_metric': '9',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_12',
|
||||||
|
'default_metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance_external': '15',
|
||||||
|
'distance_inter_area': '16',
|
||||||
|
'distance_intra_area': '17',
|
||||||
|
'distribute_list_in': 'test_value_18',
|
||||||
|
'distribute_route_map_in': 'test_value_19',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'restart_mode': 'none',
|
||||||
|
'restart_period': '22',
|
||||||
|
'rfc1583_compatible': 'enable',
|
||||||
|
'router_id': 'test_value_24',
|
||||||
|
'spf_timers': 'test_value_25',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database-overflow': 'enable',
|
||||||
|
'database-overflow-max-lsas': '7',
|
||||||
|
'database-overflow-time-to-recover': '8',
|
||||||
|
'default-information-metric': '9',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_12',
|
||||||
|
'default-metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance-external': '15',
|
||||||
|
'distance-inter-area': '16',
|
||||||
|
'distance-intra-area': '17',
|
||||||
|
'distribute-list-in': 'test_value_18',
|
||||||
|
'distribute-route-map-in': 'test_value_19',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'restart-mode': 'none',
|
||||||
|
'restart-period': '22',
|
||||||
|
'rfc1583-compatible': 'enable',
|
||||||
|
'router-id': 'test_value_24',
|
||||||
|
'spf-timers': 'test_value_25',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf': {
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database_overflow': 'enable',
|
||||||
|
'database_overflow_max_lsas': '7',
|
||||||
|
'database_overflow_time_to_recover': '8',
|
||||||
|
'default_information_metric': '9',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_12',
|
||||||
|
'default_metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance_external': '15',
|
||||||
|
'distance_inter_area': '16',
|
||||||
|
'distance_intra_area': '17',
|
||||||
|
'distribute_list_in': 'test_value_18',
|
||||||
|
'distribute_route_map_in': 'test_value_19',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'restart_mode': 'none',
|
||||||
|
'restart_period': '22',
|
||||||
|
'rfc1583_compatible': 'enable',
|
||||||
|
'router_id': 'test_value_24',
|
||||||
|
'spf_timers': 'test_value_25',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database-overflow': 'enable',
|
||||||
|
'database-overflow-max-lsas': '7',
|
||||||
|
'database-overflow-time-to-recover': '8',
|
||||||
|
'default-information-metric': '9',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_12',
|
||||||
|
'default-metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance-external': '15',
|
||||||
|
'distance-inter-area': '16',
|
||||||
|
'distance-intra-area': '17',
|
||||||
|
'distribute-list-in': 'test_value_18',
|
||||||
|
'distribute-route-map-in': 'test_value_19',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'restart-mode': 'none',
|
||||||
|
'restart-period': '22',
|
||||||
|
'rfc1583-compatible': 'enable',
|
||||||
|
'router-id': 'test_value_24',
|
||||||
|
'spf-timers': 'test_value_25',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf': {
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database_overflow': 'enable',
|
||||||
|
'database_overflow_max_lsas': '7',
|
||||||
|
'database_overflow_time_to_recover': '8',
|
||||||
|
'default_information_metric': '9',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_12',
|
||||||
|
'default_metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance_external': '15',
|
||||||
|
'distance_inter_area': '16',
|
||||||
|
'distance_intra_area': '17',
|
||||||
|
'distribute_list_in': 'test_value_18',
|
||||||
|
'distribute_route_map_in': 'test_value_19',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'restart_mode': 'none',
|
||||||
|
'restart_period': '22',
|
||||||
|
'rfc1583_compatible': 'enable',
|
||||||
|
'router_id': 'test_value_24',
|
||||||
|
'spf_timers': 'test_value_25',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database-overflow': 'enable',
|
||||||
|
'database-overflow-max-lsas': '7',
|
||||||
|
'database-overflow-time-to-recover': '8',
|
||||||
|
'default-information-metric': '9',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_12',
|
||||||
|
'default-metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance-external': '15',
|
||||||
|
'distance-inter-area': '16',
|
||||||
|
'distance-intra-area': '17',
|
||||||
|
'distribute-list-in': 'test_value_18',
|
||||||
|
'distribute-route-map-in': 'test_value_19',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'restart-mode': 'none',
|
||||||
|
'restart-period': '22',
|
||||||
|
'rfc1583-compatible': 'enable',
|
||||||
|
'router-id': 'test_value_24',
|
||||||
|
'spf-timers': 'test_value_25',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database_overflow': 'enable',
|
||||||
|
'database_overflow_max_lsas': '7',
|
||||||
|
'database_overflow_time_to_recover': '8',
|
||||||
|
'default_information_metric': '9',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_12',
|
||||||
|
'default_metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance_external': '15',
|
||||||
|
'distance_inter_area': '16',
|
||||||
|
'distance_intra_area': '17',
|
||||||
|
'distribute_list_in': 'test_value_18',
|
||||||
|
'distribute_route_map_in': 'test_value_19',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'restart_mode': 'none',
|
||||||
|
'restart_period': '22',
|
||||||
|
'rfc1583_compatible': 'enable',
|
||||||
|
'router_id': 'test_value_24',
|
||||||
|
'spf_timers': 'test_value_25',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'database-overflow': 'enable',
|
||||||
|
'database-overflow-max-lsas': '7',
|
||||||
|
'database-overflow-time-to-recover': '8',
|
||||||
|
'default-information-metric': '9',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_12',
|
||||||
|
'default-metric': '13',
|
||||||
|
'distance': '14',
|
||||||
|
'distance-external': '15',
|
||||||
|
'distance-inter-area': '16',
|
||||||
|
'distance-intra-area': '17',
|
||||||
|
'distribute-list-in': 'test_value_18',
|
||||||
|
'distribute-route-map-in': 'test_value_19',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'restart-mode': 'none',
|
||||||
|
'restart-period': '22',
|
||||||
|
'rfc1583-compatible': 'enable',
|
||||||
|
'router-id': 'test_value_24',
|
||||||
|
'spf-timers': 'test_value_25',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,239 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_ospf6
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_ospf6.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf6_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf6': {
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default_information_metric': '6',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_9',
|
||||||
|
'default_metric': '10',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'router_id': 'test_value_12',
|
||||||
|
'spf_timers': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default-information-metric': '6',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_9',
|
||||||
|
'default-metric': '10',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'router-id': 'test_value_12',
|
||||||
|
'spf-timers': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf6_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf6': {
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default_information_metric': '6',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_9',
|
||||||
|
'default_metric': '10',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'router_id': 'test_value_12',
|
||||||
|
'spf_timers': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default-information-metric': '6',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_9',
|
||||||
|
'default-metric': '10',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'router-id': 'test_value_12',
|
||||||
|
'spf-timers': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf6_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf6': {
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default_information_metric': '6',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_9',
|
||||||
|
'default_metric': '10',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'router_id': 'test_value_12',
|
||||||
|
'spf_timers': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default-information-metric': '6',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_9',
|
||||||
|
'default-metric': '10',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'router-id': 'test_value_12',
|
||||||
|
'spf-timers': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_ospf6_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_ospf6': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'abr_type': 'cisco',
|
||||||
|
'auto_cost_ref_bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default_information_metric': '6',
|
||||||
|
'default_information_metric_type': '1',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_information_route_map': 'test_value_9',
|
||||||
|
'default_metric': '10',
|
||||||
|
'log_neighbour_changes': 'enable',
|
||||||
|
'router_id': 'test_value_12',
|
||||||
|
'spf_timers': 'test_value_13',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_ospf6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'abr-type': 'cisco',
|
||||||
|
'auto-cost-ref-bandwidth': '4',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'default-information-metric': '6',
|
||||||
|
'default-information-metric-type': '1',
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-information-route-map': 'test_value_9',
|
||||||
|
'default-metric': '10',
|
||||||
|
'log-neighbour-changes': 'enable',
|
||||||
|
'router-id': 'test_value_12',
|
||||||
|
'spf-timers': 'test_value_13',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'ospf6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,339 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_policy
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_policy.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy': {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst_negate': 'enable',
|
||||||
|
'end_port': '6',
|
||||||
|
'end_source_port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output_device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq_num': '11',
|
||||||
|
'src_negate': 'enable',
|
||||||
|
'start_port': '13',
|
||||||
|
'start_source_port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos_mask': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst-negate': 'enable',
|
||||||
|
'end-port': '6',
|
||||||
|
'end-source-port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output-device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq-num': '11',
|
||||||
|
'src-negate': 'enable',
|
||||||
|
'start-port': '13',
|
||||||
|
'start-source-port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos-mask': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy': {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst_negate': 'enable',
|
||||||
|
'end_port': '6',
|
||||||
|
'end_source_port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output_device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq_num': '11',
|
||||||
|
'src_negate': 'enable',
|
||||||
|
'start_port': '13',
|
||||||
|
'start_source_port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos_mask': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst-negate': 'enable',
|
||||||
|
'end-port': '6',
|
||||||
|
'end-source-port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output-device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq-num': '11',
|
||||||
|
'src-negate': 'enable',
|
||||||
|
'start-port': '13',
|
||||||
|
'start-source-port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos-mask': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_policy': {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst_negate': 'enable',
|
||||||
|
'end_port': '6',
|
||||||
|
'end_source_port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output_device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq_num': '11',
|
||||||
|
'src_negate': 'enable',
|
||||||
|
'start_port': '13',
|
||||||
|
'start_source_port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos_mask': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'policy', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_policy': {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst_negate': 'enable',
|
||||||
|
'end_port': '6',
|
||||||
|
'end_source_port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output_device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq_num': '11',
|
||||||
|
'src_negate': 'enable',
|
||||||
|
'start_port': '13',
|
||||||
|
'start_source_port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos_mask': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'policy', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy': {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst_negate': 'enable',
|
||||||
|
'end_port': '6',
|
||||||
|
'end_source_port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output_device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq_num': '11',
|
||||||
|
'src_negate': 'enable',
|
||||||
|
'start_port': '13',
|
||||||
|
'start_source_port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos_mask': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst-negate': 'enable',
|
||||||
|
'end-port': '6',
|
||||||
|
'end-source-port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output-device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq-num': '11',
|
||||||
|
'src-negate': 'enable',
|
||||||
|
'start-port': '13',
|
||||||
|
'start-source-port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos-mask': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst_negate': 'enable',
|
||||||
|
'end_port': '6',
|
||||||
|
'end_source_port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output_device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq_num': '11',
|
||||||
|
'src_negate': 'enable',
|
||||||
|
'start_port': '13',
|
||||||
|
'start_source_port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos_mask': 'test_value_17'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'action': 'deny',
|
||||||
|
'comments': 'test_value_4',
|
||||||
|
'dst-negate': 'enable',
|
||||||
|
'end-port': '6',
|
||||||
|
'end-source-port': '7',
|
||||||
|
'gateway': 'test_value_8',
|
||||||
|
'output-device': 'test_value_9',
|
||||||
|
'protocol': '10',
|
||||||
|
'seq-num': '11',
|
||||||
|
'src-negate': 'enable',
|
||||||
|
'start-port': '13',
|
||||||
|
'start-source-port': '14',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_16',
|
||||||
|
'tos-mask': 'test_value_17'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,319 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_policy6
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_policy6.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy6_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy6': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end_port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input_device': 'test_value_7',
|
||||||
|
'output_device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq_num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start_port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos_mask': 'test_value_15'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end-port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input-device': 'test_value_7',
|
||||||
|
'output-device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq-num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start-port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos-mask': 'test_value_15'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy6_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy6': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end_port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input_device': 'test_value_7',
|
||||||
|
'output_device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq_num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start_port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos_mask': 'test_value_15'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end-port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input-device': 'test_value_7',
|
||||||
|
'output-device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq-num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start-port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos-mask': 'test_value_15'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy6_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_policy6': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end_port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input_device': 'test_value_7',
|
||||||
|
'output_device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq_num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start_port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos_mask': 'test_value_15'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'policy6', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy6_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_policy6': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end_port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input_device': 'test_value_7',
|
||||||
|
'output_device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq_num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start_port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos_mask': 'test_value_15'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'policy6', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy6_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy6': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end_port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input_device': 'test_value_7',
|
||||||
|
'output_device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq_num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start_port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos_mask': 'test_value_15'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end-port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input-device': 'test_value_7',
|
||||||
|
'output-device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq-num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start-port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos-mask': 'test_value_15'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_policy6_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_policy6': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end_port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input_device': 'test_value_7',
|
||||||
|
'output_device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq_num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start_port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos_mask': 'test_value_15'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_policy6.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'dst': 'test_value_4',
|
||||||
|
'end-port': '5',
|
||||||
|
'gateway': 'test_value_6',
|
||||||
|
'input-device': 'test_value_7',
|
||||||
|
'output-device': 'test_value_8',
|
||||||
|
'protocol': '9',
|
||||||
|
'seq-num': '10',
|
||||||
|
'src': 'test_value_11',
|
||||||
|
'start-port': '12',
|
||||||
|
'status': 'enable',
|
||||||
|
'tos': 'test_value_14',
|
||||||
|
'tos-mask': 'test_value_15'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'policy6', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,219 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_prefix_list
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_prefix_list.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_prefix_list_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_prefix_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_prefix_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'prefix-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_prefix_list_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_prefix_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_prefix_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'prefix-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_prefix_list_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_prefix_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_prefix_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'prefix-list', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_prefix_list_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_prefix_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_prefix_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'prefix-list', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_prefix_list_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_prefix_list': {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_prefix_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'prefix-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_prefix_list_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_prefix_list': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_prefix_list.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'comments': 'test_value_3',
|
||||||
|
'name': 'default_name_4',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'prefix-list', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,207 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_rip
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_rip.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_rip_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_rip': {
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_metric': '4',
|
||||||
|
'garbage_timer': '5',
|
||||||
|
'max_out_metric': '6',
|
||||||
|
'recv_buffer_size': '7',
|
||||||
|
'timeout_timer': '8',
|
||||||
|
'update_timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_rip.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-metric': '4',
|
||||||
|
'garbage-timer': '5',
|
||||||
|
'max-out-metric': '6',
|
||||||
|
'recv-buffer-size': '7',
|
||||||
|
'timeout-timer': '8',
|
||||||
|
'update-timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'rip', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_rip_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_rip': {
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_metric': '4',
|
||||||
|
'garbage_timer': '5',
|
||||||
|
'max_out_metric': '6',
|
||||||
|
'recv_buffer_size': '7',
|
||||||
|
'timeout_timer': '8',
|
||||||
|
'update_timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_rip.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-metric': '4',
|
||||||
|
'garbage-timer': '5',
|
||||||
|
'max-out-metric': '6',
|
||||||
|
'recv-buffer-size': '7',
|
||||||
|
'timeout-timer': '8',
|
||||||
|
'update-timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'rip', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_rip_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_rip': {
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_metric': '4',
|
||||||
|
'garbage_timer': '5',
|
||||||
|
'max_out_metric': '6',
|
||||||
|
'recv_buffer_size': '7',
|
||||||
|
'timeout_timer': '8',
|
||||||
|
'update_timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_rip.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-metric': '4',
|
||||||
|
'garbage-timer': '5',
|
||||||
|
'max-out-metric': '6',
|
||||||
|
'recv-buffer-size': '7',
|
||||||
|
'timeout-timer': '8',
|
||||||
|
'update-timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'rip', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_rip_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_rip': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'default_information_originate': 'enable',
|
||||||
|
'default_metric': '4',
|
||||||
|
'garbage_timer': '5',
|
||||||
|
'max_out_metric': '6',
|
||||||
|
'recv_buffer_size': '7',
|
||||||
|
'timeout_timer': '8',
|
||||||
|
'update_timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_rip.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'default-information-originate': 'enable',
|
||||||
|
'default-metric': '4',
|
||||||
|
'garbage-timer': '5',
|
||||||
|
'max-out-metric': '6',
|
||||||
|
'recv-buffer-size': '7',
|
||||||
|
'timeout-timer': '8',
|
||||||
|
'update-timer': '9',
|
||||||
|
'version': '1'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'rip', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,159 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_setting
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_setting.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_setting_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_setting': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show_filter': 'test_value_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_setting.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show-filter': 'test_value_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_setting_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_setting': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show_filter': 'test_value_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_setting.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show-filter': 'test_value_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_setting_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_setting': {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show_filter': 'test_value_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_setting.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show-filter': 'test_value_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_setting_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_setting': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show_filter': 'test_value_4'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_setting.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'hostname': 'myhostname3',
|
||||||
|
'show-filter': 'test_value_4'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'setting', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
@ -0,0 +1,379 @@
|
|||||||
|
# Copyright 2019 Fortinet, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Make coding more python3-ish
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import pytest
|
||||||
|
from mock import ANY
|
||||||
|
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||||
|
|
||||||
|
try:
|
||||||
|
from ansible.modules.network.fortios import fortios_router_static
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_router_static.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
fos_instance = FortiOSHandler(connection_mock)
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_static_creation(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_static': {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic_gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet_service': '12',
|
||||||
|
'internet_service_custom': 'test_value_13',
|
||||||
|
'link_monitor_exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq_num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual_wan_link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_static.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic-gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet-service': '12',
|
||||||
|
'internet-service-custom': 'test_value_13',
|
||||||
|
'link-monitor-exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq-num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual-wan-link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'static', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_static_creation_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_static': {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic_gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet_service': '12',
|
||||||
|
'internet_service_custom': 'test_value_13',
|
||||||
|
'link_monitor_exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq_num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual_wan_link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_static.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic-gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet-service': '12',
|
||||||
|
'internet-service-custom': 'test_value_13',
|
||||||
|
'link-monitor-exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq-num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual-wan-link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'static', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_static_removal(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_static': {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic_gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet_service': '12',
|
||||||
|
'internet_service_custom': 'test_value_13',
|
||||||
|
'link_monitor_exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq_num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual_wan_link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_static.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'static', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_static_deletion_fails(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
|
||||||
|
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'absent',
|
||||||
|
'router_static': {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic_gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet_service': '12',
|
||||||
|
'internet_service_custom': 'test_value_13',
|
||||||
|
'link_monitor_exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq_num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual_wan_link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_static.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
delete_method_mock.assert_called_with('router', 'static', mkey=ANY, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 500
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_static_idempotent(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_static': {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic_gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet_service': '12',
|
||||||
|
'internet_service_custom': 'test_value_13',
|
||||||
|
'link_monitor_exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq_num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual_wan_link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_static.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic-gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet-service': '12',
|
||||||
|
'internet-service-custom': 'test_value_13',
|
||||||
|
'link-monitor-exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq-num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual-wan-link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'static', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert not changed
|
||||||
|
assert response['status'] == 'error'
|
||||||
|
assert response['http_status'] == 404
|
||||||
|
|
||||||
|
|
||||||
|
def test_router_static_filter_foreign_attributes(mocker):
|
||||||
|
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
|
||||||
|
|
||||||
|
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
|
||||||
|
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
|
||||||
|
|
||||||
|
input_data = {
|
||||||
|
'username': 'admin',
|
||||||
|
'state': 'present',
|
||||||
|
'router_static': {
|
||||||
|
'random_attribute_not_valid': 'tag',
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic_gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet_service': '12',
|
||||||
|
'internet_service_custom': 'test_value_13',
|
||||||
|
'link_monitor_exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq_num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual_wan_link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
},
|
||||||
|
'vdom': 'root'}
|
||||||
|
|
||||||
|
is_error, changed, response = fortios_router_static.fortios_router(input_data, fos_instance)
|
||||||
|
|
||||||
|
expected_data = {
|
||||||
|
'bfd': 'enable',
|
||||||
|
'blackhole': 'enable',
|
||||||
|
'comment': 'Optional comments.',
|
||||||
|
'device': 'test_value_6',
|
||||||
|
'distance': '7',
|
||||||
|
'dst': 'test_value_8',
|
||||||
|
'dstaddr': 'test_value_9',
|
||||||
|
'dynamic-gateway': 'enable',
|
||||||
|
'gateway': 'test_value_11',
|
||||||
|
'internet-service': '12',
|
||||||
|
'internet-service-custom': 'test_value_13',
|
||||||
|
'link-monitor-exempt': 'enable',
|
||||||
|
'priority': '15',
|
||||||
|
'seq-num': '16',
|
||||||
|
'src': 'test_value_17',
|
||||||
|
'status': 'enable',
|
||||||
|
'virtual-wan-link': 'enable',
|
||||||
|
'vrf': '20',
|
||||||
|
'weight': '21'
|
||||||
|
}
|
||||||
|
|
||||||
|
set_method_mock.assert_called_with('router', 'static', data=expected_data, vdom='root')
|
||||||
|
schema_method_mock.assert_not_called()
|
||||||
|
assert not is_error
|
||||||
|
assert changed
|
||||||
|
assert response['status'] == 'success'
|
||||||
|
assert response['http_status'] == 200
|
Loading…
Reference in New Issue