mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 3 (#60678)
* FortiOS modules for 2.9 - 3 * Remove default values in doc, as suggested from review * Retriggering due to shippable failure * Update fortios_firewall_ipv6_eh_filter.py * Update fortios_firewall_ipmacbinding_setting.py * Update fortios_firewall_ippool.py * Update fortios_firewall_local_in_policy6.py * Update fortios_firewall_local_in_policy.pypull/60806/head
parent
d8f9904f43
commit
decb016a2d
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -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_firewall_internet_service_group
|
||||
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_firewall_internet_service_group.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_internet_service_group_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',
|
||||
'firewall_internet_service_group': {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-group', 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_firewall_internet_service_group_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',
|
||||
'firewall_internet_service_group': {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-group', 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_firewall_internet_service_group_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',
|
||||
'firewall_internet_service_group': {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'internet-service-group', 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_firewall_internet_service_group_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',
|
||||
'firewall_internet_service_group': {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'internet-service-group', 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_firewall_internet_service_group_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',
|
||||
'firewall_internet_service_group': {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-group', 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_firewall_internet_service_group_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',
|
||||
'firewall_internet_service_group': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-group', 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_firewall_ip_translation
|
||||
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_firewall_ip_translation.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_ip_translation_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',
|
||||
'firewall_ip_translation': {
|
||||
'endip': 'test_value_3',
|
||||
'map_startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ip_translation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'endip': 'test_value_3',
|
||||
'map-startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ip-translation', 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_firewall_ip_translation_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',
|
||||
'firewall_ip_translation': {
|
||||
'endip': 'test_value_3',
|
||||
'map_startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ip_translation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'endip': 'test_value_3',
|
||||
'map-startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ip-translation', 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_firewall_ip_translation_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',
|
||||
'firewall_ip_translation': {
|
||||
'endip': 'test_value_3',
|
||||
'map_startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ip_translation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ip-translation', 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_firewall_ip_translation_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',
|
||||
'firewall_ip_translation': {
|
||||
'endip': 'test_value_3',
|
||||
'map_startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ip_translation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ip-translation', 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_firewall_ip_translation_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',
|
||||
'firewall_ip_translation': {
|
||||
'endip': 'test_value_3',
|
||||
'map_startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ip_translation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'endip': 'test_value_3',
|
||||
'map-startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ip-translation', 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_firewall_ip_translation_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',
|
||||
'firewall_ip_translation': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'endip': 'test_value_3',
|
||||
'map_startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ip_translation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'endip': 'test_value_3',
|
||||
'map-startip': 'test_value_4',
|
||||
'startip': 'test_value_5',
|
||||
'transid': '6',
|
||||
'type': 'SCTP'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ip-translation', 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,167 @@
|
||||
# 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_firewall_ipmacbinding_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_firewall_ipmacbinding_setting.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_ipmacbinding_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',
|
||||
'firewall_ipmacbinding_setting': {
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_setting.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', '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_firewall_ipmacbinding_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',
|
||||
'firewall_ipmacbinding_setting': {
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_setting.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', '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_firewall_ipmacbinding_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',
|
||||
'firewall_ipmacbinding_setting': {
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_setting.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', '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_firewall_ipmacbinding_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',
|
||||
'firewall_ipmacbinding_setting': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_setting.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'bindthroughfw': 'enable',
|
||||
'bindtofw': 'enable',
|
||||
'undefinedhost': 'allow'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', '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,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_firewall_ipmacbinding_table
|
||||
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_firewall_ipmacbinding_table.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_ipmacbinding_table_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',
|
||||
'firewall_ipmacbinding_table': {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq_num': '6',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_table.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq-num': '6',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', 'table', 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_firewall_ipmacbinding_table_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',
|
||||
'firewall_ipmacbinding_table': {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq_num': '6',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_table.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq-num': '6',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', 'table', 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_firewall_ipmacbinding_table_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',
|
||||
'firewall_ipmacbinding_table': {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq_num': '6',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_table.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall.ipmacbinding', 'table', 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_firewall_ipmacbinding_table_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',
|
||||
'firewall_ipmacbinding_table': {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq_num': '6',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_table.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall.ipmacbinding', 'table', 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_firewall_ipmacbinding_table_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',
|
||||
'firewall_ipmacbinding_table': {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq_num': '6',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_table.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq-num': '6',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', 'table', 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_firewall_ipmacbinding_table_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',
|
||||
'firewall_ipmacbinding_table': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq_num': '6',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipmacbinding_table.fortios_firewall_ipmacbinding(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip': 'test_value_3',
|
||||
'mac': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'seq-num': '6',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall.ipmacbinding', 'table', 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,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_firewall_ippool
|
||||
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_firewall_ippool.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_ippool_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',
|
||||
'firewall_ippool': {
|
||||
'arp_intf': 'test_value_3',
|
||||
'arp_reply': 'disable',
|
||||
'associated_interface': 'test_value_5',
|
||||
'block_size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num_blocks_per_user': '10',
|
||||
'pba_timeout': '11',
|
||||
'permit_any_host': 'disable',
|
||||
'source_endip': 'test_value_13',
|
||||
'source_startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'arp-intf': 'test_value_3',
|
||||
'arp-reply': 'disable',
|
||||
'associated-interface': 'test_value_5',
|
||||
'block-size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num-blocks-per-user': '10',
|
||||
'pba-timeout': '11',
|
||||
'permit-any-host': 'disable',
|
||||
'source-endip': 'test_value_13',
|
||||
'source-startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool', 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_firewall_ippool_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',
|
||||
'firewall_ippool': {
|
||||
'arp_intf': 'test_value_3',
|
||||
'arp_reply': 'disable',
|
||||
'associated_interface': 'test_value_5',
|
||||
'block_size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num_blocks_per_user': '10',
|
||||
'pba_timeout': '11',
|
||||
'permit_any_host': 'disable',
|
||||
'source_endip': 'test_value_13',
|
||||
'source_startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'arp-intf': 'test_value_3',
|
||||
'arp-reply': 'disable',
|
||||
'associated-interface': 'test_value_5',
|
||||
'block-size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num-blocks-per-user': '10',
|
||||
'pba-timeout': '11',
|
||||
'permit-any-host': 'disable',
|
||||
'source-endip': 'test_value_13',
|
||||
'source-startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool', 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_firewall_ippool_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',
|
||||
'firewall_ippool': {
|
||||
'arp_intf': 'test_value_3',
|
||||
'arp_reply': 'disable',
|
||||
'associated_interface': 'test_value_5',
|
||||
'block_size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num_blocks_per_user': '10',
|
||||
'pba_timeout': '11',
|
||||
'permit_any_host': 'disable',
|
||||
'source_endip': 'test_value_13',
|
||||
'source_startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ippool', 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_firewall_ippool_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',
|
||||
'firewall_ippool': {
|
||||
'arp_intf': 'test_value_3',
|
||||
'arp_reply': 'disable',
|
||||
'associated_interface': 'test_value_5',
|
||||
'block_size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num_blocks_per_user': '10',
|
||||
'pba_timeout': '11',
|
||||
'permit_any_host': 'disable',
|
||||
'source_endip': 'test_value_13',
|
||||
'source_startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ippool', 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_firewall_ippool_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',
|
||||
'firewall_ippool': {
|
||||
'arp_intf': 'test_value_3',
|
||||
'arp_reply': 'disable',
|
||||
'associated_interface': 'test_value_5',
|
||||
'block_size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num_blocks_per_user': '10',
|
||||
'pba_timeout': '11',
|
||||
'permit_any_host': 'disable',
|
||||
'source_endip': 'test_value_13',
|
||||
'source_startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'arp-intf': 'test_value_3',
|
||||
'arp-reply': 'disable',
|
||||
'associated-interface': 'test_value_5',
|
||||
'block-size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num-blocks-per-user': '10',
|
||||
'pba-timeout': '11',
|
||||
'permit-any-host': 'disable',
|
||||
'source-endip': 'test_value_13',
|
||||
'source-startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool', 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_firewall_ippool_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',
|
||||
'firewall_ippool': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'arp_intf': 'test_value_3',
|
||||
'arp_reply': 'disable',
|
||||
'associated_interface': 'test_value_5',
|
||||
'block_size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num_blocks_per_user': '10',
|
||||
'pba_timeout': '11',
|
||||
'permit_any_host': 'disable',
|
||||
'source_endip': 'test_value_13',
|
||||
'source_startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'arp-intf': 'test_value_3',
|
||||
'arp-reply': 'disable',
|
||||
'associated-interface': 'test_value_5',
|
||||
'block-size': '6',
|
||||
'comments': 'test_value_7',
|
||||
'endip': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'num-blocks-per-user': '10',
|
||||
'pba-timeout': '11',
|
||||
'permit-any-host': 'disable',
|
||||
'source-endip': 'test_value_13',
|
||||
'source-startip': 'test_value_14',
|
||||
'startip': 'test_value_15',
|
||||
'type': 'overload'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool', 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,229 @@
|
||||
# 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_firewall_ippool6
|
||||
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_firewall_ippool6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_ippool6_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',
|
||||
'firewall_ippool6': {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool6', 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_firewall_ippool6_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',
|
||||
'firewall_ippool6': {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool6', 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_firewall_ippool6_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',
|
||||
'firewall_ippool6': {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ippool6', 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_firewall_ippool6_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',
|
||||
'firewall_ippool6': {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ippool6', 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_firewall_ippool6_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',
|
||||
'firewall_ippool6': {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool6', 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_firewall_ippool6_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',
|
||||
'firewall_ippool6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ippool6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'endip': 'test_value_4',
|
||||
'name': 'default_name_5',
|
||||
'startip': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ippool6', 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_firewall_ipv6_eh_filter
|
||||
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_firewall_ipv6_eh_filter.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_ipv6_eh_filter_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',
|
||||
'firewall_ipv6_eh_filter': {
|
||||
'auth': 'enable',
|
||||
'dest_opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt_type': '6',
|
||||
'hop_opt': 'enable',
|
||||
'no_next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing_type': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipv6_eh_filter.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auth': 'enable',
|
||||
'dest-opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt-type': '6',
|
||||
'hop-opt': 'enable',
|
||||
'no-next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing-type': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ipv6-eh-filter', 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_firewall_ipv6_eh_filter_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',
|
||||
'firewall_ipv6_eh_filter': {
|
||||
'auth': 'enable',
|
||||
'dest_opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt_type': '6',
|
||||
'hop_opt': 'enable',
|
||||
'no_next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing_type': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipv6_eh_filter.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auth': 'enable',
|
||||
'dest-opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt-type': '6',
|
||||
'hop-opt': 'enable',
|
||||
'no-next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing-type': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ipv6-eh-filter', 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_firewall_ipv6_eh_filter_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',
|
||||
'firewall_ipv6_eh_filter': {
|
||||
'auth': 'enable',
|
||||
'dest_opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt_type': '6',
|
||||
'hop_opt': 'enable',
|
||||
'no_next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing_type': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipv6_eh_filter.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auth': 'enable',
|
||||
'dest-opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt-type': '6',
|
||||
'hop-opt': 'enable',
|
||||
'no-next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing-type': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ipv6-eh-filter', 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_firewall_ipv6_eh_filter_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',
|
||||
'firewall_ipv6_eh_filter': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'auth': 'enable',
|
||||
'dest_opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt_type': '6',
|
||||
'hop_opt': 'enable',
|
||||
'no_next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing_type': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ipv6_eh_filter.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auth': 'enable',
|
||||
'dest-opt': 'enable',
|
||||
'fragment': 'enable',
|
||||
'hdopt-type': '6',
|
||||
'hop-opt': 'enable',
|
||||
'no-next': 'enable',
|
||||
'routing': 'enable',
|
||||
'routing-type': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ipv6-eh-filter', 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,279 @@
|
||||
# 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_firewall_ldb_monitor
|
||||
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_firewall_ldb_monitor.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_ldb_monitor_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',
|
||||
'firewall_ldb_monitor': {
|
||||
'http_get': 'test_value_3',
|
||||
'http_match': 'test_value_4',
|
||||
'http_max_redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ldb_monitor.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'http-get': 'test_value_3',
|
||||
'http-match': 'test_value_4',
|
||||
'http-max-redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ldb-monitor', 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_firewall_ldb_monitor_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',
|
||||
'firewall_ldb_monitor': {
|
||||
'http_get': 'test_value_3',
|
||||
'http_match': 'test_value_4',
|
||||
'http_max_redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ldb_monitor.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'http-get': 'test_value_3',
|
||||
'http-match': 'test_value_4',
|
||||
'http-max-redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ldb-monitor', 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_firewall_ldb_monitor_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',
|
||||
'firewall_ldb_monitor': {
|
||||
'http_get': 'test_value_3',
|
||||
'http_match': 'test_value_4',
|
||||
'http_max_redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ldb_monitor.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ldb-monitor', 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_firewall_ldb_monitor_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',
|
||||
'firewall_ldb_monitor': {
|
||||
'http_get': 'test_value_3',
|
||||
'http_match': 'test_value_4',
|
||||
'http_max_redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ldb_monitor.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'ldb-monitor', 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_firewall_ldb_monitor_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',
|
||||
'firewall_ldb_monitor': {
|
||||
'http_get': 'test_value_3',
|
||||
'http_match': 'test_value_4',
|
||||
'http_max_redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ldb_monitor.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'http-get': 'test_value_3',
|
||||
'http-match': 'test_value_4',
|
||||
'http-max-redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ldb-monitor', 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_firewall_ldb_monitor_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',
|
||||
'firewall_ldb_monitor': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'http_get': 'test_value_3',
|
||||
'http_match': 'test_value_4',
|
||||
'http_max_redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_ldb_monitor.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'http-get': 'test_value_3',
|
||||
'http-match': 'test_value_4',
|
||||
'http-max-redirects': '5',
|
||||
'interval': '6',
|
||||
'name': 'default_name_7',
|
||||
'port': '8',
|
||||
'retry': '9',
|
||||
'timeout': '10',
|
||||
'type': 'ping'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'ldb-monitor', 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,259 @@
|
||||
# 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_firewall_local_in_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_firewall_local_in_policy.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_local_in_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',
|
||||
'firewall_local_in_policy': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha_mgmt_intf_only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha-mgmt-intf-only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha_mgmt_intf_only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha-mgmt-intf-only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha_mgmt_intf_only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha_mgmt_intf_only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha_mgmt_intf_only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha-mgmt-intf-only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha_mgmt_intf_only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'ha-mgmt-intf-only': 'enable',
|
||||
'intf': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'schedule': 'test_value_8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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,249 @@
|
||||
# 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_firewall_local_in_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_firewall_local_in_policy6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_local_in_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',
|
||||
'firewall_local_in_policy6': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy6': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy6': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy6': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy6': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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_firewall_local_in_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',
|
||||
'firewall_local_in_policy6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_local_in_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'intf': 'test_value_5',
|
||||
'policyid': '6',
|
||||
'schedule': 'test_value_7',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'local-in-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,279 @@
|
||||
# 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_firewall_multicast_address
|
||||
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_firewall_multicast_address.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_multicast_address_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',
|
||||
'firewall_multicast_address': {
|
||||
'associated_interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start_ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'associated-interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start-ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address', 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_firewall_multicast_address_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',
|
||||
'firewall_multicast_address': {
|
||||
'associated_interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start_ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'associated-interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start-ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address', 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_firewall_multicast_address_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',
|
||||
'firewall_multicast_address': {
|
||||
'associated_interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start_ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-address', 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_firewall_multicast_address_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',
|
||||
'firewall_multicast_address': {
|
||||
'associated_interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start_ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-address', 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_firewall_multicast_address_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',
|
||||
'firewall_multicast_address': {
|
||||
'associated_interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start_ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'associated-interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start-ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address', 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_firewall_multicast_address_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',
|
||||
'firewall_multicast_address': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'associated_interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start_ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'associated-interface': 'test_value_3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'start-ip': 'test_value_8',
|
||||
'subnet': 'test_value_9',
|
||||
'type': 'multicastrange',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address', 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_firewall_multicast_address6
|
||||
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_firewall_multicast_address6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_multicast_address6_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',
|
||||
'firewall_multicast_address6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address6', 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_firewall_multicast_address6_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',
|
||||
'firewall_multicast_address6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address6', 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_firewall_multicast_address6_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',
|
||||
'firewall_multicast_address6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-address6', 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_firewall_multicast_address6_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',
|
||||
'firewall_multicast_address6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-address6', 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_firewall_multicast_address6_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',
|
||||
'firewall_multicast_address6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address6', 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_firewall_multicast_address6_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',
|
||||
'firewall_multicast_address6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'ip6': 'test_value_5',
|
||||
'name': 'default_name_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-address6', 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,309 @@
|
||||
# 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_firewall_multicast_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_firewall_multicast_policy.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_multicast_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',
|
||||
'firewall_multicast_policy': {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end_port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat_ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start_port': '13',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end-port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat-ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start-port': '13',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy': {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end_port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat_ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start_port': '13',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end-port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat-ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start-port': '13',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy': {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end_port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat_ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start_port': '13',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy': {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end_port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat_ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start_port': '13',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy': {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end_port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat_ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start_port': '13',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end-port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat-ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start-port': '13',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end_port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat_ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start_port': '13',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dnat': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'end-port': '6',
|
||||
'id': '7',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '9',
|
||||
'snat': 'enable',
|
||||
'snat-ip': 'test_value_11',
|
||||
'srcintf': 'test_value_12',
|
||||
'start-port': '13',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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,279 @@
|
||||
# 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_firewall_multicast_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_firewall_multicast_policy6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_multicast_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',
|
||||
'firewall_multicast_policy6': {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end_port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start_port': '10',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end-port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start-port': '10',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy6': {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end_port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start_port': '10',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end-port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start-port': '10',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy6': {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end_port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start_port': '10',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy6': {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end_port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start_port': '10',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy6': {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end_port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start_port': '10',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end-port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start-port': '10',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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_firewall_multicast_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',
|
||||
'firewall_multicast_policy6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end_port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start_port': '10',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_multicast_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'dstintf': 'test_value_4',
|
||||
'end-port': '5',
|
||||
'id': '6',
|
||||
'logtraffic': 'enable',
|
||||
'protocol': '8',
|
||||
'srcintf': 'test_value_9',
|
||||
'start-port': '10',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'multicast-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
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,359 @@
|
||||
# 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_firewall_policy46
|
||||
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_firewall_policy46.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_policy46_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',
|
||||
'firewall_policy46': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy46.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy46', 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_firewall_policy46_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',
|
||||
'firewall_policy46': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy46.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy46', 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_firewall_policy46_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',
|
||||
'firewall_policy46': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy46.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'policy46', 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_firewall_policy46_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',
|
||||
'firewall_policy46': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy46.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'policy46', 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_firewall_policy46_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',
|
||||
'firewall_policy46': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy46.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy46', 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_firewall_policy46_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',
|
||||
'firewall_policy46': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy46.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy46', 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,789 @@
|
||||
# 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_firewall_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_firewall_policy6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_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',
|
||||
'firewall_policy6': {
|
||||
'action': 'accept',
|
||||
'application_list': 'test_value_4',
|
||||
'av_profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv_forward': 'enable',
|
||||
'diffserv_reverse': 'enable',
|
||||
'diffservcode_forward': 'test_value_9',
|
||||
'diffservcode_rev': 'test_value_10',
|
||||
'dlp_sensor': 'test_value_11',
|
||||
'dscp_match': 'enable',
|
||||
'dscp_negate': 'enable',
|
||||
'dscp_value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr_negate': 'enable',
|
||||
'firewall_session_dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global_label': 'test_value_19',
|
||||
'icap_profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips_sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic_start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per_ip_shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile_group': 'test_value_34',
|
||||
'profile_protocol_options': 'test_value_35',
|
||||
'profile_type': 'single',
|
||||
'replacemsg_override_group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send_deny_packet': 'enable',
|
||||
'service_negate': 'enable',
|
||||
'session_ttl': '42',
|
||||
'spamfilter_profile': 'test_value_43',
|
||||
'srcaddr_negate': 'enable',
|
||||
'ssh_filter_profile': 'test_value_45',
|
||||
'ssl_mirror': 'enable',
|
||||
'ssl_ssh_profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '49',
|
||||
'tcp_mss_sender': '50',
|
||||
'tcp_session_without_syn': 'all',
|
||||
'timeout_send_rst': 'enable',
|
||||
'traffic_shaper': 'test_value_53',
|
||||
'traffic_shaper_reverse': 'test_value_54',
|
||||
'utm_status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan_cos_fwd': '57',
|
||||
'vlan_cos_rev': '58',
|
||||
'vlan_filter': 'test_value_59',
|
||||
'voip_profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter_profile': 'test_value_62'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'application-list': 'test_value_4',
|
||||
'av-profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv-forward': 'enable',
|
||||
'diffserv-reverse': 'enable',
|
||||
'diffservcode-forward': 'test_value_9',
|
||||
'diffservcode-rev': 'test_value_10',
|
||||
'dlp-sensor': 'test_value_11',
|
||||
'dscp-match': 'enable',
|
||||
'dscp-negate': 'enable',
|
||||
'dscp-value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr-negate': 'enable',
|
||||
'firewall-session-dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global-label': 'test_value_19',
|
||||
'icap-profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips-sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic-start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per-ip-shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile-group': 'test_value_34',
|
||||
'profile-protocol-options': 'test_value_35',
|
||||
'profile-type': 'single',
|
||||
'replacemsg-override-group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send-deny-packet': 'enable',
|
||||
'service-negate': 'enable',
|
||||
'session-ttl': '42',
|
||||
'spamfilter-profile': 'test_value_43',
|
||||
'srcaddr-negate': 'enable',
|
||||
'ssh-filter-profile': 'test_value_45',
|
||||
'ssl-mirror': 'enable',
|
||||
'ssl-ssh-profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '49',
|
||||
'tcp-mss-sender': '50',
|
||||
'tcp-session-without-syn': 'all',
|
||||
'timeout-send-rst': 'enable',
|
||||
'traffic-shaper': 'test_value_53',
|
||||
'traffic-shaper-reverse': 'test_value_54',
|
||||
'utm-status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan-cos-fwd': '57',
|
||||
'vlan-cos-rev': '58',
|
||||
'vlan-filter': 'test_value_59',
|
||||
'voip-profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter-profile': 'test_value_62'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_firewall_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',
|
||||
'firewall_policy6': {
|
||||
'action': 'accept',
|
||||
'application_list': 'test_value_4',
|
||||
'av_profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv_forward': 'enable',
|
||||
'diffserv_reverse': 'enable',
|
||||
'diffservcode_forward': 'test_value_9',
|
||||
'diffservcode_rev': 'test_value_10',
|
||||
'dlp_sensor': 'test_value_11',
|
||||
'dscp_match': 'enable',
|
||||
'dscp_negate': 'enable',
|
||||
'dscp_value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr_negate': 'enable',
|
||||
'firewall_session_dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global_label': 'test_value_19',
|
||||
'icap_profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips_sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic_start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per_ip_shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile_group': 'test_value_34',
|
||||
'profile_protocol_options': 'test_value_35',
|
||||
'profile_type': 'single',
|
||||
'replacemsg_override_group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send_deny_packet': 'enable',
|
||||
'service_negate': 'enable',
|
||||
'session_ttl': '42',
|
||||
'spamfilter_profile': 'test_value_43',
|
||||
'srcaddr_negate': 'enable',
|
||||
'ssh_filter_profile': 'test_value_45',
|
||||
'ssl_mirror': 'enable',
|
||||
'ssl_ssh_profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '49',
|
||||
'tcp_mss_sender': '50',
|
||||
'tcp_session_without_syn': 'all',
|
||||
'timeout_send_rst': 'enable',
|
||||
'traffic_shaper': 'test_value_53',
|
||||
'traffic_shaper_reverse': 'test_value_54',
|
||||
'utm_status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan_cos_fwd': '57',
|
||||
'vlan_cos_rev': '58',
|
||||
'vlan_filter': 'test_value_59',
|
||||
'voip_profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter_profile': 'test_value_62'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'application-list': 'test_value_4',
|
||||
'av-profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv-forward': 'enable',
|
||||
'diffserv-reverse': 'enable',
|
||||
'diffservcode-forward': 'test_value_9',
|
||||
'diffservcode-rev': 'test_value_10',
|
||||
'dlp-sensor': 'test_value_11',
|
||||
'dscp-match': 'enable',
|
||||
'dscp-negate': 'enable',
|
||||
'dscp-value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr-negate': 'enable',
|
||||
'firewall-session-dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global-label': 'test_value_19',
|
||||
'icap-profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips-sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic-start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per-ip-shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile-group': 'test_value_34',
|
||||
'profile-protocol-options': 'test_value_35',
|
||||
'profile-type': 'single',
|
||||
'replacemsg-override-group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send-deny-packet': 'enable',
|
||||
'service-negate': 'enable',
|
||||
'session-ttl': '42',
|
||||
'spamfilter-profile': 'test_value_43',
|
||||
'srcaddr-negate': 'enable',
|
||||
'ssh-filter-profile': 'test_value_45',
|
||||
'ssl-mirror': 'enable',
|
||||
'ssl-ssh-profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '49',
|
||||
'tcp-mss-sender': '50',
|
||||
'tcp-session-without-syn': 'all',
|
||||
'timeout-send-rst': 'enable',
|
||||
'traffic-shaper': 'test_value_53',
|
||||
'traffic-shaper-reverse': 'test_value_54',
|
||||
'utm-status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan-cos-fwd': '57',
|
||||
'vlan-cos-rev': '58',
|
||||
'vlan-filter': 'test_value_59',
|
||||
'voip-profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter-profile': 'test_value_62'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_firewall_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',
|
||||
'firewall_policy6': {
|
||||
'action': 'accept',
|
||||
'application_list': 'test_value_4',
|
||||
'av_profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv_forward': 'enable',
|
||||
'diffserv_reverse': 'enable',
|
||||
'diffservcode_forward': 'test_value_9',
|
||||
'diffservcode_rev': 'test_value_10',
|
||||
'dlp_sensor': 'test_value_11',
|
||||
'dscp_match': 'enable',
|
||||
'dscp_negate': 'enable',
|
||||
'dscp_value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr_negate': 'enable',
|
||||
'firewall_session_dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global_label': 'test_value_19',
|
||||
'icap_profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips_sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic_start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per_ip_shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile_group': 'test_value_34',
|
||||
'profile_protocol_options': 'test_value_35',
|
||||
'profile_type': 'single',
|
||||
'replacemsg_override_group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send_deny_packet': 'enable',
|
||||
'service_negate': 'enable',
|
||||
'session_ttl': '42',
|
||||
'spamfilter_profile': 'test_value_43',
|
||||
'srcaddr_negate': 'enable',
|
||||
'ssh_filter_profile': 'test_value_45',
|
||||
'ssl_mirror': 'enable',
|
||||
'ssl_ssh_profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '49',
|
||||
'tcp_mss_sender': '50',
|
||||
'tcp_session_without_syn': 'all',
|
||||
'timeout_send_rst': 'enable',
|
||||
'traffic_shaper': 'test_value_53',
|
||||
'traffic_shaper_reverse': 'test_value_54',
|
||||
'utm_status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan_cos_fwd': '57',
|
||||
'vlan_cos_rev': '58',
|
||||
'vlan_filter': 'test_value_59',
|
||||
'voip_profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter_profile': 'test_value_62'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', '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_firewall_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',
|
||||
'firewall_policy6': {
|
||||
'action': 'accept',
|
||||
'application_list': 'test_value_4',
|
||||
'av_profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv_forward': 'enable',
|
||||
'diffserv_reverse': 'enable',
|
||||
'diffservcode_forward': 'test_value_9',
|
||||
'diffservcode_rev': 'test_value_10',
|
||||
'dlp_sensor': 'test_value_11',
|
||||
'dscp_match': 'enable',
|
||||
'dscp_negate': 'enable',
|
||||
'dscp_value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr_negate': 'enable',
|
||||
'firewall_session_dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global_label': 'test_value_19',
|
||||
'icap_profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips_sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic_start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per_ip_shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile_group': 'test_value_34',
|
||||
'profile_protocol_options': 'test_value_35',
|
||||
'profile_type': 'single',
|
||||
'replacemsg_override_group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send_deny_packet': 'enable',
|
||||
'service_negate': 'enable',
|
||||
'session_ttl': '42',
|
||||
'spamfilter_profile': 'test_value_43',
|
||||
'srcaddr_negate': 'enable',
|
||||
'ssh_filter_profile': 'test_value_45',
|
||||
'ssl_mirror': 'enable',
|
||||
'ssl_ssh_profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '49',
|
||||
'tcp_mss_sender': '50',
|
||||
'tcp_session_without_syn': 'all',
|
||||
'timeout_send_rst': 'enable',
|
||||
'traffic_shaper': 'test_value_53',
|
||||
'traffic_shaper_reverse': 'test_value_54',
|
||||
'utm_status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan_cos_fwd': '57',
|
||||
'vlan_cos_rev': '58',
|
||||
'vlan_filter': 'test_value_59',
|
||||
'voip_profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter_profile': 'test_value_62'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', '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_firewall_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',
|
||||
'firewall_policy6': {
|
||||
'action': 'accept',
|
||||
'application_list': 'test_value_4',
|
||||
'av_profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv_forward': 'enable',
|
||||
'diffserv_reverse': 'enable',
|
||||
'diffservcode_forward': 'test_value_9',
|
||||
'diffservcode_rev': 'test_value_10',
|
||||
'dlp_sensor': 'test_value_11',
|
||||
'dscp_match': 'enable',
|
||||
'dscp_negate': 'enable',
|
||||
'dscp_value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr_negate': 'enable',
|
||||
'firewall_session_dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global_label': 'test_value_19',
|
||||
'icap_profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips_sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic_start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per_ip_shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile_group': 'test_value_34',
|
||||
'profile_protocol_options': 'test_value_35',
|
||||
'profile_type': 'single',
|
||||
'replacemsg_override_group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send_deny_packet': 'enable',
|
||||
'service_negate': 'enable',
|
||||
'session_ttl': '42',
|
||||
'spamfilter_profile': 'test_value_43',
|
||||
'srcaddr_negate': 'enable',
|
||||
'ssh_filter_profile': 'test_value_45',
|
||||
'ssl_mirror': 'enable',
|
||||
'ssl_ssh_profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '49',
|
||||
'tcp_mss_sender': '50',
|
||||
'tcp_session_without_syn': 'all',
|
||||
'timeout_send_rst': 'enable',
|
||||
'traffic_shaper': 'test_value_53',
|
||||
'traffic_shaper_reverse': 'test_value_54',
|
||||
'utm_status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan_cos_fwd': '57',
|
||||
'vlan_cos_rev': '58',
|
||||
'vlan_filter': 'test_value_59',
|
||||
'voip_profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter_profile': 'test_value_62'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'application-list': 'test_value_4',
|
||||
'av-profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv-forward': 'enable',
|
||||
'diffserv-reverse': 'enable',
|
||||
'diffservcode-forward': 'test_value_9',
|
||||
'diffservcode-rev': 'test_value_10',
|
||||
'dlp-sensor': 'test_value_11',
|
||||
'dscp-match': 'enable',
|
||||
'dscp-negate': 'enable',
|
||||
'dscp-value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr-negate': 'enable',
|
||||
'firewall-session-dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global-label': 'test_value_19',
|
||||
'icap-profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips-sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic-start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per-ip-shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile-group': 'test_value_34',
|
||||
'profile-protocol-options': 'test_value_35',
|
||||
'profile-type': 'single',
|
||||
'replacemsg-override-group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send-deny-packet': 'enable',
|
||||
'service-negate': 'enable',
|
||||
'session-ttl': '42',
|
||||
'spamfilter-profile': 'test_value_43',
|
||||
'srcaddr-negate': 'enable',
|
||||
'ssh-filter-profile': 'test_value_45',
|
||||
'ssl-mirror': 'enable',
|
||||
'ssl-ssh-profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '49',
|
||||
'tcp-mss-sender': '50',
|
||||
'tcp-session-without-syn': 'all',
|
||||
'timeout-send-rst': 'enable',
|
||||
'traffic-shaper': 'test_value_53',
|
||||
'traffic-shaper-reverse': 'test_value_54',
|
||||
'utm-status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan-cos-fwd': '57',
|
||||
'vlan-cos-rev': '58',
|
||||
'vlan-filter': 'test_value_59',
|
||||
'voip-profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter-profile': 'test_value_62'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_firewall_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',
|
||||
'firewall_policy6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'action': 'accept',
|
||||
'application_list': 'test_value_4',
|
||||
'av_profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv_forward': 'enable',
|
||||
'diffserv_reverse': 'enable',
|
||||
'diffservcode_forward': 'test_value_9',
|
||||
'diffservcode_rev': 'test_value_10',
|
||||
'dlp_sensor': 'test_value_11',
|
||||
'dscp_match': 'enable',
|
||||
'dscp_negate': 'enable',
|
||||
'dscp_value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr_negate': 'enable',
|
||||
'firewall_session_dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global_label': 'test_value_19',
|
||||
'icap_profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips_sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic_start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per_ip_shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile_group': 'test_value_34',
|
||||
'profile_protocol_options': 'test_value_35',
|
||||
'profile_type': 'single',
|
||||
'replacemsg_override_group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send_deny_packet': 'enable',
|
||||
'service_negate': 'enable',
|
||||
'session_ttl': '42',
|
||||
'spamfilter_profile': 'test_value_43',
|
||||
'srcaddr_negate': 'enable',
|
||||
'ssh_filter_profile': 'test_value_45',
|
||||
'ssl_mirror': 'enable',
|
||||
'ssl_ssh_profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '49',
|
||||
'tcp_mss_sender': '50',
|
||||
'tcp_session_without_syn': 'all',
|
||||
'timeout_send_rst': 'enable',
|
||||
'traffic_shaper': 'test_value_53',
|
||||
'traffic_shaper_reverse': 'test_value_54',
|
||||
'utm_status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan_cos_fwd': '57',
|
||||
'vlan_cos_rev': '58',
|
||||
'vlan_filter': 'test_value_59',
|
||||
'voip_profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter_profile': 'test_value_62'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'application-list': 'test_value_4',
|
||||
'av-profile': 'test_value_5',
|
||||
'comments': 'test_value_6',
|
||||
'diffserv-forward': 'enable',
|
||||
'diffserv-reverse': 'enable',
|
||||
'diffservcode-forward': 'test_value_9',
|
||||
'diffservcode-rev': 'test_value_10',
|
||||
'dlp-sensor': 'test_value_11',
|
||||
'dscp-match': 'enable',
|
||||
'dscp-negate': 'enable',
|
||||
'dscp-value': 'test_value_14',
|
||||
'dsri': 'enable',
|
||||
'dstaddr-negate': 'enable',
|
||||
'firewall-session-dirty': 'check-all',
|
||||
'fixedport': 'enable',
|
||||
'global-label': 'test_value_19',
|
||||
'icap-profile': 'test_value_20',
|
||||
'inbound': 'enable',
|
||||
'ippool': 'enable',
|
||||
'ips-sensor': 'test_value_23',
|
||||
'label': 'test_value_24',
|
||||
'logtraffic': 'all',
|
||||
'logtraffic-start': 'enable',
|
||||
'name': 'default_name_27',
|
||||
'nat': 'enable',
|
||||
'natinbound': 'enable',
|
||||
'natoutbound': 'enable',
|
||||
'outbound': 'enable',
|
||||
'per-ip-shaper': 'test_value_32',
|
||||
'policyid': '33',
|
||||
'profile-group': 'test_value_34',
|
||||
'profile-protocol-options': 'test_value_35',
|
||||
'profile-type': 'single',
|
||||
'replacemsg-override-group': 'test_value_37',
|
||||
'rsso': 'enable',
|
||||
'schedule': 'test_value_39',
|
||||
'send-deny-packet': 'enable',
|
||||
'service-negate': 'enable',
|
||||
'session-ttl': '42',
|
||||
'spamfilter-profile': 'test_value_43',
|
||||
'srcaddr-negate': 'enable',
|
||||
'ssh-filter-profile': 'test_value_45',
|
||||
'ssl-mirror': 'enable',
|
||||
'ssl-ssh-profile': 'test_value_47',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '49',
|
||||
'tcp-mss-sender': '50',
|
||||
'tcp-session-without-syn': 'all',
|
||||
'timeout-send-rst': 'enable',
|
||||
'traffic-shaper': 'test_value_53',
|
||||
'traffic-shaper-reverse': 'test_value_54',
|
||||
'utm-status': 'enable',
|
||||
'uuid': 'test_value_56',
|
||||
'vlan-cos-fwd': '57',
|
||||
'vlan-cos-rev': '58',
|
||||
'vlan-filter': 'test_value_59',
|
||||
'voip-profile': 'test_value_60',
|
||||
'vpntunnel': 'test_value_61',
|
||||
'webfilter-profile': 'test_value_62'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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,359 @@
|
||||
# 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_firewall_policy64
|
||||
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_firewall_policy64.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_policy64_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',
|
||||
'firewall_policy64': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy64.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy64', 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_firewall_policy64_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',
|
||||
'firewall_policy64': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy64.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy64', 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_firewall_policy64_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',
|
||||
'firewall_policy64': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy64.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'policy64', 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_firewall_policy64_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',
|
||||
'firewall_policy64': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy64.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'policy64', 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_firewall_policy64_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',
|
||||
'firewall_policy64': {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy64.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy64', 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_firewall_policy64_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',
|
||||
'firewall_policy64': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per_ip_shaper': 'test_value_9',
|
||||
'permit_any_host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp_mss_receiver': '15',
|
||||
'tcp_mss_sender': '16',
|
||||
'traffic_shaper': 'test_value_17',
|
||||
'traffic_shaper_reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_policy64.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'action': 'accept',
|
||||
'comments': 'test_value_4',
|
||||
'dstintf': 'test_value_5',
|
||||
'fixedport': 'enable',
|
||||
'ippool': 'enable',
|
||||
'logtraffic': 'enable',
|
||||
'per-ip-shaper': 'test_value_9',
|
||||
'permit-any-host': 'enable',
|
||||
'policyid': '11',
|
||||
'schedule': 'test_value_12',
|
||||
'srcintf': 'test_value_13',
|
||||
'status': 'enable',
|
||||
'tcp-mss-receiver': '15',
|
||||
'tcp-mss-sender': '16',
|
||||
'traffic-shaper': 'test_value_17',
|
||||
'traffic-shaper-reverse': 'test_value_18',
|
||||
'uuid': 'test_value_19'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'policy64', 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,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_firewall_profile_group
|
||||
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_firewall_profile_group.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_profile_group_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',
|
||||
'firewall_profile_group': {
|
||||
'application_list': 'test_value_3',
|
||||
'av_profile': 'test_value_4',
|
||||
'dlp_sensor': 'test_value_5',
|
||||
'dnsfilter_profile': 'test_value_6',
|
||||
'icap_profile': 'test_value_7',
|
||||
'ips_sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile_protocol_options': 'test_value_10',
|
||||
'spamfilter_profile': 'test_value_11',
|
||||
'ssh_filter_profile': 'test_value_12',
|
||||
'ssl_ssh_profile': 'test_value_13',
|
||||
'voip_profile': 'test_value_14',
|
||||
'waf_profile': 'test_value_15',
|
||||
'webfilter_profile': 'test_value_16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'application-list': 'test_value_3',
|
||||
'av-profile': 'test_value_4',
|
||||
'dlp-sensor': 'test_value_5',
|
||||
'dnsfilter-profile': 'test_value_6',
|
||||
'icap-profile': 'test_value_7',
|
||||
'ips-sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile-protocol-options': 'test_value_10',
|
||||
'spamfilter-profile': 'test_value_11',
|
||||
'ssh-filter-profile': 'test_value_12',
|
||||
'ssl-ssh-profile': 'test_value_13',
|
||||
'voip-profile': 'test_value_14',
|
||||
'waf-profile': 'test_value_15',
|
||||
'webfilter-profile': 'test_value_16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-group', 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_firewall_profile_group_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',
|
||||
'firewall_profile_group': {
|
||||
'application_list': 'test_value_3',
|
||||
'av_profile': 'test_value_4',
|
||||
'dlp_sensor': 'test_value_5',
|
||||
'dnsfilter_profile': 'test_value_6',
|
||||
'icap_profile': 'test_value_7',
|
||||
'ips_sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile_protocol_options': 'test_value_10',
|
||||
'spamfilter_profile': 'test_value_11',
|
||||
'ssh_filter_profile': 'test_value_12',
|
||||
'ssl_ssh_profile': 'test_value_13',
|
||||
'voip_profile': 'test_value_14',
|
||||
'waf_profile': 'test_value_15',
|
||||
'webfilter_profile': 'test_value_16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'application-list': 'test_value_3',
|
||||
'av-profile': 'test_value_4',
|
||||
'dlp-sensor': 'test_value_5',
|
||||
'dnsfilter-profile': 'test_value_6',
|
||||
'icap-profile': 'test_value_7',
|
||||
'ips-sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile-protocol-options': 'test_value_10',
|
||||
'spamfilter-profile': 'test_value_11',
|
||||
'ssh-filter-profile': 'test_value_12',
|
||||
'ssl-ssh-profile': 'test_value_13',
|
||||
'voip-profile': 'test_value_14',
|
||||
'waf-profile': 'test_value_15',
|
||||
'webfilter-profile': 'test_value_16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-group', 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_firewall_profile_group_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',
|
||||
'firewall_profile_group': {
|
||||
'application_list': 'test_value_3',
|
||||
'av_profile': 'test_value_4',
|
||||
'dlp_sensor': 'test_value_5',
|
||||
'dnsfilter_profile': 'test_value_6',
|
||||
'icap_profile': 'test_value_7',
|
||||
'ips_sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile_protocol_options': 'test_value_10',
|
||||
'spamfilter_profile': 'test_value_11',
|
||||
'ssh_filter_profile': 'test_value_12',
|
||||
'ssl_ssh_profile': 'test_value_13',
|
||||
'voip_profile': 'test_value_14',
|
||||
'waf_profile': 'test_value_15',
|
||||
'webfilter_profile': 'test_value_16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'profile-group', 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_firewall_profile_group_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',
|
||||
'firewall_profile_group': {
|
||||
'application_list': 'test_value_3',
|
||||
'av_profile': 'test_value_4',
|
||||
'dlp_sensor': 'test_value_5',
|
||||
'dnsfilter_profile': 'test_value_6',
|
||||
'icap_profile': 'test_value_7',
|
||||
'ips_sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile_protocol_options': 'test_value_10',
|
||||
'spamfilter_profile': 'test_value_11',
|
||||
'ssh_filter_profile': 'test_value_12',
|
||||
'ssl_ssh_profile': 'test_value_13',
|
||||
'voip_profile': 'test_value_14',
|
||||
'waf_profile': 'test_value_15',
|
||||
'webfilter_profile': 'test_value_16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'profile-group', 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_firewall_profile_group_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',
|
||||
'firewall_profile_group': {
|
||||
'application_list': 'test_value_3',
|
||||
'av_profile': 'test_value_4',
|
||||
'dlp_sensor': 'test_value_5',
|
||||
'dnsfilter_profile': 'test_value_6',
|
||||
'icap_profile': 'test_value_7',
|
||||
'ips_sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile_protocol_options': 'test_value_10',
|
||||
'spamfilter_profile': 'test_value_11',
|
||||
'ssh_filter_profile': 'test_value_12',
|
||||
'ssl_ssh_profile': 'test_value_13',
|
||||
'voip_profile': 'test_value_14',
|
||||
'waf_profile': 'test_value_15',
|
||||
'webfilter_profile': 'test_value_16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'application-list': 'test_value_3',
|
||||
'av-profile': 'test_value_4',
|
||||
'dlp-sensor': 'test_value_5',
|
||||
'dnsfilter-profile': 'test_value_6',
|
||||
'icap-profile': 'test_value_7',
|
||||
'ips-sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile-protocol-options': 'test_value_10',
|
||||
'spamfilter-profile': 'test_value_11',
|
||||
'ssh-filter-profile': 'test_value_12',
|
||||
'ssl-ssh-profile': 'test_value_13',
|
||||
'voip-profile': 'test_value_14',
|
||||
'waf-profile': 'test_value_15',
|
||||
'webfilter-profile': 'test_value_16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-group', 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_firewall_profile_group_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',
|
||||
'firewall_profile_group': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'application_list': 'test_value_3',
|
||||
'av_profile': 'test_value_4',
|
||||
'dlp_sensor': 'test_value_5',
|
||||
'dnsfilter_profile': 'test_value_6',
|
||||
'icap_profile': 'test_value_7',
|
||||
'ips_sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile_protocol_options': 'test_value_10',
|
||||
'spamfilter_profile': 'test_value_11',
|
||||
'ssh_filter_profile': 'test_value_12',
|
||||
'ssl_ssh_profile': 'test_value_13',
|
||||
'voip_profile': 'test_value_14',
|
||||
'waf_profile': 'test_value_15',
|
||||
'webfilter_profile': 'test_value_16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_group.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'application-list': 'test_value_3',
|
||||
'av-profile': 'test_value_4',
|
||||
'dlp-sensor': 'test_value_5',
|
||||
'dnsfilter-profile': 'test_value_6',
|
||||
'icap-profile': 'test_value_7',
|
||||
'ips-sensor': 'test_value_8',
|
||||
'name': 'default_name_9',
|
||||
'profile-protocol-options': 'test_value_10',
|
||||
'spamfilter-profile': 'test_value_11',
|
||||
'ssh-filter-profile': 'test_value_12',
|
||||
'ssl-ssh-profile': 'test_value_13',
|
||||
'voip-profile': 'test_value_14',
|
||||
'waf-profile': 'test_value_15',
|
||||
'webfilter-profile': 'test_value_16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-group', 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,249 @@
|
||||
# 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_firewall_profile_protocol_options
|
||||
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_firewall_profile_protocol_options.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_profile_protocol_options_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',
|
||||
'firewall_profile_protocol_options': {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize_log': 'disable',
|
||||
'replacemsg_group': 'test_value_6',
|
||||
'rpc_over_http': 'enable',
|
||||
'switching_protocols_log': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_protocol_options.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize-log': 'disable',
|
||||
'replacemsg-group': 'test_value_6',
|
||||
'rpc-over-http': 'enable',
|
||||
'switching-protocols-log': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-protocol-options', 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_firewall_profile_protocol_options_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',
|
||||
'firewall_profile_protocol_options': {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize_log': 'disable',
|
||||
'replacemsg_group': 'test_value_6',
|
||||
'rpc_over_http': 'enable',
|
||||
'switching_protocols_log': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_protocol_options.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize-log': 'disable',
|
||||
'replacemsg-group': 'test_value_6',
|
||||
'rpc-over-http': 'enable',
|
||||
'switching-protocols-log': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-protocol-options', 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_firewall_profile_protocol_options_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',
|
||||
'firewall_profile_protocol_options': {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize_log': 'disable',
|
||||
'replacemsg_group': 'test_value_6',
|
||||
'rpc_over_http': 'enable',
|
||||
'switching_protocols_log': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_protocol_options.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'profile-protocol-options', 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_firewall_profile_protocol_options_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',
|
||||
'firewall_profile_protocol_options': {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize_log': 'disable',
|
||||
'replacemsg_group': 'test_value_6',
|
||||
'rpc_over_http': 'enable',
|
||||
'switching_protocols_log': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_protocol_options.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'profile-protocol-options', 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_firewall_profile_protocol_options_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',
|
||||
'firewall_profile_protocol_options': {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize_log': 'disable',
|
||||
'replacemsg_group': 'test_value_6',
|
||||
'rpc_over_http': 'enable',
|
||||
'switching_protocols_log': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_protocol_options.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize-log': 'disable',
|
||||
'replacemsg-group': 'test_value_6',
|
||||
'rpc-over-http': 'enable',
|
||||
'switching-protocols-log': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-protocol-options', 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_firewall_profile_protocol_options_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',
|
||||
'firewall_profile_protocol_options': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize_log': 'disable',
|
||||
'replacemsg_group': 'test_value_6',
|
||||
'rpc_over_http': 'enable',
|
||||
'switching_protocols_log': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_profile_protocol_options.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Optional comments.',
|
||||
'name': 'default_name_4',
|
||||
'oversize-log': 'disable',
|
||||
'replacemsg-group': 'test_value_6',
|
||||
'rpc-over-http': 'enable',
|
||||
'switching-protocols-log': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'profile-protocol-options', 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