mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 2 (#60598)
* FortiOS modules for 2.9 - 2 * Fix long lines and ignore.txtpull/60694/head
parent
9c61ef10d1
commit
ca28ae3be5
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,289 @@
|
||||
# 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_endpoint_control_forticlient_ems
|
||||
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_endpoint_control_forticlient_ems.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_endpoint_control_forticlient_ems_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',
|
||||
'endpoint_control_forticlient_ems': {
|
||||
'address': 'test_value_3',
|
||||
'admin_password': 'test_value_4',
|
||||
'admin_type': 'Windows',
|
||||
'admin_username': 'test_value_6',
|
||||
'https_port': '7',
|
||||
'listen_port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest_api_auth': 'disable',
|
||||
'serial_number': 'test_value_11',
|
||||
'upload_port': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_ems.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address': 'test_value_3',
|
||||
'admin-password': 'test_value_4',
|
||||
'admin-type': 'Windows',
|
||||
'admin-username': 'test_value_6',
|
||||
'https-port': '7',
|
||||
'listen-port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest-api-auth': 'disable',
|
||||
'serial-number': 'test_value_11',
|
||||
'upload-port': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-ems', 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_endpoint_control_forticlient_ems_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',
|
||||
'endpoint_control_forticlient_ems': {
|
||||
'address': 'test_value_3',
|
||||
'admin_password': 'test_value_4',
|
||||
'admin_type': 'Windows',
|
||||
'admin_username': 'test_value_6',
|
||||
'https_port': '7',
|
||||
'listen_port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest_api_auth': 'disable',
|
||||
'serial_number': 'test_value_11',
|
||||
'upload_port': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_ems.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address': 'test_value_3',
|
||||
'admin-password': 'test_value_4',
|
||||
'admin-type': 'Windows',
|
||||
'admin-username': 'test_value_6',
|
||||
'https-port': '7',
|
||||
'listen-port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest-api-auth': 'disable',
|
||||
'serial-number': 'test_value_11',
|
||||
'upload-port': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-ems', 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_endpoint_control_forticlient_ems_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',
|
||||
'endpoint_control_forticlient_ems': {
|
||||
'address': 'test_value_3',
|
||||
'admin_password': 'test_value_4',
|
||||
'admin_type': 'Windows',
|
||||
'admin_username': 'test_value_6',
|
||||
'https_port': '7',
|
||||
'listen_port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest_api_auth': 'disable',
|
||||
'serial_number': 'test_value_11',
|
||||
'upload_port': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_ems.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('endpoint-control', 'forticlient-ems', 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_endpoint_control_forticlient_ems_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',
|
||||
'endpoint_control_forticlient_ems': {
|
||||
'address': 'test_value_3',
|
||||
'admin_password': 'test_value_4',
|
||||
'admin_type': 'Windows',
|
||||
'admin_username': 'test_value_6',
|
||||
'https_port': '7',
|
||||
'listen_port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest_api_auth': 'disable',
|
||||
'serial_number': 'test_value_11',
|
||||
'upload_port': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_ems.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('endpoint-control', 'forticlient-ems', 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_endpoint_control_forticlient_ems_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',
|
||||
'endpoint_control_forticlient_ems': {
|
||||
'address': 'test_value_3',
|
||||
'admin_password': 'test_value_4',
|
||||
'admin_type': 'Windows',
|
||||
'admin_username': 'test_value_6',
|
||||
'https_port': '7',
|
||||
'listen_port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest_api_auth': 'disable',
|
||||
'serial_number': 'test_value_11',
|
||||
'upload_port': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_ems.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address': 'test_value_3',
|
||||
'admin-password': 'test_value_4',
|
||||
'admin-type': 'Windows',
|
||||
'admin-username': 'test_value_6',
|
||||
'https-port': '7',
|
||||
'listen-port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest-api-auth': 'disable',
|
||||
'serial-number': 'test_value_11',
|
||||
'upload-port': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-ems', 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_endpoint_control_forticlient_ems_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',
|
||||
'endpoint_control_forticlient_ems': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'address': 'test_value_3',
|
||||
'admin_password': 'test_value_4',
|
||||
'admin_type': 'Windows',
|
||||
'admin_username': 'test_value_6',
|
||||
'https_port': '7',
|
||||
'listen_port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest_api_auth': 'disable',
|
||||
'serial_number': 'test_value_11',
|
||||
'upload_port': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_ems.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address': 'test_value_3',
|
||||
'admin-password': 'test_value_4',
|
||||
'admin-type': 'Windows',
|
||||
'admin-username': 'test_value_6',
|
||||
'https-port': '7',
|
||||
'listen-port': '8',
|
||||
'name': 'default_name_9',
|
||||
'rest-api-auth': 'disable',
|
||||
'serial-number': 'test_value_11',
|
||||
'upload-port': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-ems', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,209 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_endpoint_control_forticlient_registration_sync
|
||||
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_endpoint_control_forticlient_registration_sync.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_endpoint_control_forticlient_registration_sync_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',
|
||||
'endpoint_control_forticlient_registration_sync': {
|
||||
'peer_ip': 'test_value_3',
|
||||
'peer_name': 'test_value_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_registration_sync.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'peer-ip': 'test_value_3',
|
||||
'peer-name': 'test_value_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-registration-sync', 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_endpoint_control_forticlient_registration_sync_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',
|
||||
'endpoint_control_forticlient_registration_sync': {
|
||||
'peer_ip': 'test_value_3',
|
||||
'peer_name': 'test_value_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_registration_sync.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'peer-ip': 'test_value_3',
|
||||
'peer-name': 'test_value_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-registration-sync', 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_endpoint_control_forticlient_registration_sync_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',
|
||||
'endpoint_control_forticlient_registration_sync': {
|
||||
'peer_ip': 'test_value_3',
|
||||
'peer_name': 'test_value_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_registration_sync.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('endpoint-control', 'forticlient-registration-sync', 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_endpoint_control_forticlient_registration_sync_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',
|
||||
'endpoint_control_forticlient_registration_sync': {
|
||||
'peer_ip': 'test_value_3',
|
||||
'peer_name': 'test_value_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_registration_sync.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('endpoint-control', 'forticlient-registration-sync', 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_endpoint_control_forticlient_registration_sync_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',
|
||||
'endpoint_control_forticlient_registration_sync': {
|
||||
'peer_ip': 'test_value_3',
|
||||
'peer_name': 'test_value_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_registration_sync.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'peer-ip': 'test_value_3',
|
||||
'peer-name': 'test_value_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-registration-sync', 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_endpoint_control_forticlient_registration_sync_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',
|
||||
'endpoint_control_forticlient_registration_sync': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'peer_ip': 'test_value_3',
|
||||
'peer_name': 'test_value_4'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_forticlient_registration_sync.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'peer-ip': 'test_value_3',
|
||||
'peer-name': 'test_value_4'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'forticlient-registration-sync', 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_endpoint_control_profile
|
||||
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_endpoint_control_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_endpoint_control_profile_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',
|
||||
'endpoint_control_profile': {
|
||||
'description': 'test_value_3',
|
||||
'profile_name': 'test_value_4',
|
||||
'replacemsg_override_group': 'test_value_5',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_profile.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'description': 'test_value_3',
|
||||
'profile-name': 'test_value_4',
|
||||
'replacemsg-override-group': 'test_value_5',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'profile', 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_endpoint_control_profile_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',
|
||||
'endpoint_control_profile': {
|
||||
'description': 'test_value_3',
|
||||
'profile_name': 'test_value_4',
|
||||
'replacemsg_override_group': 'test_value_5',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_profile.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'description': 'test_value_3',
|
||||
'profile-name': 'test_value_4',
|
||||
'replacemsg-override-group': 'test_value_5',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'profile', 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_endpoint_control_profile_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',
|
||||
'endpoint_control_profile': {
|
||||
'description': 'test_value_3',
|
||||
'profile_name': 'test_value_4',
|
||||
'replacemsg_override_group': 'test_value_5',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_profile.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('endpoint-control', 'profile', 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_endpoint_control_profile_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',
|
||||
'endpoint_control_profile': {
|
||||
'description': 'test_value_3',
|
||||
'profile_name': 'test_value_4',
|
||||
'replacemsg_override_group': 'test_value_5',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_profile.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('endpoint-control', 'profile', 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_endpoint_control_profile_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',
|
||||
'endpoint_control_profile': {
|
||||
'description': 'test_value_3',
|
||||
'profile_name': 'test_value_4',
|
||||
'replacemsg_override_group': 'test_value_5',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_profile.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'description': 'test_value_3',
|
||||
'profile-name': 'test_value_4',
|
||||
'replacemsg-override-group': 'test_value_5',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'profile', 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_endpoint_control_profile_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',
|
||||
'endpoint_control_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'description': 'test_value_3',
|
||||
'profile_name': 'test_value_4',
|
||||
'replacemsg_override_group': 'test_value_5',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_profile.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'description': 'test_value_3',
|
||||
'profile-name': 'test_value_4',
|
||||
'replacemsg-override-group': 'test_value_5',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'profile', 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,255 @@
|
||||
# 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_endpoint_control_settings
|
||||
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_endpoint_control_settings.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_endpoint_control_settings_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',
|
||||
'endpoint_control_settings': {
|
||||
'download_custom_link': 'test_value_3',
|
||||
'download_location': 'fortiguard',
|
||||
'forticlient_avdb_update_interval': '5',
|
||||
'forticlient_dereg_unsupported_client': 'enable',
|
||||
'forticlient_ems_rest_api_call_timeout': '7',
|
||||
'forticlient_keepalive_interval': '8',
|
||||
'forticlient_offline_grace': 'enable',
|
||||
'forticlient_offline_grace_interval': '10',
|
||||
'forticlient_reg_key': 'test_value_11',
|
||||
'forticlient_reg_key_enforce': 'enable',
|
||||
'forticlient_reg_timeout': '13',
|
||||
'forticlient_sys_update_interval': '14',
|
||||
'forticlient_user_avatar': 'enable',
|
||||
'forticlient_warning_interval': '16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_settings.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'download-custom-link': 'test_value_3',
|
||||
'download-location': 'fortiguard',
|
||||
'forticlient-avdb-update-interval': '5',
|
||||
'forticlient-dereg-unsupported-client': 'enable',
|
||||
'forticlient-ems-rest-api-call-timeout': '7',
|
||||
'forticlient-keepalive-interval': '8',
|
||||
'forticlient-offline-grace': 'enable',
|
||||
'forticlient-offline-grace-interval': '10',
|
||||
'forticlient-reg-key': 'test_value_11',
|
||||
'forticlient-reg-key-enforce': 'enable',
|
||||
'forticlient-reg-timeout': '13',
|
||||
'forticlient-sys-update-interval': '14',
|
||||
'forticlient-user-avatar': 'enable',
|
||||
'forticlient-warning-interval': '16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'settings', 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_endpoint_control_settings_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',
|
||||
'endpoint_control_settings': {
|
||||
'download_custom_link': 'test_value_3',
|
||||
'download_location': 'fortiguard',
|
||||
'forticlient_avdb_update_interval': '5',
|
||||
'forticlient_dereg_unsupported_client': 'enable',
|
||||
'forticlient_ems_rest_api_call_timeout': '7',
|
||||
'forticlient_keepalive_interval': '8',
|
||||
'forticlient_offline_grace': 'enable',
|
||||
'forticlient_offline_grace_interval': '10',
|
||||
'forticlient_reg_key': 'test_value_11',
|
||||
'forticlient_reg_key_enforce': 'enable',
|
||||
'forticlient_reg_timeout': '13',
|
||||
'forticlient_sys_update_interval': '14',
|
||||
'forticlient_user_avatar': 'enable',
|
||||
'forticlient_warning_interval': '16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_settings.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'download-custom-link': 'test_value_3',
|
||||
'download-location': 'fortiguard',
|
||||
'forticlient-avdb-update-interval': '5',
|
||||
'forticlient-dereg-unsupported-client': 'enable',
|
||||
'forticlient-ems-rest-api-call-timeout': '7',
|
||||
'forticlient-keepalive-interval': '8',
|
||||
'forticlient-offline-grace': 'enable',
|
||||
'forticlient-offline-grace-interval': '10',
|
||||
'forticlient-reg-key': 'test_value_11',
|
||||
'forticlient-reg-key-enforce': 'enable',
|
||||
'forticlient-reg-timeout': '13',
|
||||
'forticlient-sys-update-interval': '14',
|
||||
'forticlient-user-avatar': 'enable',
|
||||
'forticlient-warning-interval': '16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'settings', 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_endpoint_control_settings_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',
|
||||
'endpoint_control_settings': {
|
||||
'download_custom_link': 'test_value_3',
|
||||
'download_location': 'fortiguard',
|
||||
'forticlient_avdb_update_interval': '5',
|
||||
'forticlient_dereg_unsupported_client': 'enable',
|
||||
'forticlient_ems_rest_api_call_timeout': '7',
|
||||
'forticlient_keepalive_interval': '8',
|
||||
'forticlient_offline_grace': 'enable',
|
||||
'forticlient_offline_grace_interval': '10',
|
||||
'forticlient_reg_key': 'test_value_11',
|
||||
'forticlient_reg_key_enforce': 'enable',
|
||||
'forticlient_reg_timeout': '13',
|
||||
'forticlient_sys_update_interval': '14',
|
||||
'forticlient_user_avatar': 'enable',
|
||||
'forticlient_warning_interval': '16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_settings.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'download-custom-link': 'test_value_3',
|
||||
'download-location': 'fortiguard',
|
||||
'forticlient-avdb-update-interval': '5',
|
||||
'forticlient-dereg-unsupported-client': 'enable',
|
||||
'forticlient-ems-rest-api-call-timeout': '7',
|
||||
'forticlient-keepalive-interval': '8',
|
||||
'forticlient-offline-grace': 'enable',
|
||||
'forticlient-offline-grace-interval': '10',
|
||||
'forticlient-reg-key': 'test_value_11',
|
||||
'forticlient-reg-key-enforce': 'enable',
|
||||
'forticlient-reg-timeout': '13',
|
||||
'forticlient-sys-update-interval': '14',
|
||||
'forticlient-user-avatar': 'enable',
|
||||
'forticlient-warning-interval': '16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'settings', 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_endpoint_control_settings_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',
|
||||
'endpoint_control_settings': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'download_custom_link': 'test_value_3',
|
||||
'download_location': 'fortiguard',
|
||||
'forticlient_avdb_update_interval': '5',
|
||||
'forticlient_dereg_unsupported_client': 'enable',
|
||||
'forticlient_ems_rest_api_call_timeout': '7',
|
||||
'forticlient_keepalive_interval': '8',
|
||||
'forticlient_offline_grace': 'enable',
|
||||
'forticlient_offline_grace_interval': '10',
|
||||
'forticlient_reg_key': 'test_value_11',
|
||||
'forticlient_reg_key_enforce': 'enable',
|
||||
'forticlient_reg_timeout': '13',
|
||||
'forticlient_sys_update_interval': '14',
|
||||
'forticlient_user_avatar': 'enable',
|
||||
'forticlient_warning_interval': '16'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_endpoint_control_settings.fortios_endpoint_control(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'download-custom-link': 'test_value_3',
|
||||
'download-location': 'fortiguard',
|
||||
'forticlient-avdb-update-interval': '5',
|
||||
'forticlient-dereg-unsupported-client': 'enable',
|
||||
'forticlient-ems-rest-api-call-timeout': '7',
|
||||
'forticlient-keepalive-interval': '8',
|
||||
'forticlient-offline-grace': 'enable',
|
||||
'forticlient-offline-grace-interval': '10',
|
||||
'forticlient-reg-key': 'test_value_11',
|
||||
'forticlient-reg-key-enforce': 'enable',
|
||||
'forticlient-reg-timeout': '13',
|
||||
'forticlient-sys-update-interval': '14',
|
||||
'forticlient-user-avatar': 'enable',
|
||||
'forticlient-warning-interval': '16'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('endpoint-control', 'settings', 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,559 @@
|
||||
# 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_extender_controller_extender
|
||||
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_extender_controller_extender.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_extender_controller_extender_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',
|
||||
'extender_controller_extender': {
|
||||
'aaa_shared_secret': 'test_value_3',
|
||||
'access_point_name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at_dial_script': 'test_value_6',
|
||||
'billing_start_day': '7',
|
||||
'cdma_aaa_spi': 'test_value_8',
|
||||
'cdma_ha_spi': 'test_value_9',
|
||||
'cdma_nai': 'test_value_10',
|
||||
'conn_status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial_mode': 'dial-on-demand',
|
||||
'dial_status': '14',
|
||||
'ext_name': 'test_value_15',
|
||||
'ha_shared_secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated_update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem_passwd': 'test_value_21',
|
||||
'modem_type': 'cdma',
|
||||
'multi_mode': 'auto',
|
||||
'ppp_auth_protocol': 'auto',
|
||||
'ppp_echo_request': 'enable',
|
||||
'ppp_password': 'test_value_26',
|
||||
'ppp_username': 'test_value_27',
|
||||
'primary_ha': 'test_value_28',
|
||||
'quota_limit_mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant_intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary_ha': 'test_value_34',
|
||||
'sim_pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax_auth_protocol': 'tls',
|
||||
'wimax_carrier': 'test_value_38',
|
||||
'wimax_realm': 'test_value_39'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_extender_controller_extender.fortios_extender_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'aaa-shared-secret': 'test_value_3',
|
||||
'access-point-name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at-dial-script': 'test_value_6',
|
||||
'billing-start-day': '7',
|
||||
'cdma-aaa-spi': 'test_value_8',
|
||||
'cdma-ha-spi': 'test_value_9',
|
||||
'cdma-nai': 'test_value_10',
|
||||
'conn-status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial-mode': 'dial-on-demand',
|
||||
'dial-status': '14',
|
||||
'ext-name': 'test_value_15',
|
||||
'ha-shared-secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated-update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem-passwd': 'test_value_21',
|
||||
'modem-type': 'cdma',
|
||||
'multi-mode': 'auto',
|
||||
'ppp-auth-protocol': 'auto',
|
||||
'ppp-echo-request': 'enable',
|
||||
'ppp-password': 'test_value_26',
|
||||
'ppp-username': 'test_value_27',
|
||||
'primary-ha': 'test_value_28',
|
||||
'quota-limit-mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant-intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary-ha': 'test_value_34',
|
||||
'sim-pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax-auth-protocol': 'tls',
|
||||
'wimax-carrier': 'test_value_38',
|
||||
'wimax-realm': 'test_value_39'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('extender-controller', 'extender', 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_extender_controller_extender_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',
|
||||
'extender_controller_extender': {
|
||||
'aaa_shared_secret': 'test_value_3',
|
||||
'access_point_name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at_dial_script': 'test_value_6',
|
||||
'billing_start_day': '7',
|
||||
'cdma_aaa_spi': 'test_value_8',
|
||||
'cdma_ha_spi': 'test_value_9',
|
||||
'cdma_nai': 'test_value_10',
|
||||
'conn_status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial_mode': 'dial-on-demand',
|
||||
'dial_status': '14',
|
||||
'ext_name': 'test_value_15',
|
||||
'ha_shared_secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated_update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem_passwd': 'test_value_21',
|
||||
'modem_type': 'cdma',
|
||||
'multi_mode': 'auto',
|
||||
'ppp_auth_protocol': 'auto',
|
||||
'ppp_echo_request': 'enable',
|
||||
'ppp_password': 'test_value_26',
|
||||
'ppp_username': 'test_value_27',
|
||||
'primary_ha': 'test_value_28',
|
||||
'quota_limit_mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant_intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary_ha': 'test_value_34',
|
||||
'sim_pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax_auth_protocol': 'tls',
|
||||
'wimax_carrier': 'test_value_38',
|
||||
'wimax_realm': 'test_value_39'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_extender_controller_extender.fortios_extender_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'aaa-shared-secret': 'test_value_3',
|
||||
'access-point-name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at-dial-script': 'test_value_6',
|
||||
'billing-start-day': '7',
|
||||
'cdma-aaa-spi': 'test_value_8',
|
||||
'cdma-ha-spi': 'test_value_9',
|
||||
'cdma-nai': 'test_value_10',
|
||||
'conn-status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial-mode': 'dial-on-demand',
|
||||
'dial-status': '14',
|
||||
'ext-name': 'test_value_15',
|
||||
'ha-shared-secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated-update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem-passwd': 'test_value_21',
|
||||
'modem-type': 'cdma',
|
||||
'multi-mode': 'auto',
|
||||
'ppp-auth-protocol': 'auto',
|
||||
'ppp-echo-request': 'enable',
|
||||
'ppp-password': 'test_value_26',
|
||||
'ppp-username': 'test_value_27',
|
||||
'primary-ha': 'test_value_28',
|
||||
'quota-limit-mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant-intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary-ha': 'test_value_34',
|
||||
'sim-pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax-auth-protocol': 'tls',
|
||||
'wimax-carrier': 'test_value_38',
|
||||
'wimax-realm': 'test_value_39'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('extender-controller', 'extender', 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_extender_controller_extender_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',
|
||||
'extender_controller_extender': {
|
||||
'aaa_shared_secret': 'test_value_3',
|
||||
'access_point_name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at_dial_script': 'test_value_6',
|
||||
'billing_start_day': '7',
|
||||
'cdma_aaa_spi': 'test_value_8',
|
||||
'cdma_ha_spi': 'test_value_9',
|
||||
'cdma_nai': 'test_value_10',
|
||||
'conn_status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial_mode': 'dial-on-demand',
|
||||
'dial_status': '14',
|
||||
'ext_name': 'test_value_15',
|
||||
'ha_shared_secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated_update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem_passwd': 'test_value_21',
|
||||
'modem_type': 'cdma',
|
||||
'multi_mode': 'auto',
|
||||
'ppp_auth_protocol': 'auto',
|
||||
'ppp_echo_request': 'enable',
|
||||
'ppp_password': 'test_value_26',
|
||||
'ppp_username': 'test_value_27',
|
||||
'primary_ha': 'test_value_28',
|
||||
'quota_limit_mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant_intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary_ha': 'test_value_34',
|
||||
'sim_pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax_auth_protocol': 'tls',
|
||||
'wimax_carrier': 'test_value_38',
|
||||
'wimax_realm': 'test_value_39'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_extender_controller_extender.fortios_extender_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('extender-controller', 'extender', 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_extender_controller_extender_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',
|
||||
'extender_controller_extender': {
|
||||
'aaa_shared_secret': 'test_value_3',
|
||||
'access_point_name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at_dial_script': 'test_value_6',
|
||||
'billing_start_day': '7',
|
||||
'cdma_aaa_spi': 'test_value_8',
|
||||
'cdma_ha_spi': 'test_value_9',
|
||||
'cdma_nai': 'test_value_10',
|
||||
'conn_status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial_mode': 'dial-on-demand',
|
||||
'dial_status': '14',
|
||||
'ext_name': 'test_value_15',
|
||||
'ha_shared_secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated_update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem_passwd': 'test_value_21',
|
||||
'modem_type': 'cdma',
|
||||
'multi_mode': 'auto',
|
||||
'ppp_auth_protocol': 'auto',
|
||||
'ppp_echo_request': 'enable',
|
||||
'ppp_password': 'test_value_26',
|
||||
'ppp_username': 'test_value_27',
|
||||
'primary_ha': 'test_value_28',
|
||||
'quota_limit_mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant_intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary_ha': 'test_value_34',
|
||||
'sim_pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax_auth_protocol': 'tls',
|
||||
'wimax_carrier': 'test_value_38',
|
||||
'wimax_realm': 'test_value_39'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_extender_controller_extender.fortios_extender_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('extender-controller', 'extender', 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_extender_controller_extender_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',
|
||||
'extender_controller_extender': {
|
||||
'aaa_shared_secret': 'test_value_3',
|
||||
'access_point_name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at_dial_script': 'test_value_6',
|
||||
'billing_start_day': '7',
|
||||
'cdma_aaa_spi': 'test_value_8',
|
||||
'cdma_ha_spi': 'test_value_9',
|
||||
'cdma_nai': 'test_value_10',
|
||||
'conn_status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial_mode': 'dial-on-demand',
|
||||
'dial_status': '14',
|
||||
'ext_name': 'test_value_15',
|
||||
'ha_shared_secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated_update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem_passwd': 'test_value_21',
|
||||
'modem_type': 'cdma',
|
||||
'multi_mode': 'auto',
|
||||
'ppp_auth_protocol': 'auto',
|
||||
'ppp_echo_request': 'enable',
|
||||
'ppp_password': 'test_value_26',
|
||||
'ppp_username': 'test_value_27',
|
||||
'primary_ha': 'test_value_28',
|
||||
'quota_limit_mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant_intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary_ha': 'test_value_34',
|
||||
'sim_pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax_auth_protocol': 'tls',
|
||||
'wimax_carrier': 'test_value_38',
|
||||
'wimax_realm': 'test_value_39'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_extender_controller_extender.fortios_extender_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'aaa-shared-secret': 'test_value_3',
|
||||
'access-point-name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at-dial-script': 'test_value_6',
|
||||
'billing-start-day': '7',
|
||||
'cdma-aaa-spi': 'test_value_8',
|
||||
'cdma-ha-spi': 'test_value_9',
|
||||
'cdma-nai': 'test_value_10',
|
||||
'conn-status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial-mode': 'dial-on-demand',
|
||||
'dial-status': '14',
|
||||
'ext-name': 'test_value_15',
|
||||
'ha-shared-secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated-update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem-passwd': 'test_value_21',
|
||||
'modem-type': 'cdma',
|
||||
'multi-mode': 'auto',
|
||||
'ppp-auth-protocol': 'auto',
|
||||
'ppp-echo-request': 'enable',
|
||||
'ppp-password': 'test_value_26',
|
||||
'ppp-username': 'test_value_27',
|
||||
'primary-ha': 'test_value_28',
|
||||
'quota-limit-mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant-intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary-ha': 'test_value_34',
|
||||
'sim-pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax-auth-protocol': 'tls',
|
||||
'wimax-carrier': 'test_value_38',
|
||||
'wimax-realm': 'test_value_39'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('extender-controller', 'extender', 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_extender_controller_extender_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',
|
||||
'extender_controller_extender': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'aaa_shared_secret': 'test_value_3',
|
||||
'access_point_name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at_dial_script': 'test_value_6',
|
||||
'billing_start_day': '7',
|
||||
'cdma_aaa_spi': 'test_value_8',
|
||||
'cdma_ha_spi': 'test_value_9',
|
||||
'cdma_nai': 'test_value_10',
|
||||
'conn_status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial_mode': 'dial-on-demand',
|
||||
'dial_status': '14',
|
||||
'ext_name': 'test_value_15',
|
||||
'ha_shared_secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated_update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem_passwd': 'test_value_21',
|
||||
'modem_type': 'cdma',
|
||||
'multi_mode': 'auto',
|
||||
'ppp_auth_protocol': 'auto',
|
||||
'ppp_echo_request': 'enable',
|
||||
'ppp_password': 'test_value_26',
|
||||
'ppp_username': 'test_value_27',
|
||||
'primary_ha': 'test_value_28',
|
||||
'quota_limit_mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant_intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary_ha': 'test_value_34',
|
||||
'sim_pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax_auth_protocol': 'tls',
|
||||
'wimax_carrier': 'test_value_38',
|
||||
'wimax_realm': 'test_value_39'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_extender_controller_extender.fortios_extender_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'aaa-shared-secret': 'test_value_3',
|
||||
'access-point-name': 'test_value_4',
|
||||
'admin': 'disable',
|
||||
'at-dial-script': 'test_value_6',
|
||||
'billing-start-day': '7',
|
||||
'cdma-aaa-spi': 'test_value_8',
|
||||
'cdma-ha-spi': 'test_value_9',
|
||||
'cdma-nai': 'test_value_10',
|
||||
'conn-status': '11',
|
||||
'description': 'test_value_12',
|
||||
'dial-mode': 'dial-on-demand',
|
||||
'dial-status': '14',
|
||||
'ext-name': 'test_value_15',
|
||||
'ha-shared-secret': 'test_value_16',
|
||||
'id': '17',
|
||||
'ifname': 'test_value_18',
|
||||
'initiated-update': 'enable',
|
||||
'mode': 'standalone',
|
||||
'modem-passwd': 'test_value_21',
|
||||
'modem-type': 'cdma',
|
||||
'multi-mode': 'auto',
|
||||
'ppp-auth-protocol': 'auto',
|
||||
'ppp-echo-request': 'enable',
|
||||
'ppp-password': 'test_value_26',
|
||||
'ppp-username': 'test_value_27',
|
||||
'primary-ha': 'test_value_28',
|
||||
'quota-limit-mb': '29',
|
||||
'redial': 'none',
|
||||
'redundant-intf': 'test_value_31',
|
||||
'roaming': 'enable',
|
||||
'role': 'none',
|
||||
'secondary-ha': 'test_value_34',
|
||||
'sim-pin': 'test_value_35',
|
||||
'vdom': '36',
|
||||
'wimax-auth-protocol': 'tls',
|
||||
'wimax-carrier': 'test_value_38',
|
||||
'wimax-realm': 'test_value_39'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('extender-controller', 'extender', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,219 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_firewall_DoS_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_DoS_policy.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_DoS_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_DoS_policy': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy': {
|
||||
'random_attribute_not_valid': 'tag', 'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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,219 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_firewall_DoS_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_DoS_policy6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_DoS_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_DoS_policy6': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy6': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy6': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy6': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy6': {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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_DoS_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_DoS_policy6': {
|
||||
'random_attribute_not_valid': 'tag', 'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_DoS_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'comments': 'test_value_3',
|
||||
'interface': 'test_value_4',
|
||||
'policyid': '5',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'DoS-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,439 @@
|
||||
# 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_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_address.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_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_address': {
|
||||
'allow_routing': 'enable',
|
||||
'associated_interface': 'test_value_4',
|
||||
'cache_ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end_ip': 'test_value_9',
|
||||
'epg_name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj_id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy_group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn_tag': 'test_value_18',
|
||||
'start_ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet_name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard_fqdn': 'test_value_27'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'associated-interface': 'test_value_4',
|
||||
'cache-ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end-ip': 'test_value_9',
|
||||
'epg-name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj-id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy-group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn-tag': 'test_value_18',
|
||||
'start-ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet-name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard-fqdn': 'test_value_27'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_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_address': {
|
||||
'allow_routing': 'enable',
|
||||
'associated_interface': 'test_value_4',
|
||||
'cache_ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end_ip': 'test_value_9',
|
||||
'epg_name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj_id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy_group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn_tag': 'test_value_18',
|
||||
'start_ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet_name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard_fqdn': 'test_value_27'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'associated-interface': 'test_value_4',
|
||||
'cache-ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end-ip': 'test_value_9',
|
||||
'epg-name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj-id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy-group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn-tag': 'test_value_18',
|
||||
'start-ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet-name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard-fqdn': 'test_value_27'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_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_address': {
|
||||
'allow_routing': 'enable',
|
||||
'associated_interface': 'test_value_4',
|
||||
'cache_ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end_ip': 'test_value_9',
|
||||
'epg_name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj_id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy_group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn_tag': 'test_value_18',
|
||||
'start_ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet_name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard_fqdn': 'test_value_27'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', '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_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_address': {
|
||||
'allow_routing': 'enable',
|
||||
'associated_interface': 'test_value_4',
|
||||
'cache_ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end_ip': 'test_value_9',
|
||||
'epg_name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj_id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy_group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn_tag': 'test_value_18',
|
||||
'start_ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet_name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard_fqdn': 'test_value_27'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', '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_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_address': {
|
||||
'allow_routing': 'enable',
|
||||
'associated_interface': 'test_value_4',
|
||||
'cache_ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end_ip': 'test_value_9',
|
||||
'epg_name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj_id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy_group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn_tag': 'test_value_18',
|
||||
'start_ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet_name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard_fqdn': 'test_value_27'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'associated-interface': 'test_value_4',
|
||||
'cache-ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end-ip': 'test_value_9',
|
||||
'epg-name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj-id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy-group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn-tag': 'test_value_18',
|
||||
'start-ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet-name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard-fqdn': 'test_value_27'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_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_address': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'allow_routing': 'enable',
|
||||
'associated_interface': 'test_value_4',
|
||||
'cache_ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end_ip': 'test_value_9',
|
||||
'epg_name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj_id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy_group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn_tag': 'test_value_18',
|
||||
'start_ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet_name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard_fqdn': 'test_value_27'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'associated-interface': 'test_value_4',
|
||||
'cache-ttl': '5',
|
||||
'color': '6',
|
||||
'comment': 'Comment.',
|
||||
'country': 'test_value_8',
|
||||
'end-ip': 'test_value_9',
|
||||
'epg-name': 'test_value_10',
|
||||
'filter': 'test_value_11',
|
||||
'fqdn': 'test_value_12',
|
||||
'name': 'default_name_13',
|
||||
'obj-id': 'test_value_14',
|
||||
'organization': 'test_value_15',
|
||||
'policy-group': 'test_value_16',
|
||||
'sdn': 'aci',
|
||||
'sdn-tag': 'test_value_18',
|
||||
'start-ip': 'test_value_19',
|
||||
'subnet': 'test_value_20',
|
||||
'subnet-name': 'test_value_21',
|
||||
'tenant': 'test_value_22',
|
||||
'type': 'ipmask',
|
||||
'uuid': 'test_value_24',
|
||||
'visibility': 'enable',
|
||||
'wildcard': 'test_value_26',
|
||||
'wildcard-fqdn': 'test_value_27'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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,349 @@
|
||||
# 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_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_address6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_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_address6': {
|
||||
'cache_ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host_type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj_id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start_ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host-type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj-id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start-ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_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_address6': {
|
||||
'cache_ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host_type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj_id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start_ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host-type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj-id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start-ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_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_address6': {
|
||||
'cache_ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host_type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj_id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start_ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', '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_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_address6': {
|
||||
'cache_ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host_type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj_id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start_ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', '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_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_address6': {
|
||||
'cache_ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host_type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj_id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start_ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host-type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj-id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start-ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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_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_address6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'cache_ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end_ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host_type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj_id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start_ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-ttl': '3',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'end-ip': 'test_value_6',
|
||||
'fqdn': 'test_value_7',
|
||||
'host': 'test_value_8',
|
||||
'host-type': 'any',
|
||||
'ip6': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'obj-id': 'test_value_12',
|
||||
'sdn': 'nsx',
|
||||
'start-ip': 'test_value_14',
|
||||
'template': 'test_value_15',
|
||||
'type': 'ipprefix',
|
||||
'uuid': 'test_value_17',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', '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,219 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_firewall_address6_template
|
||||
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_address6_template.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_address6_template_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_address6_template': {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet_segment_count': '5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6_template.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet-segment-count': '5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'address6-template', 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_address6_template_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_address6_template': {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet_segment_count': '5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6_template.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet-segment-count': '5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'address6-template', 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_address6_template_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_address6_template': {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet_segment_count': '5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6_template.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'address6-template', 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_address6_template_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_address6_template': {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet_segment_count': '5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6_template.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'address6-template', 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_address6_template_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_address6_template': {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet_segment_count': '5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6_template.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet-segment-count': '5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'address6-template', 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_address6_template_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_address6_template': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet_segment_count': '5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_address6_template.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'ip6': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
'subnet-segment-count': '5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'address6-template', 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_addrgrp
|
||||
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_addrgrp.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_addrgrp_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_addrgrp': {
|
||||
'allow_routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp', 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_addrgrp_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_addrgrp': {
|
||||
'allow_routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp', 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_addrgrp_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_addrgrp': {
|
||||
'allow_routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'addrgrp', 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_addrgrp_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_addrgrp': {
|
||||
'allow_routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'addrgrp', 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_addrgrp_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_addrgrp': {
|
||||
'allow_routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp', 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_addrgrp_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_addrgrp': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'allow_routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-routing': 'enable',
|
||||
'color': '4',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_6',
|
||||
'uuid': 'test_value_7',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp', 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_addrgrp6
|
||||
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_addrgrp6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_addrgrp6_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_addrgrp6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp6', 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_addrgrp6_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_addrgrp6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp6', 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_addrgrp6_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_addrgrp6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'addrgrp6', 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_addrgrp6_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_addrgrp6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'addrgrp6', 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_addrgrp6_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_addrgrp6': {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp6', 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_addrgrp6_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_addrgrp6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_addrgrp6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'color': '3',
|
||||
'comment': 'Comment.',
|
||||
'name': 'default_name_5',
|
||||
'uuid': 'test_value_6',
|
||||
'visibility': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'addrgrp6', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,159 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_firewall_auth_portal
|
||||
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_auth_portal.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_auth_portal_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_auth_portal': {'identity_based_route': 'test_value_3',
|
||||
'portal_addr': 'test_value_4',
|
||||
'portal_addr6': 'test_value_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_auth_portal.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'identity-based-route': 'test_value_3',
|
||||
'portal-addr': 'test_value_4',
|
||||
'portal-addr6': 'test_value_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'auth-portal', 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_auth_portal_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_auth_portal': {'identity_based_route': 'test_value_3',
|
||||
'portal_addr': 'test_value_4',
|
||||
'portal_addr6': 'test_value_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_auth_portal.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'identity-based-route': 'test_value_3',
|
||||
'portal-addr': 'test_value_4',
|
||||
'portal-addr6': 'test_value_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'auth-portal', 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_auth_portal_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_auth_portal': {'identity_based_route': 'test_value_3',
|
||||
'portal_addr': 'test_value_4',
|
||||
'portal_addr6': 'test_value_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_auth_portal.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'identity-based-route': 'test_value_3',
|
||||
'portal-addr': 'test_value_4',
|
||||
'portal-addr6': 'test_value_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'auth-portal', 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_auth_portal_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_auth_portal': {
|
||||
'random_attribute_not_valid': 'tag', 'identity_based_route': 'test_value_3',
|
||||
'portal_addr': 'test_value_4',
|
||||
'portal_addr6': 'test_value_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_auth_portal.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {'identity-based-route': 'test_value_3',
|
||||
'portal-addr': 'test_value_4',
|
||||
'portal-addr6': 'test_value_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'auth-portal', 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_central_snat_map
|
||||
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_central_snat_map.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_central_snat_map_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_central_snat_map': {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat_port': 'test_value_5',
|
||||
'orig_port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_central_snat_map.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat-port': 'test_value_5',
|
||||
'orig-port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'central-snat-map', 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_central_snat_map_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_central_snat_map': {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat_port': 'test_value_5',
|
||||
'orig_port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_central_snat_map.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat-port': 'test_value_5',
|
||||
'orig-port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'central-snat-map', 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_central_snat_map_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_central_snat_map': {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat_port': 'test_value_5',
|
||||
'orig_port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_central_snat_map.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'central-snat-map', 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_central_snat_map_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_central_snat_map': {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat_port': 'test_value_5',
|
||||
'orig_port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_central_snat_map.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'central-snat-map', 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_central_snat_map_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_central_snat_map': {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat_port': 'test_value_5',
|
||||
'orig_port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_central_snat_map.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat-port': 'test_value_5',
|
||||
'orig-port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'central-snat-map', 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_central_snat_map_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_central_snat_map': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat_port': 'test_value_5',
|
||||
'orig_port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_central_snat_map.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'nat': 'disable',
|
||||
'nat-port': 'test_value_5',
|
||||
'orig-port': 'test_value_6',
|
||||
'policyid': '7',
|
||||
'protocol': '8',
|
||||
'status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'central-snat-map', 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_dnstranslation
|
||||
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_dnstranslation.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_dnstranslation_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_dnstranslation': {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_dnstranslation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'dnstranslation', 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_dnstranslation_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_dnstranslation': {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_dnstranslation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'dnstranslation', 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_dnstranslation_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_dnstranslation': {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_dnstranslation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'dnstranslation', 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_dnstranslation_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_dnstranslation': {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_dnstranslation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'dnstranslation', 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_dnstranslation_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_dnstranslation': {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_dnstranslation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'dnstranslation', 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_dnstranslation_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_dnstranslation': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_dnstranslation.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'dst': 'test_value_3',
|
||||
'id': '4',
|
||||
'netmask': 'test_value_5',
|
||||
'src': 'test_value_6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'dnstranslation', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,219 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_firewall_identity_based_route
|
||||
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_identity_based_route.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_identity_based_route_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_identity_based_route': {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_identity_based_route.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'identity-based-route', 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_identity_based_route_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_identity_based_route': {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_identity_based_route.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'identity-based-route', 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_identity_based_route_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_identity_based_route': {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_identity_based_route.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'identity-based-route', 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_identity_based_route_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_identity_based_route': {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_identity_based_route.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'identity-based-route', 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_identity_based_route_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_identity_based_route': {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_identity_based_route.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'identity-based-route', 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_identity_based_route_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_identity_based_route': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_identity_based_route.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comments': 'test_value_3',
|
||||
'name': 'default_name_4',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'identity-based-route', 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,399 @@
|
||||
# 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_interface_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_interface_policy.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_interface_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_interface_policy': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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,399 @@
|
||||
# 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_interface_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_interface_policy6.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_interface_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_interface_policy6': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy6': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy6': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy6': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy6': {
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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_interface_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_interface_policy6': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'address_type': 'ipv4',
|
||||
'application_list': 'test_value_4',
|
||||
'application_list_status': 'enable',
|
||||
'av_profile': 'test_value_6',
|
||||
'av_profile_status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp_sensor': 'test_value_9',
|
||||
'dlp_sensor_status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips_sensor': 'test_value_13',
|
||||
'ips_sensor_status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan_botnet_connections': 'disable',
|
||||
'spamfilter_profile': 'test_value_19',
|
||||
'spamfilter_profile_status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter_profile': 'test_value_22',
|
||||
'webfilter_profile_status': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_interface_policy6.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'address-type': 'ipv4',
|
||||
'application-list': 'test_value_4',
|
||||
'application-list-status': 'enable',
|
||||
'av-profile': 'test_value_6',
|
||||
'av-profile-status': 'enable',
|
||||
'comments': 'test_value_8',
|
||||
'dlp-sensor': 'test_value_9',
|
||||
'dlp-sensor-status': 'enable',
|
||||
'dsri': 'enable',
|
||||
'interface': 'test_value_12',
|
||||
'ips-sensor': 'test_value_13',
|
||||
'ips-sensor-status': 'enable',
|
||||
'label': 'test_value_15',
|
||||
'logtraffic': 'all',
|
||||
'policyid': '17',
|
||||
'scan-botnet-connections': 'disable',
|
||||
'spamfilter-profile': 'test_value_19',
|
||||
'spamfilter-profile-status': 'enable',
|
||||
'status': 'enable',
|
||||
'webfilter-profile': 'test_value_22',
|
||||
'webfilter-profile-status': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'interface-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,269 @@
|
||||
# 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
|
||||
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.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_internet_service_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': {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon_id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld_id': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon-id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld-id': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service', 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_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': {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon_id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld_id': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon-id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld-id': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service', 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_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': {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon_id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld_id': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'internet-service', 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_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': {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon_id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld_id': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'internet-service', 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_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': {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon_id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld_id': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon-id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld-id': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service', 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_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': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon_id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld_id': '10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'database': 'isdb',
|
||||
'direction': 'src',
|
||||
'icon-id': '5',
|
||||
'id': '6',
|
||||
'name': 'default_name_7',
|
||||
'offset': '8',
|
||||
'reputation': '9',
|
||||
'sld-id': '10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,219 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_firewall_internet_service_custom
|
||||
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_custom.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_firewall_internet_service_custom_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_custom': {
|
||||
'comment': 'Comment.',
|
||||
'master_service_id': '4',
|
||||
'name': 'default_name_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_custom.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'master-service-id': '4',
|
||||
'name': 'default_name_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-custom', 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_custom_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_custom': {
|
||||
'comment': 'Comment.',
|
||||
'master_service_id': '4',
|
||||
'name': 'default_name_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_custom.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'master-service-id': '4',
|
||||
'name': 'default_name_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-custom', 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_custom_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_custom': {
|
||||
'comment': 'Comment.',
|
||||
'master_service_id': '4',
|
||||
'name': 'default_name_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_custom.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'internet-service-custom', 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_custom_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_custom': {
|
||||
'comment': 'Comment.',
|
||||
'master_service_id': '4',
|
||||
'name': 'default_name_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_custom.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('firewall', 'internet-service-custom', 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_custom_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_custom': {
|
||||
'comment': 'Comment.',
|
||||
'master_service_id': '4',
|
||||
'name': 'default_name_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_custom.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'master-service-id': '4',
|
||||
'name': 'default_name_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-custom', 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_custom_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_custom': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comment': 'Comment.',
|
||||
'master_service_id': '4',
|
||||
'name': 'default_name_5'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_firewall_internet_service_custom.fortios_firewall(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'master-service-id': '4',
|
||||
'name': 'default_name_5'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('firewall', 'internet-service-custom', 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