mirror of https://github.com/ansible/ansible.git
FortiOS modules for 2.9 - 9 (#61320)
* FortiOS modules for 2.9 - 9 * Undo ignore file * Remove non valid identifiers * Leave fortios_switch_controller_lldp_profile and fortios_switch_controller_managed_switch out of this PR * Updated fortios_switch_controller_lldp_profile and fortios_switch_controller_managed_switchpull/61368/head
parent
0074fa5672
commit
e62fb1e2f9
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,339 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_spamfilter_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_spamfilter_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_spamfilter_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',
|
||||
'spamfilter_profile': {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow_based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg_group': 'test_value_7',
|
||||
'spam_bwl_table': '8',
|
||||
'spam_bword_table': '9',
|
||||
'spam_bword_threshold': '10',
|
||||
'spam_filtering': 'enable',
|
||||
'spam_iptrust_table': '12',
|
||||
'spam_log': 'disable',
|
||||
'spam_log_fortiguard_response': 'disable',
|
||||
'spam_mheader_table': '15',
|
||||
'spam_rbl_table': '16',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_spamfilter_profile.fortios_spamfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow-based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg-group': 'test_value_7',
|
||||
'spam-bwl-table': '8',
|
||||
'spam-bword-table': '9',
|
||||
'spam-bword-threshold': '10',
|
||||
'spam-filtering': 'enable',
|
||||
'spam-iptrust-table': '12',
|
||||
'spam-log': 'disable',
|
||||
'spam-log-fortiguard-response': 'disable',
|
||||
'spam-mheader-table': '15',
|
||||
'spam-rbl-table': '16',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('spamfilter', '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_spamfilter_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',
|
||||
'spamfilter_profile': {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow_based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg_group': 'test_value_7',
|
||||
'spam_bwl_table': '8',
|
||||
'spam_bword_table': '9',
|
||||
'spam_bword_threshold': '10',
|
||||
'spam_filtering': 'enable',
|
||||
'spam_iptrust_table': '12',
|
||||
'spam_log': 'disable',
|
||||
'spam_log_fortiguard_response': 'disable',
|
||||
'spam_mheader_table': '15',
|
||||
'spam_rbl_table': '16',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_spamfilter_profile.fortios_spamfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow-based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg-group': 'test_value_7',
|
||||
'spam-bwl-table': '8',
|
||||
'spam-bword-table': '9',
|
||||
'spam-bword-threshold': '10',
|
||||
'spam-filtering': 'enable',
|
||||
'spam-iptrust-table': '12',
|
||||
'spam-log': 'disable',
|
||||
'spam-log-fortiguard-response': 'disable',
|
||||
'spam-mheader-table': '15',
|
||||
'spam-rbl-table': '16',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('spamfilter', '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_spamfilter_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',
|
||||
'spamfilter_profile': {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow_based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg_group': 'test_value_7',
|
||||
'spam_bwl_table': '8',
|
||||
'spam_bword_table': '9',
|
||||
'spam_bword_threshold': '10',
|
||||
'spam_filtering': 'enable',
|
||||
'spam_iptrust_table': '12',
|
||||
'spam_log': 'disable',
|
||||
'spam_log_fortiguard_response': 'disable',
|
||||
'spam_mheader_table': '15',
|
||||
'spam_rbl_table': '16',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_spamfilter_profile.fortios_spamfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('spamfilter', '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_spamfilter_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',
|
||||
'spamfilter_profile': {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow_based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg_group': 'test_value_7',
|
||||
'spam_bwl_table': '8',
|
||||
'spam_bword_table': '9',
|
||||
'spam_bword_threshold': '10',
|
||||
'spam_filtering': 'enable',
|
||||
'spam_iptrust_table': '12',
|
||||
'spam_log': 'disable',
|
||||
'spam_log_fortiguard_response': 'disable',
|
||||
'spam_mheader_table': '15',
|
||||
'spam_rbl_table': '16',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_spamfilter_profile.fortios_spamfilter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('spamfilter', '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_spamfilter_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',
|
||||
'spamfilter_profile': {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow_based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg_group': 'test_value_7',
|
||||
'spam_bwl_table': '8',
|
||||
'spam_bword_table': '9',
|
||||
'spam_bword_threshold': '10',
|
||||
'spam_filtering': 'enable',
|
||||
'spam_iptrust_table': '12',
|
||||
'spam_log': 'disable',
|
||||
'spam_log_fortiguard_response': 'disable',
|
||||
'spam_mheader_table': '15',
|
||||
'spam_rbl_table': '16',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_spamfilter_profile.fortios_spamfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow-based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg-group': 'test_value_7',
|
||||
'spam-bwl-table': '8',
|
||||
'spam-bword-table': '9',
|
||||
'spam-bword-threshold': '10',
|
||||
'spam-filtering': 'enable',
|
||||
'spam-iptrust-table': '12',
|
||||
'spam-log': 'disable',
|
||||
'spam-log-fortiguard-response': 'disable',
|
||||
'spam-mheader-table': '15',
|
||||
'spam-rbl-table': '16',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('spamfilter', '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_spamfilter_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',
|
||||
'spamfilter_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow_based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg_group': 'test_value_7',
|
||||
'spam_bwl_table': '8',
|
||||
'spam_bword_table': '9',
|
||||
'spam_bword_threshold': '10',
|
||||
'spam_filtering': 'enable',
|
||||
'spam_iptrust_table': '12',
|
||||
'spam_log': 'disable',
|
||||
'spam_log_fortiguard_response': 'disable',
|
||||
'spam_mheader_table': '15',
|
||||
'spam_rbl_table': '16',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_spamfilter_profile.fortios_spamfilter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'comment': 'Comment.',
|
||||
'external': 'enable',
|
||||
'flow-based': 'enable',
|
||||
'name': 'default_name_6',
|
||||
'replacemsg-group': 'test_value_7',
|
||||
'spam-bwl-table': '8',
|
||||
'spam-bword-table': '9',
|
||||
'spam-bword-threshold': '10',
|
||||
'spam-filtering': 'enable',
|
||||
'spam-iptrust-table': '12',
|
||||
'spam-log': 'disable',
|
||||
'spam-log-fortiguard-response': 'disable',
|
||||
'spam-mheader-table': '15',
|
||||
'spam-rbl-table': '16',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('spamfilter', '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,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_ssh_filter_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_ssh_filter_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_ssh_filter_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',
|
||||
'ssh_filter_profile': {
|
||||
'block': 'x11',
|
||||
'default_command_log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_ssh_filter_profile.fortios_ssh_filter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'block': 'x11',
|
||||
'default-command-log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('ssh-filter', '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_ssh_filter_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',
|
||||
'ssh_filter_profile': {
|
||||
'block': 'x11',
|
||||
'default_command_log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_ssh_filter_profile.fortios_ssh_filter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'block': 'x11',
|
||||
'default-command-log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('ssh-filter', '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_ssh_filter_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',
|
||||
'ssh_filter_profile': {
|
||||
'block': 'x11',
|
||||
'default_command_log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_ssh_filter_profile.fortios_ssh_filter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('ssh-filter', '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_ssh_filter_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',
|
||||
'ssh_filter_profile': {
|
||||
'block': 'x11',
|
||||
'default_command_log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_ssh_filter_profile.fortios_ssh_filter(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('ssh-filter', '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_ssh_filter_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',
|
||||
'ssh_filter_profile': {
|
||||
'block': 'x11',
|
||||
'default_command_log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_ssh_filter_profile.fortios_ssh_filter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'block': 'x11',
|
||||
'default-command-log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('ssh-filter', '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_ssh_filter_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',
|
||||
'ssh_filter_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'block': 'x11',
|
||||
'default_command_log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_ssh_filter_profile.fortios_ssh_filter(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'block': 'x11',
|
||||
'default-command-log': 'enable',
|
||||
'log': 'x11',
|
||||
'name': 'default_name_6',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('ssh-filter', '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,199 @@
|
||||
# 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_switch_controller_global
|
||||
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_switch_controller_global.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_switch_controller_global_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',
|
||||
'switch_controller_global': {
|
||||
'allow_multiple_interfaces': 'enable',
|
||||
'default_virtual_switch_vlan': 'test_value_4',
|
||||
'https_image_push': 'enable',
|
||||
'log_mac_limit_violations': 'enable',
|
||||
'mac_aging_interval': '7',
|
||||
'mac_retention_period': '8',
|
||||
'mac_violation_timer': '9'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_global.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-multiple-interfaces': 'enable',
|
||||
'default-virtual-switch-vlan': 'test_value_4',
|
||||
'https-image-push': 'enable',
|
||||
'log-mac-limit-violations': 'enable',
|
||||
'mac-aging-interval': '7',
|
||||
'mac-retention-period': '8',
|
||||
'mac-violation-timer': '9'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'global', 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_switch_controller_global_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',
|
||||
'switch_controller_global': {
|
||||
'allow_multiple_interfaces': 'enable',
|
||||
'default_virtual_switch_vlan': 'test_value_4',
|
||||
'https_image_push': 'enable',
|
||||
'log_mac_limit_violations': 'enable',
|
||||
'mac_aging_interval': '7',
|
||||
'mac_retention_period': '8',
|
||||
'mac_violation_timer': '9'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_global.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-multiple-interfaces': 'enable',
|
||||
'default-virtual-switch-vlan': 'test_value_4',
|
||||
'https-image-push': 'enable',
|
||||
'log-mac-limit-violations': 'enable',
|
||||
'mac-aging-interval': '7',
|
||||
'mac-retention-period': '8',
|
||||
'mac-violation-timer': '9'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'global', 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_switch_controller_global_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',
|
||||
'switch_controller_global': {
|
||||
'allow_multiple_interfaces': 'enable',
|
||||
'default_virtual_switch_vlan': 'test_value_4',
|
||||
'https_image_push': 'enable',
|
||||
'log_mac_limit_violations': 'enable',
|
||||
'mac_aging_interval': '7',
|
||||
'mac_retention_period': '8',
|
||||
'mac_violation_timer': '9'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_global.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-multiple-interfaces': 'enable',
|
||||
'default-virtual-switch-vlan': 'test_value_4',
|
||||
'https-image-push': 'enable',
|
||||
'log-mac-limit-violations': 'enable',
|
||||
'mac-aging-interval': '7',
|
||||
'mac-retention-period': '8',
|
||||
'mac-violation-timer': '9'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'global', 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_switch_controller_global_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',
|
||||
'switch_controller_global': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'allow_multiple_interfaces': 'enable',
|
||||
'default_virtual_switch_vlan': 'test_value_4',
|
||||
'https_image_push': 'enable',
|
||||
'log_mac_limit_violations': 'enable',
|
||||
'mac_aging_interval': '7',
|
||||
'mac_retention_period': '8',
|
||||
'mac_violation_timer': '9'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_global.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-multiple-interfaces': 'enable',
|
||||
'default-virtual-switch-vlan': 'test_value_4',
|
||||
'https-image-push': 'enable',
|
||||
'log-mac-limit-violations': 'enable',
|
||||
'mac-aging-interval': '7',
|
||||
'mac-retention-period': '8',
|
||||
'mac-violation-timer': '9'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'global', 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_switch_controller_lldp_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_switch_controller_lldp_profile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_profile': {
|
||||
'802.1_tlvs': 'port-vlan-id',
|
||||
'802.3_tlvs': 'max-frame-size',
|
||||
'auto_isl': 'disable',
|
||||
'auto_isl_hello_timer': '6',
|
||||
'auto_isl_port_group': '7',
|
||||
'auto_isl_receive_timeout': '8',
|
||||
'med_tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_profile.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'802.1-tlvs': 'port-vlan-id',
|
||||
'802.3-tlvs': 'max-frame-size',
|
||||
'auto-isl': 'disable',
|
||||
'auto-isl-hello-timer': '6',
|
||||
'auto-isl-port-group': '7',
|
||||
'auto-isl-receive-timeout': '8',
|
||||
'med-tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_profile': {
|
||||
'802.1_tlvs': 'port-vlan-id',
|
||||
'802.3_tlvs': 'max-frame-size',
|
||||
'auto_isl': 'disable',
|
||||
'auto_isl_hello_timer': '6',
|
||||
'auto_isl_port_group': '7',
|
||||
'auto_isl_receive_timeout': '8',
|
||||
'med_tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_profile.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'802.1-tlvs': 'port-vlan-id',
|
||||
'802.3-tlvs': 'max-frame-size',
|
||||
'auto-isl': 'disable',
|
||||
'auto-isl-hello-timer': '6',
|
||||
'auto-isl-port-group': '7',
|
||||
'auto-isl-receive-timeout': '8',
|
||||
'med-tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_profile': {
|
||||
'802.1_tlvs': 'port-vlan-id',
|
||||
'802.3_tlvs': 'max-frame-size',
|
||||
'auto_isl': 'disable',
|
||||
'auto_isl_hello_timer': '6',
|
||||
'auto_isl_port_group': '7',
|
||||
'auto_isl_receive_timeout': '8',
|
||||
'med_tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_profile.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_profile': {
|
||||
'802.1_tlvs': 'port-vlan-id',
|
||||
'802.3_tlvs': 'max-frame-size',
|
||||
'auto_isl': 'disable',
|
||||
'auto_isl_hello_timer': '6',
|
||||
'auto_isl_port_group': '7',
|
||||
'auto_isl_receive_timeout': '8',
|
||||
'med_tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_profile.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_profile': {
|
||||
'802.1_tlvs': 'port-vlan-id',
|
||||
'802.3_tlvs': 'max-frame-size',
|
||||
'auto_isl': 'disable',
|
||||
'auto_isl_hello_timer': '6',
|
||||
'auto_isl_port_group': '7',
|
||||
'auto_isl_receive_timeout': '8',
|
||||
'med_tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_profile.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'802.1-tlvs': 'port-vlan-id',
|
||||
'802.3-tlvs': 'max-frame-size',
|
||||
'auto-isl': 'disable',
|
||||
'auto-isl-hello-timer': '6',
|
||||
'auto-isl-port-group': '7',
|
||||
'auto-isl-receive-timeout': '8',
|
||||
'med-tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_profile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'802.1_tlvs': 'port-vlan-id',
|
||||
'802.3_tlvs': 'max-frame-size',
|
||||
'auto_isl': 'disable',
|
||||
'auto_isl_hello_timer': '6',
|
||||
'auto_isl_port_group': '7',
|
||||
'auto_isl_receive_timeout': '8',
|
||||
'med_tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_profile.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'802.1-tlvs': 'port-vlan-id',
|
||||
'802.3-tlvs': 'max-frame-size',
|
||||
'auto-isl': 'disable',
|
||||
'auto-isl-hello-timer': '6',
|
||||
'auto-isl-port-group': '7',
|
||||
'auto-isl-receive-timeout': '8',
|
||||
'med-tlvs': 'inventory-management',
|
||||
'name': 'default_name_10'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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,183 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_switch_controller_lldp_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_switch_controller_lldp_settings.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_settings': {
|
||||
'fast_start_interval': '3',
|
||||
'management_interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx_hold': '6',
|
||||
'tx_interval': '7'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-start-interval': '3',
|
||||
'management-interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx-hold': '6',
|
||||
'tx-interval': '7'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_settings': {
|
||||
'fast_start_interval': '3',
|
||||
'management_interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx_hold': '6',
|
||||
'tx_interval': '7'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-start-interval': '3',
|
||||
'management-interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx-hold': '6',
|
||||
'tx-interval': '7'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_settings': {
|
||||
'fast_start_interval': '3',
|
||||
'management_interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx_hold': '6',
|
||||
'tx_interval': '7'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-start-interval': '3',
|
||||
'management-interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx-hold': '6',
|
||||
'tx-interval': '7'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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_switch_controller_lldp_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',
|
||||
'switch_controller_lldp_settings': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'fast_start_interval': '3',
|
||||
'management_interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx_hold': '6',
|
||||
'tx_interval': '7'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_lldp_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'fast-start-interval': '3',
|
||||
'management-interface': 'internal',
|
||||
'status': 'enable',
|
||||
'tx-hold': '6',
|
||||
'tx-interval': '7'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'lldp-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,151 @@
|
||||
# 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_switch_controller_mac_sync_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_switch_controller_mac_sync_settings.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_switch_controller_mac_sync_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',
|
||||
'switch_controller_mac_sync_settings': {
|
||||
'mac_sync_interval': '3'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_mac_sync_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'mac-sync-interval': '3'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'mac-sync-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_switch_controller_mac_sync_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',
|
||||
'switch_controller_mac_sync_settings': {
|
||||
'mac_sync_interval': '3'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_mac_sync_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'mac-sync-interval': '3'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'mac-sync-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_switch_controller_mac_sync_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',
|
||||
'switch_controller_mac_sync_settings': {
|
||||
'mac_sync_interval': '3'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_mac_sync_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'mac-sync-interval': '3'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'mac-sync-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_switch_controller_mac_sync_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',
|
||||
'switch_controller_mac_sync_settings': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'mac_sync_interval': '3'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_mac_sync_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'mac-sync-interval': '3'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'mac-sync-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,389 @@
|
||||
# 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_switch_controller_managed_switch
|
||||
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_switch_controller_managed_switch.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_switch_controller_managed_switch_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',
|
||||
'switch_controller_managed_switch': {'delayed_restart_trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly_connected': '5',
|
||||
'dynamic_capability': '6',
|
||||
'dynamically_discovered': '7',
|
||||
'fsw_wan1_admin': 'discovered',
|
||||
'fsw_wan1_peer': 'test_value_9',
|
||||
'fsw_wan2_admin': 'discovered',
|
||||
'fsw_wan2_peer': 'test_value_11',
|
||||
'max_allowed_trunk_members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner_vdom': 'test_value_14',
|
||||
'poe_detection_type': '15',
|
||||
'poe_pre_standard_detection': 'enable',
|
||||
'pre_provisioned': '17',
|
||||
'staged_image_version': 'test_value_18',
|
||||
'switch_device_tag': 'test_value_19',
|
||||
'switch_id': 'test_value_20',
|
||||
'switch_profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_managed_switch.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {'delayed-restart-trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly-connected': '5',
|
||||
'dynamic-capability': '6',
|
||||
'dynamically-discovered': '7',
|
||||
'fsw-wan1-admin': 'discovered',
|
||||
'fsw-wan1-peer': 'test_value_9',
|
||||
'fsw-wan2-admin': 'discovered',
|
||||
'fsw-wan2-peer': 'test_value_11',
|
||||
'max-allowed-trunk-members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner-vdom': 'test_value_14',
|
||||
'poe-detection-type': '15',
|
||||
'poe-pre-standard-detection': 'enable',
|
||||
'pre-provisioned': '17',
|
||||
'staged-image-version': 'test_value_18',
|
||||
'switch-device-tag': 'test_value_19',
|
||||
'switch-id': 'test_value_20',
|
||||
'switch-profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'managed-switch', 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_switch_controller_managed_switch_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',
|
||||
'switch_controller_managed_switch': {'delayed_restart_trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly_connected': '5',
|
||||
'dynamic_capability': '6',
|
||||
'dynamically_discovered': '7',
|
||||
'fsw_wan1_admin': 'discovered',
|
||||
'fsw_wan1_peer': 'test_value_9',
|
||||
'fsw_wan2_admin': 'discovered',
|
||||
'fsw_wan2_peer': 'test_value_11',
|
||||
'max_allowed_trunk_members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner_vdom': 'test_value_14',
|
||||
'poe_detection_type': '15',
|
||||
'poe_pre_standard_detection': 'enable',
|
||||
'pre_provisioned': '17',
|
||||
'staged_image_version': 'test_value_18',
|
||||
'switch_device_tag': 'test_value_19',
|
||||
'switch_id': 'test_value_20',
|
||||
'switch_profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_managed_switch.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {'delayed-restart-trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly-connected': '5',
|
||||
'dynamic-capability': '6',
|
||||
'dynamically-discovered': '7',
|
||||
'fsw-wan1-admin': 'discovered',
|
||||
'fsw-wan1-peer': 'test_value_9',
|
||||
'fsw-wan2-admin': 'discovered',
|
||||
'fsw-wan2-peer': 'test_value_11',
|
||||
'max-allowed-trunk-members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner-vdom': 'test_value_14',
|
||||
'poe-detection-type': '15',
|
||||
'poe-pre-standard-detection': 'enable',
|
||||
'pre-provisioned': '17',
|
||||
'staged-image-version': 'test_value_18',
|
||||
'switch-device-tag': 'test_value_19',
|
||||
'switch-id': 'test_value_20',
|
||||
'switch-profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'managed-switch', 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_switch_controller_managed_switch_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',
|
||||
'switch_controller_managed_switch': {'delayed_restart_trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly_connected': '5',
|
||||
'dynamic_capability': '6',
|
||||
'dynamically_discovered': '7',
|
||||
'fsw_wan1_admin': 'discovered',
|
||||
'fsw_wan1_peer': 'test_value_9',
|
||||
'fsw_wan2_admin': 'discovered',
|
||||
'fsw_wan2_peer': 'test_value_11',
|
||||
'max_allowed_trunk_members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner_vdom': 'test_value_14',
|
||||
'poe_detection_type': '15',
|
||||
'poe_pre_standard_detection': 'enable',
|
||||
'pre_provisioned': '17',
|
||||
'staged_image_version': 'test_value_18',
|
||||
'switch_device_tag': 'test_value_19',
|
||||
'switch_id': 'test_value_20',
|
||||
'switch_profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_managed_switch.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('switch-controller', 'managed-switch', 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_switch_controller_managed_switch_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',
|
||||
'switch_controller_managed_switch': {'delayed_restart_trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly_connected': '5',
|
||||
'dynamic_capability': '6',
|
||||
'dynamically_discovered': '7',
|
||||
'fsw_wan1_admin': 'discovered',
|
||||
'fsw_wan1_peer': 'test_value_9',
|
||||
'fsw_wan2_admin': 'discovered',
|
||||
'fsw_wan2_peer': 'test_value_11',
|
||||
'max_allowed_trunk_members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner_vdom': 'test_value_14',
|
||||
'poe_detection_type': '15',
|
||||
'poe_pre_standard_detection': 'enable',
|
||||
'pre_provisioned': '17',
|
||||
'staged_image_version': 'test_value_18',
|
||||
'switch_device_tag': 'test_value_19',
|
||||
'switch_id': 'test_value_20',
|
||||
'switch_profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_managed_switch.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('switch-controller', 'managed-switch', 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_switch_controller_managed_switch_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',
|
||||
'switch_controller_managed_switch': {'delayed_restart_trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly_connected': '5',
|
||||
'dynamic_capability': '6',
|
||||
'dynamically_discovered': '7',
|
||||
'fsw_wan1_admin': 'discovered',
|
||||
'fsw_wan1_peer': 'test_value_9',
|
||||
'fsw_wan2_admin': 'discovered',
|
||||
'fsw_wan2_peer': 'test_value_11',
|
||||
'max_allowed_trunk_members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner_vdom': 'test_value_14',
|
||||
'poe_detection_type': '15',
|
||||
'poe_pre_standard_detection': 'enable',
|
||||
'pre_provisioned': '17',
|
||||
'staged_image_version': 'test_value_18',
|
||||
'switch_device_tag': 'test_value_19',
|
||||
'switch_id': 'test_value_20',
|
||||
'switch_profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_managed_switch.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {'delayed-restart-trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly-connected': '5',
|
||||
'dynamic-capability': '6',
|
||||
'dynamically-discovered': '7',
|
||||
'fsw-wan1-admin': 'discovered',
|
||||
'fsw-wan1-peer': 'test_value_9',
|
||||
'fsw-wan2-admin': 'discovered',
|
||||
'fsw-wan2-peer': 'test_value_11',
|
||||
'max-allowed-trunk-members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner-vdom': 'test_value_14',
|
||||
'poe-detection-type': '15',
|
||||
'poe-pre-standard-detection': 'enable',
|
||||
'pre-provisioned': '17',
|
||||
'staged-image-version': 'test_value_18',
|
||||
'switch-device-tag': 'test_value_19',
|
||||
'switch-id': 'test_value_20',
|
||||
'switch-profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'managed-switch', 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_switch_controller_managed_switch_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',
|
||||
'switch_controller_managed_switch': {
|
||||
'random_attribute_not_valid': 'tag', 'delayed_restart_trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly_connected': '5',
|
||||
'dynamic_capability': '6',
|
||||
'dynamically_discovered': '7',
|
||||
'fsw_wan1_admin': 'discovered',
|
||||
'fsw_wan1_peer': 'test_value_9',
|
||||
'fsw_wan2_admin': 'discovered',
|
||||
'fsw_wan2_peer': 'test_value_11',
|
||||
'max_allowed_trunk_members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner_vdom': 'test_value_14',
|
||||
'poe_detection_type': '15',
|
||||
'poe_pre_standard_detection': 'enable',
|
||||
'pre_provisioned': '17',
|
||||
'staged_image_version': 'test_value_18',
|
||||
'switch_device_tag': 'test_value_19',
|
||||
'switch_id': 'test_value_20',
|
||||
'switch_profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_managed_switch.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {'delayed-restart-trigger': '3',
|
||||
'description': 'test_value_4',
|
||||
'directly-connected': '5',
|
||||
'dynamic-capability': '6',
|
||||
'dynamically-discovered': '7',
|
||||
'fsw-wan1-admin': 'discovered',
|
||||
'fsw-wan1-peer': 'test_value_9',
|
||||
'fsw-wan2-admin': 'discovered',
|
||||
'fsw-wan2-peer': 'test_value_11',
|
||||
'max-allowed-trunk-members': '12',
|
||||
'name': 'default_name_13',
|
||||
'owner-vdom': 'test_value_14',
|
||||
'poe-detection-type': '15',
|
||||
'poe-pre-standard-detection': 'enable',
|
||||
'pre-provisioned': '17',
|
||||
'staged-image-version': 'test_value_18',
|
||||
'switch-device-tag': 'test_value_19',
|
||||
'switch-id': 'test_value_20',
|
||||
'switch-profile': 'test_value_21',
|
||||
'type': 'virtual',
|
||||
'version': '23'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'managed-switch', 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,151 @@
|
||||
# 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_switch_controller_network_monitor_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_switch_controller_network_monitor_settings.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_switch_controller_network_monitor_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',
|
||||
'switch_controller_network_monitor_settings': {
|
||||
'network_monitoring': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_network_monitor_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'network-monitoring': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'network-monitor-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_switch_controller_network_monitor_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',
|
||||
'switch_controller_network_monitor_settings': {
|
||||
'network_monitoring': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_network_monitor_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'network-monitoring': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'network-monitor-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_switch_controller_network_monitor_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',
|
||||
'switch_controller_network_monitor_settings': {
|
||||
'network_monitoring': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_network_monitor_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'network-monitoring': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'network-monitor-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_switch_controller_network_monitor_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',
|
||||
'switch_controller_network_monitor_settings': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'network_monitoring': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_switch_controller_network_monitor_settings.fortios_switch_controller(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'network-monitoring': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('switch-controller', 'network-monitor-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,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_system_accprofile
|
||||
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_system_accprofile.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_accprofile_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',
|
||||
'system_accprofile': {
|
||||
'admintimeout': '3',
|
||||
'admintimeout_override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_accprofile.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admintimeout': '3',
|
||||
'admintimeout-override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'accprofile', 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_system_accprofile_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',
|
||||
'system_accprofile': {
|
||||
'admintimeout': '3',
|
||||
'admintimeout_override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_accprofile.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admintimeout': '3',
|
||||
'admintimeout-override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'accprofile', 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_system_accprofile_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',
|
||||
'system_accprofile': {
|
||||
'admintimeout': '3',
|
||||
'admintimeout_override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_accprofile.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'accprofile', 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_system_accprofile_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',
|
||||
'system_accprofile': {
|
||||
'admintimeout': '3',
|
||||
'admintimeout_override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_accprofile.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'accprofile', 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_system_accprofile_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',
|
||||
'system_accprofile': {
|
||||
'admintimeout': '3',
|
||||
'admintimeout_override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_accprofile.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admintimeout': '3',
|
||||
'admintimeout-override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'accprofile', 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_system_accprofile_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',
|
||||
'system_accprofile': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'admintimeout': '3',
|
||||
'admintimeout_override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_accprofile.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'admintimeout': '3',
|
||||
'admintimeout-override': 'enable',
|
||||
'authgrp': 'none',
|
||||
'comments': 'test_value_6',
|
||||
'ftviewgrp': 'none',
|
||||
'fwgrp': 'none',
|
||||
'loggrp': 'none',
|
||||
'name': 'default_name_10',
|
||||
'netgrp': 'none',
|
||||
'scope': 'vdom',
|
||||
'secfabgrp': 'none',
|
||||
'sysgrp': 'none',
|
||||
'utmgrp': 'none',
|
||||
'vpngrp': 'none',
|
||||
'wanoptgrp': 'none',
|
||||
'wifi': 'none'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'accprofile', 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,689 @@
|
||||
# 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_system_admin
|
||||
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_system_admin.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_admin_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',
|
||||
'system_admin': {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile_override': 'enable',
|
||||
'allow_remove_admin_session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email_to': 'test_value_7',
|
||||
'force_password_change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest_auth': 'disable',
|
||||
'guest_lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6_trusthost1': 'test_value_15',
|
||||
'ip6_trusthost10': 'test_value_16',
|
||||
'ip6_trusthost2': 'test_value_17',
|
||||
'ip6_trusthost3': 'test_value_18',
|
||||
'ip6_trusthost4': 'test_value_19',
|
||||
'ip6_trusthost5': 'test_value_20',
|
||||
'ip6_trusthost6': 'test_value_21',
|
||||
'ip6_trusthost7': 'test_value_22',
|
||||
'ip6_trusthost8': 'test_value_23',
|
||||
'ip6_trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password_expire': 'test_value_27',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_29',
|
||||
'radius_vdom_override': 'enable',
|
||||
'remote_auth': 'enable',
|
||||
'remote_group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms_custom_server': 'test_value_34',
|
||||
'sms_phone': 'test_value_35',
|
||||
'sms_server': 'fortiguard',
|
||||
'ssh_certificate': 'test_value_37',
|
||||
'ssh_public_key1': 'test_value_38',
|
||||
'ssh_public_key2': 'test_value_39',
|
||||
'ssh_public_key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two_factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_admin.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile-override': 'enable',
|
||||
'allow-remove-admin-session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email-to': 'test_value_7',
|
||||
'force-password-change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest-auth': 'disable',
|
||||
'guest-lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6-trusthost1': 'test_value_15',
|
||||
'ip6-trusthost10': 'test_value_16',
|
||||
'ip6-trusthost2': 'test_value_17',
|
||||
'ip6-trusthost3': 'test_value_18',
|
||||
'ip6-trusthost4': 'test_value_19',
|
||||
'ip6-trusthost5': 'test_value_20',
|
||||
'ip6-trusthost6': 'test_value_21',
|
||||
'ip6-trusthost7': 'test_value_22',
|
||||
'ip6-trusthost8': 'test_value_23',
|
||||
'ip6-trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password-expire': 'test_value_27',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_29',
|
||||
'radius-vdom-override': 'enable',
|
||||
'remote-auth': 'enable',
|
||||
'remote-group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms-custom-server': 'test_value_34',
|
||||
'sms-phone': 'test_value_35',
|
||||
'sms-server': 'fortiguard',
|
||||
'ssh-certificate': 'test_value_37',
|
||||
'ssh-public-key1': 'test_value_38',
|
||||
'ssh-public-key2': 'test_value_39',
|
||||
'ssh-public-key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two-factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'admin', 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_system_admin_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',
|
||||
'system_admin': {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile_override': 'enable',
|
||||
'allow_remove_admin_session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email_to': 'test_value_7',
|
||||
'force_password_change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest_auth': 'disable',
|
||||
'guest_lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6_trusthost1': 'test_value_15',
|
||||
'ip6_trusthost10': 'test_value_16',
|
||||
'ip6_trusthost2': 'test_value_17',
|
||||
'ip6_trusthost3': 'test_value_18',
|
||||
'ip6_trusthost4': 'test_value_19',
|
||||
'ip6_trusthost5': 'test_value_20',
|
||||
'ip6_trusthost6': 'test_value_21',
|
||||
'ip6_trusthost7': 'test_value_22',
|
||||
'ip6_trusthost8': 'test_value_23',
|
||||
'ip6_trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password_expire': 'test_value_27',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_29',
|
||||
'radius_vdom_override': 'enable',
|
||||
'remote_auth': 'enable',
|
||||
'remote_group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms_custom_server': 'test_value_34',
|
||||
'sms_phone': 'test_value_35',
|
||||
'sms_server': 'fortiguard',
|
||||
'ssh_certificate': 'test_value_37',
|
||||
'ssh_public_key1': 'test_value_38',
|
||||
'ssh_public_key2': 'test_value_39',
|
||||
'ssh_public_key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two_factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_admin.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile-override': 'enable',
|
||||
'allow-remove-admin-session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email-to': 'test_value_7',
|
||||
'force-password-change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest-auth': 'disable',
|
||||
'guest-lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6-trusthost1': 'test_value_15',
|
||||
'ip6-trusthost10': 'test_value_16',
|
||||
'ip6-trusthost2': 'test_value_17',
|
||||
'ip6-trusthost3': 'test_value_18',
|
||||
'ip6-trusthost4': 'test_value_19',
|
||||
'ip6-trusthost5': 'test_value_20',
|
||||
'ip6-trusthost6': 'test_value_21',
|
||||
'ip6-trusthost7': 'test_value_22',
|
||||
'ip6-trusthost8': 'test_value_23',
|
||||
'ip6-trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password-expire': 'test_value_27',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_29',
|
||||
'radius-vdom-override': 'enable',
|
||||
'remote-auth': 'enable',
|
||||
'remote-group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms-custom-server': 'test_value_34',
|
||||
'sms-phone': 'test_value_35',
|
||||
'sms-server': 'fortiguard',
|
||||
'ssh-certificate': 'test_value_37',
|
||||
'ssh-public-key1': 'test_value_38',
|
||||
'ssh-public-key2': 'test_value_39',
|
||||
'ssh-public-key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two-factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'admin', 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_system_admin_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',
|
||||
'system_admin': {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile_override': 'enable',
|
||||
'allow_remove_admin_session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email_to': 'test_value_7',
|
||||
'force_password_change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest_auth': 'disable',
|
||||
'guest_lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6_trusthost1': 'test_value_15',
|
||||
'ip6_trusthost10': 'test_value_16',
|
||||
'ip6_trusthost2': 'test_value_17',
|
||||
'ip6_trusthost3': 'test_value_18',
|
||||
'ip6_trusthost4': 'test_value_19',
|
||||
'ip6_trusthost5': 'test_value_20',
|
||||
'ip6_trusthost6': 'test_value_21',
|
||||
'ip6_trusthost7': 'test_value_22',
|
||||
'ip6_trusthost8': 'test_value_23',
|
||||
'ip6_trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password_expire': 'test_value_27',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_29',
|
||||
'radius_vdom_override': 'enable',
|
||||
'remote_auth': 'enable',
|
||||
'remote_group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms_custom_server': 'test_value_34',
|
||||
'sms_phone': 'test_value_35',
|
||||
'sms_server': 'fortiguard',
|
||||
'ssh_certificate': 'test_value_37',
|
||||
'ssh_public_key1': 'test_value_38',
|
||||
'ssh_public_key2': 'test_value_39',
|
||||
'ssh_public_key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two_factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_admin.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'admin', 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_system_admin_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',
|
||||
'system_admin': {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile_override': 'enable',
|
||||
'allow_remove_admin_session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email_to': 'test_value_7',
|
||||
'force_password_change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest_auth': 'disable',
|
||||
'guest_lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6_trusthost1': 'test_value_15',
|
||||
'ip6_trusthost10': 'test_value_16',
|
||||
'ip6_trusthost2': 'test_value_17',
|
||||
'ip6_trusthost3': 'test_value_18',
|
||||
'ip6_trusthost4': 'test_value_19',
|
||||
'ip6_trusthost5': 'test_value_20',
|
||||
'ip6_trusthost6': 'test_value_21',
|
||||
'ip6_trusthost7': 'test_value_22',
|
||||
'ip6_trusthost8': 'test_value_23',
|
||||
'ip6_trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password_expire': 'test_value_27',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_29',
|
||||
'radius_vdom_override': 'enable',
|
||||
'remote_auth': 'enable',
|
||||
'remote_group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms_custom_server': 'test_value_34',
|
||||
'sms_phone': 'test_value_35',
|
||||
'sms_server': 'fortiguard',
|
||||
'ssh_certificate': 'test_value_37',
|
||||
'ssh_public_key1': 'test_value_38',
|
||||
'ssh_public_key2': 'test_value_39',
|
||||
'ssh_public_key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two_factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_admin.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'admin', 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_system_admin_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',
|
||||
'system_admin': {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile_override': 'enable',
|
||||
'allow_remove_admin_session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email_to': 'test_value_7',
|
||||
'force_password_change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest_auth': 'disable',
|
||||
'guest_lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6_trusthost1': 'test_value_15',
|
||||
'ip6_trusthost10': 'test_value_16',
|
||||
'ip6_trusthost2': 'test_value_17',
|
||||
'ip6_trusthost3': 'test_value_18',
|
||||
'ip6_trusthost4': 'test_value_19',
|
||||
'ip6_trusthost5': 'test_value_20',
|
||||
'ip6_trusthost6': 'test_value_21',
|
||||
'ip6_trusthost7': 'test_value_22',
|
||||
'ip6_trusthost8': 'test_value_23',
|
||||
'ip6_trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password_expire': 'test_value_27',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_29',
|
||||
'radius_vdom_override': 'enable',
|
||||
'remote_auth': 'enable',
|
||||
'remote_group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms_custom_server': 'test_value_34',
|
||||
'sms_phone': 'test_value_35',
|
||||
'sms_server': 'fortiguard',
|
||||
'ssh_certificate': 'test_value_37',
|
||||
'ssh_public_key1': 'test_value_38',
|
||||
'ssh_public_key2': 'test_value_39',
|
||||
'ssh_public_key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two_factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_admin.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile-override': 'enable',
|
||||
'allow-remove-admin-session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email-to': 'test_value_7',
|
||||
'force-password-change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest-auth': 'disable',
|
||||
'guest-lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6-trusthost1': 'test_value_15',
|
||||
'ip6-trusthost10': 'test_value_16',
|
||||
'ip6-trusthost2': 'test_value_17',
|
||||
'ip6-trusthost3': 'test_value_18',
|
||||
'ip6-trusthost4': 'test_value_19',
|
||||
'ip6-trusthost5': 'test_value_20',
|
||||
'ip6-trusthost6': 'test_value_21',
|
||||
'ip6-trusthost7': 'test_value_22',
|
||||
'ip6-trusthost8': 'test_value_23',
|
||||
'ip6-trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password-expire': 'test_value_27',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_29',
|
||||
'radius-vdom-override': 'enable',
|
||||
'remote-auth': 'enable',
|
||||
'remote-group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms-custom-server': 'test_value_34',
|
||||
'sms-phone': 'test_value_35',
|
||||
'sms-server': 'fortiguard',
|
||||
'ssh-certificate': 'test_value_37',
|
||||
'ssh-public-key1': 'test_value_38',
|
||||
'ssh-public-key2': 'test_value_39',
|
||||
'ssh-public-key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two-factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'admin', 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_system_admin_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',
|
||||
'system_admin': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile_override': 'enable',
|
||||
'allow_remove_admin_session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email_to': 'test_value_7',
|
||||
'force_password_change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest_auth': 'disable',
|
||||
'guest_lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6_trusthost1': 'test_value_15',
|
||||
'ip6_trusthost10': 'test_value_16',
|
||||
'ip6_trusthost2': 'test_value_17',
|
||||
'ip6_trusthost3': 'test_value_18',
|
||||
'ip6_trusthost4': 'test_value_19',
|
||||
'ip6_trusthost5': 'test_value_20',
|
||||
'ip6_trusthost6': 'test_value_21',
|
||||
'ip6_trusthost7': 'test_value_22',
|
||||
'ip6_trusthost8': 'test_value_23',
|
||||
'ip6_trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password_expire': 'test_value_27',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_29',
|
||||
'radius_vdom_override': 'enable',
|
||||
'remote_auth': 'enable',
|
||||
'remote_group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms_custom_server': 'test_value_34',
|
||||
'sms_phone': 'test_value_35',
|
||||
'sms_server': 'fortiguard',
|
||||
'ssh_certificate': 'test_value_37',
|
||||
'ssh_public_key1': 'test_value_38',
|
||||
'ssh_public_key2': 'test_value_39',
|
||||
'ssh_public_key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two_factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_admin.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'accprofile-override': 'enable',
|
||||
'allow-remove-admin-session': 'enable',
|
||||
'comments': 'test_value_6',
|
||||
'email-to': 'test_value_7',
|
||||
'force-password-change': 'enable',
|
||||
'fortitoken': 'test_value_9',
|
||||
'guest-auth': 'disable',
|
||||
'guest-lang': 'test_value_11',
|
||||
'hidden': '12',
|
||||
'history0': 'test_value_13',
|
||||
'history1': 'test_value_14',
|
||||
'ip6-trusthost1': 'test_value_15',
|
||||
'ip6-trusthost10': 'test_value_16',
|
||||
'ip6-trusthost2': 'test_value_17',
|
||||
'ip6-trusthost3': 'test_value_18',
|
||||
'ip6-trusthost4': 'test_value_19',
|
||||
'ip6-trusthost5': 'test_value_20',
|
||||
'ip6-trusthost6': 'test_value_21',
|
||||
'ip6-trusthost7': 'test_value_22',
|
||||
'ip6-trusthost8': 'test_value_23',
|
||||
'ip6-trusthost9': 'test_value_24',
|
||||
'name': 'default_name_25',
|
||||
'password': 'test_value_26',
|
||||
'password-expire': 'test_value_27',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_29',
|
||||
'radius-vdom-override': 'enable',
|
||||
'remote-auth': 'enable',
|
||||
'remote-group': 'test_value_32',
|
||||
'schedule': 'test_value_33',
|
||||
'sms-custom-server': 'test_value_34',
|
||||
'sms-phone': 'test_value_35',
|
||||
'sms-server': 'fortiguard',
|
||||
'ssh-certificate': 'test_value_37',
|
||||
'ssh-public-key1': 'test_value_38',
|
||||
'ssh-public-key2': 'test_value_39',
|
||||
'ssh-public-key3': 'test_value_40',
|
||||
'trusthost1': 'test_value_41',
|
||||
'trusthost10': 'test_value_42',
|
||||
'trusthost2': 'test_value_43',
|
||||
'trusthost3': 'test_value_44',
|
||||
'trusthost4': 'test_value_45',
|
||||
'trusthost5': 'test_value_46',
|
||||
'trusthost6': 'test_value_47',
|
||||
'trusthost7': 'test_value_48',
|
||||
'trusthost8': 'test_value_49',
|
||||
'trusthost9': 'test_value_50',
|
||||
'two-factor': 'disable',
|
||||
'wildcard': 'enable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'admin', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
@ -0,0 +1,279 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_system_api_user
|
||||
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_system_api_user.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_api_user_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',
|
||||
'system_api_user': {
|
||||
'accprofile': 'test_value_3',
|
||||
'api_key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors_allow_origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_api_user.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'api-key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors-allow-origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'api-user', 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_system_api_user_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',
|
||||
'system_api_user': {
|
||||
'accprofile': 'test_value_3',
|
||||
'api_key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors_allow_origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_api_user.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'api-key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors-allow-origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'api-user', 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_system_api_user_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',
|
||||
'system_api_user': {
|
||||
'accprofile': 'test_value_3',
|
||||
'api_key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors_allow_origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_api_user.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'api-user', 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_system_api_user_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',
|
||||
'system_api_user': {
|
||||
'accprofile': 'test_value_3',
|
||||
'api_key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors_allow_origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_api_user.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'api-user', 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_system_api_user_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',
|
||||
'system_api_user': {
|
||||
'accprofile': 'test_value_3',
|
||||
'api_key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors_allow_origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_api_user.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'api-key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors-allow-origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'api-user', 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_system_api_user_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',
|
||||
'system_api_user': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'accprofile': 'test_value_3',
|
||||
'api_key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors_allow_origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer_auth': 'enable',
|
||||
'peer_group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_api_user.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'accprofile': 'test_value_3',
|
||||
'api-key': 'test_value_4',
|
||||
'comments': 'test_value_5',
|
||||
'cors-allow-origin': 'test_value_6',
|
||||
'name': 'default_name_7',
|
||||
'peer-auth': 'enable',
|
||||
'peer-group': 'test_value_9',
|
||||
'schedule': 'test_value_10',
|
||||
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'api-user', 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,263 @@
|
||||
# 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_system_central_management
|
||||
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_system_central_management.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_central_management_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',
|
||||
'system_central_management': {
|
||||
'allow_monitor': 'enable',
|
||||
'allow_push_configuration': 'enable',
|
||||
'allow_push_firmware': 'enable',
|
||||
'allow_remote_firmware_upgrade': 'enable',
|
||||
'enc_algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg_source_ip': 'test_value_9',
|
||||
'fmg_source_ip6': 'test_value_10',
|
||||
'include_default_servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule_config_restore': 'enable',
|
||||
'schedule_script_restore': 'enable',
|
||||
'serial_number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_central_management.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-monitor': 'enable',
|
||||
'allow-push-configuration': 'enable',
|
||||
'allow-push-firmware': 'enable',
|
||||
'allow-remote-firmware-upgrade': 'enable',
|
||||
'enc-algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg-source-ip': 'test_value_9',
|
||||
'fmg-source-ip6': 'test_value_10',
|
||||
'include-default-servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule-config-restore': 'enable',
|
||||
'schedule-script-restore': 'enable',
|
||||
'serial-number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'central-management', 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_system_central_management_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',
|
||||
'system_central_management': {
|
||||
'allow_monitor': 'enable',
|
||||
'allow_push_configuration': 'enable',
|
||||
'allow_push_firmware': 'enable',
|
||||
'allow_remote_firmware_upgrade': 'enable',
|
||||
'enc_algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg_source_ip': 'test_value_9',
|
||||
'fmg_source_ip6': 'test_value_10',
|
||||
'include_default_servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule_config_restore': 'enable',
|
||||
'schedule_script_restore': 'enable',
|
||||
'serial_number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_central_management.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-monitor': 'enable',
|
||||
'allow-push-configuration': 'enable',
|
||||
'allow-push-firmware': 'enable',
|
||||
'allow-remote-firmware-upgrade': 'enable',
|
||||
'enc-algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg-source-ip': 'test_value_9',
|
||||
'fmg-source-ip6': 'test_value_10',
|
||||
'include-default-servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule-config-restore': 'enable',
|
||||
'schedule-script-restore': 'enable',
|
||||
'serial-number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'central-management', 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_system_central_management_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',
|
||||
'system_central_management': {
|
||||
'allow_monitor': 'enable',
|
||||
'allow_push_configuration': 'enable',
|
||||
'allow_push_firmware': 'enable',
|
||||
'allow_remote_firmware_upgrade': 'enable',
|
||||
'enc_algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg_source_ip': 'test_value_9',
|
||||
'fmg_source_ip6': 'test_value_10',
|
||||
'include_default_servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule_config_restore': 'enable',
|
||||
'schedule_script_restore': 'enable',
|
||||
'serial_number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_central_management.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-monitor': 'enable',
|
||||
'allow-push-configuration': 'enable',
|
||||
'allow-push-firmware': 'enable',
|
||||
'allow-remote-firmware-upgrade': 'enable',
|
||||
'enc-algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg-source-ip': 'test_value_9',
|
||||
'fmg-source-ip6': 'test_value_10',
|
||||
'include-default-servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule-config-restore': 'enable',
|
||||
'schedule-script-restore': 'enable',
|
||||
'serial-number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'central-management', 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_system_central_management_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',
|
||||
'system_central_management': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'allow_monitor': 'enable',
|
||||
'allow_push_configuration': 'enable',
|
||||
'allow_push_firmware': 'enable',
|
||||
'allow_remote_firmware_upgrade': 'enable',
|
||||
'enc_algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg_source_ip': 'test_value_9',
|
||||
'fmg_source_ip6': 'test_value_10',
|
||||
'include_default_servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule_config_restore': 'enable',
|
||||
'schedule_script_restore': 'enable',
|
||||
'serial_number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_central_management.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'allow-monitor': 'enable',
|
||||
'allow-push-configuration': 'enable',
|
||||
'allow-push-firmware': 'enable',
|
||||
'allow-remote-firmware-upgrade': 'enable',
|
||||
'enc-algorithm': 'default',
|
||||
'fmg': 'test_value_8',
|
||||
'fmg-source-ip': 'test_value_9',
|
||||
'fmg-source-ip6': 'test_value_10',
|
||||
'include-default-servers': 'enable',
|
||||
'mode': 'normal',
|
||||
'schedule-config-restore': 'enable',
|
||||
'schedule-script-restore': 'enable',
|
||||
'serial-number': 'test_value_15',
|
||||
'type': 'fortimanager',
|
||||
'vdom': 'test_value_17'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'central-management', 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,589 @@
|
||||
# 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_system_dhcp_server
|
||||
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_system_dhcp_server.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_dhcp_server_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',
|
||||
'system_dhcp_server': {
|
||||
'auto_configuration': 'disable',
|
||||
'conflicted_ip_timeout': '4',
|
||||
'ddns_auth': 'disable',
|
||||
'ddns_key': 'test_value_6',
|
||||
'ddns_keyname': 'test_value_7',
|
||||
'ddns_server_ip': 'test_value_8',
|
||||
'ddns_ttl': '9',
|
||||
'ddns_update': 'disable',
|
||||
'ddns_update_override': 'disable',
|
||||
'ddns_zone': 'test_value_12',
|
||||
'default_gateway': 'test_value_13',
|
||||
'dns_server1': 'test_value_14',
|
||||
'dns_server2': 'test_value_15',
|
||||
'dns_server3': 'test_value_16',
|
||||
'dns_service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient_on_net_status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip_mode': 'range',
|
||||
'ipsec_lease_hold': '24',
|
||||
'lease_time': '25',
|
||||
'mac_acl_default_action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next_server': 'test_value_28',
|
||||
'ntp_server1': 'test_value_29',
|
||||
'ntp_server2': 'test_value_30',
|
||||
'ntp_server3': 'test_value_31',
|
||||
'ntp_service': 'local',
|
||||
'server_type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone_option': 'disable',
|
||||
'vci_match': 'disable',
|
||||
'wifi_ac1': 'test_value_38',
|
||||
'wifi_ac2': 'test_value_39',
|
||||
'wifi_ac3': 'test_value_40',
|
||||
'wins_server1': 'test_value_41',
|
||||
'wins_server2': 'test_value_42'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dhcp_server.fortios_system_dhcp(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auto-configuration': 'disable',
|
||||
'conflicted-ip-timeout': '4',
|
||||
'ddns-auth': 'disable',
|
||||
'ddns-key': 'test_value_6',
|
||||
'ddns-keyname': 'test_value_7',
|
||||
'ddns-server-ip': 'test_value_8',
|
||||
'ddns-ttl': '9',
|
||||
'ddns-update': 'disable',
|
||||
'ddns-update-override': 'disable',
|
||||
'ddns-zone': 'test_value_12',
|
||||
'default-gateway': 'test_value_13',
|
||||
'dns-server1': 'test_value_14',
|
||||
'dns-server2': 'test_value_15',
|
||||
'dns-server3': 'test_value_16',
|
||||
'dns-service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient-on-net-status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip-mode': 'range',
|
||||
'ipsec-lease-hold': '24',
|
||||
'lease-time': '25',
|
||||
'mac-acl-default-action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next-server': 'test_value_28',
|
||||
'ntp-server1': 'test_value_29',
|
||||
'ntp-server2': 'test_value_30',
|
||||
'ntp-server3': 'test_value_31',
|
||||
'ntp-service': 'local',
|
||||
'server-type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone-option': 'disable',
|
||||
'vci-match': 'disable',
|
||||
'wifi-ac1': 'test_value_38',
|
||||
'wifi-ac2': 'test_value_39',
|
||||
'wifi-ac3': 'test_value_40',
|
||||
'wins-server1': 'test_value_41',
|
||||
'wins-server2': 'test_value_42'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system.dhcp', 'server', 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_system_dhcp_server_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',
|
||||
'system_dhcp_server': {
|
||||
'auto_configuration': 'disable',
|
||||
'conflicted_ip_timeout': '4',
|
||||
'ddns_auth': 'disable',
|
||||
'ddns_key': 'test_value_6',
|
||||
'ddns_keyname': 'test_value_7',
|
||||
'ddns_server_ip': 'test_value_8',
|
||||
'ddns_ttl': '9',
|
||||
'ddns_update': 'disable',
|
||||
'ddns_update_override': 'disable',
|
||||
'ddns_zone': 'test_value_12',
|
||||
'default_gateway': 'test_value_13',
|
||||
'dns_server1': 'test_value_14',
|
||||
'dns_server2': 'test_value_15',
|
||||
'dns_server3': 'test_value_16',
|
||||
'dns_service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient_on_net_status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip_mode': 'range',
|
||||
'ipsec_lease_hold': '24',
|
||||
'lease_time': '25',
|
||||
'mac_acl_default_action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next_server': 'test_value_28',
|
||||
'ntp_server1': 'test_value_29',
|
||||
'ntp_server2': 'test_value_30',
|
||||
'ntp_server3': 'test_value_31',
|
||||
'ntp_service': 'local',
|
||||
'server_type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone_option': 'disable',
|
||||
'vci_match': 'disable',
|
||||
'wifi_ac1': 'test_value_38',
|
||||
'wifi_ac2': 'test_value_39',
|
||||
'wifi_ac3': 'test_value_40',
|
||||
'wins_server1': 'test_value_41',
|
||||
'wins_server2': 'test_value_42'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dhcp_server.fortios_system_dhcp(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auto-configuration': 'disable',
|
||||
'conflicted-ip-timeout': '4',
|
||||
'ddns-auth': 'disable',
|
||||
'ddns-key': 'test_value_6',
|
||||
'ddns-keyname': 'test_value_7',
|
||||
'ddns-server-ip': 'test_value_8',
|
||||
'ddns-ttl': '9',
|
||||
'ddns-update': 'disable',
|
||||
'ddns-update-override': 'disable',
|
||||
'ddns-zone': 'test_value_12',
|
||||
'default-gateway': 'test_value_13',
|
||||
'dns-server1': 'test_value_14',
|
||||
'dns-server2': 'test_value_15',
|
||||
'dns-server3': 'test_value_16',
|
||||
'dns-service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient-on-net-status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip-mode': 'range',
|
||||
'ipsec-lease-hold': '24',
|
||||
'lease-time': '25',
|
||||
'mac-acl-default-action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next-server': 'test_value_28',
|
||||
'ntp-server1': 'test_value_29',
|
||||
'ntp-server2': 'test_value_30',
|
||||
'ntp-server3': 'test_value_31',
|
||||
'ntp-service': 'local',
|
||||
'server-type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone-option': 'disable',
|
||||
'vci-match': 'disable',
|
||||
'wifi-ac1': 'test_value_38',
|
||||
'wifi-ac2': 'test_value_39',
|
||||
'wifi-ac3': 'test_value_40',
|
||||
'wins-server1': 'test_value_41',
|
||||
'wins-server2': 'test_value_42'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system.dhcp', 'server', 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_system_dhcp_server_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',
|
||||
'system_dhcp_server': {
|
||||
'auto_configuration': 'disable',
|
||||
'conflicted_ip_timeout': '4',
|
||||
'ddns_auth': 'disable',
|
||||
'ddns_key': 'test_value_6',
|
||||
'ddns_keyname': 'test_value_7',
|
||||
'ddns_server_ip': 'test_value_8',
|
||||
'ddns_ttl': '9',
|
||||
'ddns_update': 'disable',
|
||||
'ddns_update_override': 'disable',
|
||||
'ddns_zone': 'test_value_12',
|
||||
'default_gateway': 'test_value_13',
|
||||
'dns_server1': 'test_value_14',
|
||||
'dns_server2': 'test_value_15',
|
||||
'dns_server3': 'test_value_16',
|
||||
'dns_service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient_on_net_status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip_mode': 'range',
|
||||
'ipsec_lease_hold': '24',
|
||||
'lease_time': '25',
|
||||
'mac_acl_default_action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next_server': 'test_value_28',
|
||||
'ntp_server1': 'test_value_29',
|
||||
'ntp_server2': 'test_value_30',
|
||||
'ntp_server3': 'test_value_31',
|
||||
'ntp_service': 'local',
|
||||
'server_type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone_option': 'disable',
|
||||
'vci_match': 'disable',
|
||||
'wifi_ac1': 'test_value_38',
|
||||
'wifi_ac2': 'test_value_39',
|
||||
'wifi_ac3': 'test_value_40',
|
||||
'wins_server1': 'test_value_41',
|
||||
'wins_server2': 'test_value_42'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dhcp_server.fortios_system_dhcp(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system.dhcp', 'server', 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_system_dhcp_server_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',
|
||||
'system_dhcp_server': {
|
||||
'auto_configuration': 'disable',
|
||||
'conflicted_ip_timeout': '4',
|
||||
'ddns_auth': 'disable',
|
||||
'ddns_key': 'test_value_6',
|
||||
'ddns_keyname': 'test_value_7',
|
||||
'ddns_server_ip': 'test_value_8',
|
||||
'ddns_ttl': '9',
|
||||
'ddns_update': 'disable',
|
||||
'ddns_update_override': 'disable',
|
||||
'ddns_zone': 'test_value_12',
|
||||
'default_gateway': 'test_value_13',
|
||||
'dns_server1': 'test_value_14',
|
||||
'dns_server2': 'test_value_15',
|
||||
'dns_server3': 'test_value_16',
|
||||
'dns_service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient_on_net_status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip_mode': 'range',
|
||||
'ipsec_lease_hold': '24',
|
||||
'lease_time': '25',
|
||||
'mac_acl_default_action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next_server': 'test_value_28',
|
||||
'ntp_server1': 'test_value_29',
|
||||
'ntp_server2': 'test_value_30',
|
||||
'ntp_server3': 'test_value_31',
|
||||
'ntp_service': 'local',
|
||||
'server_type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone_option': 'disable',
|
||||
'vci_match': 'disable',
|
||||
'wifi_ac1': 'test_value_38',
|
||||
'wifi_ac2': 'test_value_39',
|
||||
'wifi_ac3': 'test_value_40',
|
||||
'wins_server1': 'test_value_41',
|
||||
'wins_server2': 'test_value_42'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dhcp_server.fortios_system_dhcp(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system.dhcp', 'server', 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_system_dhcp_server_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',
|
||||
'system_dhcp_server': {
|
||||
'auto_configuration': 'disable',
|
||||
'conflicted_ip_timeout': '4',
|
||||
'ddns_auth': 'disable',
|
||||
'ddns_key': 'test_value_6',
|
||||
'ddns_keyname': 'test_value_7',
|
||||
'ddns_server_ip': 'test_value_8',
|
||||
'ddns_ttl': '9',
|
||||
'ddns_update': 'disable',
|
||||
'ddns_update_override': 'disable',
|
||||
'ddns_zone': 'test_value_12',
|
||||
'default_gateway': 'test_value_13',
|
||||
'dns_server1': 'test_value_14',
|
||||
'dns_server2': 'test_value_15',
|
||||
'dns_server3': 'test_value_16',
|
||||
'dns_service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient_on_net_status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip_mode': 'range',
|
||||
'ipsec_lease_hold': '24',
|
||||
'lease_time': '25',
|
||||
'mac_acl_default_action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next_server': 'test_value_28',
|
||||
'ntp_server1': 'test_value_29',
|
||||
'ntp_server2': 'test_value_30',
|
||||
'ntp_server3': 'test_value_31',
|
||||
'ntp_service': 'local',
|
||||
'server_type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone_option': 'disable',
|
||||
'vci_match': 'disable',
|
||||
'wifi_ac1': 'test_value_38',
|
||||
'wifi_ac2': 'test_value_39',
|
||||
'wifi_ac3': 'test_value_40',
|
||||
'wins_server1': 'test_value_41',
|
||||
'wins_server2': 'test_value_42'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dhcp_server.fortios_system_dhcp(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auto-configuration': 'disable',
|
||||
'conflicted-ip-timeout': '4',
|
||||
'ddns-auth': 'disable',
|
||||
'ddns-key': 'test_value_6',
|
||||
'ddns-keyname': 'test_value_7',
|
||||
'ddns-server-ip': 'test_value_8',
|
||||
'ddns-ttl': '9',
|
||||
'ddns-update': 'disable',
|
||||
'ddns-update-override': 'disable',
|
||||
'ddns-zone': 'test_value_12',
|
||||
'default-gateway': 'test_value_13',
|
||||
'dns-server1': 'test_value_14',
|
||||
'dns-server2': 'test_value_15',
|
||||
'dns-server3': 'test_value_16',
|
||||
'dns-service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient-on-net-status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip-mode': 'range',
|
||||
'ipsec-lease-hold': '24',
|
||||
'lease-time': '25',
|
||||
'mac-acl-default-action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next-server': 'test_value_28',
|
||||
'ntp-server1': 'test_value_29',
|
||||
'ntp-server2': 'test_value_30',
|
||||
'ntp-server3': 'test_value_31',
|
||||
'ntp-service': 'local',
|
||||
'server-type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone-option': 'disable',
|
||||
'vci-match': 'disable',
|
||||
'wifi-ac1': 'test_value_38',
|
||||
'wifi-ac2': 'test_value_39',
|
||||
'wifi-ac3': 'test_value_40',
|
||||
'wins-server1': 'test_value_41',
|
||||
'wins-server2': 'test_value_42'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system.dhcp', 'server', 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_system_dhcp_server_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',
|
||||
'system_dhcp_server': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'auto_configuration': 'disable',
|
||||
'conflicted_ip_timeout': '4',
|
||||
'ddns_auth': 'disable',
|
||||
'ddns_key': 'test_value_6',
|
||||
'ddns_keyname': 'test_value_7',
|
||||
'ddns_server_ip': 'test_value_8',
|
||||
'ddns_ttl': '9',
|
||||
'ddns_update': 'disable',
|
||||
'ddns_update_override': 'disable',
|
||||
'ddns_zone': 'test_value_12',
|
||||
'default_gateway': 'test_value_13',
|
||||
'dns_server1': 'test_value_14',
|
||||
'dns_server2': 'test_value_15',
|
||||
'dns_server3': 'test_value_16',
|
||||
'dns_service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient_on_net_status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip_mode': 'range',
|
||||
'ipsec_lease_hold': '24',
|
||||
'lease_time': '25',
|
||||
'mac_acl_default_action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next_server': 'test_value_28',
|
||||
'ntp_server1': 'test_value_29',
|
||||
'ntp_server2': 'test_value_30',
|
||||
'ntp_server3': 'test_value_31',
|
||||
'ntp_service': 'local',
|
||||
'server_type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone_option': 'disable',
|
||||
'vci_match': 'disable',
|
||||
'wifi_ac1': 'test_value_38',
|
||||
'wifi_ac2': 'test_value_39',
|
||||
'wifi_ac3': 'test_value_40',
|
||||
'wins_server1': 'test_value_41',
|
||||
'wins_server2': 'test_value_42'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dhcp_server.fortios_system_dhcp(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'auto-configuration': 'disable',
|
||||
'conflicted-ip-timeout': '4',
|
||||
'ddns-auth': 'disable',
|
||||
'ddns-key': 'test_value_6',
|
||||
'ddns-keyname': 'test_value_7',
|
||||
'ddns-server-ip': 'test_value_8',
|
||||
'ddns-ttl': '9',
|
||||
'ddns-update': 'disable',
|
||||
'ddns-update-override': 'disable',
|
||||
'ddns-zone': 'test_value_12',
|
||||
'default-gateway': 'test_value_13',
|
||||
'dns-server1': 'test_value_14',
|
||||
'dns-server2': 'test_value_15',
|
||||
'dns-server3': 'test_value_16',
|
||||
'dns-service': 'local',
|
||||
'domain': 'test_value_18',
|
||||
'filename': 'test_value_19',
|
||||
'forticlient-on-net-status': 'disable',
|
||||
'id': '21',
|
||||
'interface': 'test_value_22',
|
||||
'ip-mode': 'range',
|
||||
'ipsec-lease-hold': '24',
|
||||
'lease-time': '25',
|
||||
'mac-acl-default-action': 'assign',
|
||||
'netmask': 'test_value_27',
|
||||
'next-server': 'test_value_28',
|
||||
'ntp-server1': 'test_value_29',
|
||||
'ntp-server2': 'test_value_30',
|
||||
'ntp-server3': 'test_value_31',
|
||||
'ntp-service': 'local',
|
||||
'server-type': 'regular',
|
||||
'status': 'disable',
|
||||
'timezone': '01',
|
||||
'timezone-option': 'disable',
|
||||
'vci-match': 'disable',
|
||||
'wifi-ac1': 'test_value_38',
|
||||
'wifi-ac2': 'test_value_39',
|
||||
'wifi-ac3': 'test_value_40',
|
||||
'wins-server1': 'test_value_41',
|
||||
'wins-server2': 'test_value_42'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system.dhcp', 'server', 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,223 @@
|
||||
# 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_system_dns
|
||||
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_system_dns.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_dns_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',
|
||||
'system_dns': {
|
||||
'cache_notfound_responses': 'disable',
|
||||
'dns_cache_limit': '4',
|
||||
'dns_cache_ttl': '5',
|
||||
'ip6_primary': 'test_value_6',
|
||||
'ip6_secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source_ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dns.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-notfound-responses': 'disable',
|
||||
'dns-cache-limit': '4',
|
||||
'dns-cache-ttl': '5',
|
||||
'ip6-primary': 'test_value_6',
|
||||
'ip6-secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source-ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'dns', 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_system_dns_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',
|
||||
'system_dns': {
|
||||
'cache_notfound_responses': 'disable',
|
||||
'dns_cache_limit': '4',
|
||||
'dns_cache_ttl': '5',
|
||||
'ip6_primary': 'test_value_6',
|
||||
'ip6_secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source_ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dns.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-notfound-responses': 'disable',
|
||||
'dns-cache-limit': '4',
|
||||
'dns-cache-ttl': '5',
|
||||
'ip6-primary': 'test_value_6',
|
||||
'ip6-secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source-ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'dns', 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_system_dns_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',
|
||||
'system_dns': {
|
||||
'cache_notfound_responses': 'disable',
|
||||
'dns_cache_limit': '4',
|
||||
'dns_cache_ttl': '5',
|
||||
'ip6_primary': 'test_value_6',
|
||||
'ip6_secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source_ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dns.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-notfound-responses': 'disable',
|
||||
'dns-cache-limit': '4',
|
||||
'dns-cache-ttl': '5',
|
||||
'ip6-primary': 'test_value_6',
|
||||
'ip6-secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source-ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'dns', 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_system_dns_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',
|
||||
'system_dns': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'cache_notfound_responses': 'disable',
|
||||
'dns_cache_limit': '4',
|
||||
'dns_cache_ttl': '5',
|
||||
'ip6_primary': 'test_value_6',
|
||||
'ip6_secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source_ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_dns.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'cache-notfound-responses': 'disable',
|
||||
'dns-cache-limit': '4',
|
||||
'dns-cache-ttl': '5',
|
||||
'ip6-primary': 'test_value_6',
|
||||
'ip6-secondary': 'test_value_7',
|
||||
'primary': 'test_value_8',
|
||||
'retry': '9',
|
||||
'secondary': 'test_value_10',
|
||||
'source-ip': '84.230.14.11',
|
||||
'timeout': '12'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'dns', data=expected_data, vdom='root')
|
||||
schema_method_mock.assert_not_called()
|
||||
assert not is_error
|
||||
assert changed
|
||||
assert response['status'] == 'success'
|
||||
assert response['http_status'] == 200
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,489 @@
|
||||
# Copyright 2019 Fortinet, Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from mock import ANY
|
||||
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortios import fortios_system_sdn_connector
|
||||
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_system_sdn_connector.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_sdn_connector_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',
|
||||
'system_sdn_connector': {
|
||||
'access_key': 'test_value_3',
|
||||
'azure_region': 'global',
|
||||
'client_id': 'test_value_5',
|
||||
'client_secret': 'test_value_6',
|
||||
'compartment_id': 'test_value_7',
|
||||
'gcp_project': 'test_value_8',
|
||||
'key_passwd': 'test_value_9',
|
||||
'login_endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci_cert': 'test_value_12',
|
||||
'oci_fingerprint': 'test_value_13',
|
||||
'oci_region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private_key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource_group': 'test_value_18',
|
||||
'resource_url': 'test_value_19',
|
||||
'secret_key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server_port': '22',
|
||||
'service_account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription_id': 'test_value_25',
|
||||
'tenant_id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update_interval': '28',
|
||||
'use_metadata_iam': 'disable',
|
||||
'user_id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc_id': 'test_value_32'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_sdn_connector.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'access-key': 'test_value_3',
|
||||
'azure-region': 'global',
|
||||
'client-id': 'test_value_5',
|
||||
'client-secret': 'test_value_6',
|
||||
'compartment-id': 'test_value_7',
|
||||
'gcp-project': 'test_value_8',
|
||||
'key-passwd': 'test_value_9',
|
||||
'login-endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci-cert': 'test_value_12',
|
||||
'oci-fingerprint': 'test_value_13',
|
||||
'oci-region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private-key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource-group': 'test_value_18',
|
||||
'resource-url': 'test_value_19',
|
||||
'secret-key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server-port': '22',
|
||||
'service-account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription-id': 'test_value_25',
|
||||
'tenant-id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update-interval': '28',
|
||||
'use-metadata-iam': 'disable',
|
||||
'user-id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc-id': 'test_value_32'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'sdn-connector', 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_system_sdn_connector_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',
|
||||
'system_sdn_connector': {
|
||||
'access_key': 'test_value_3',
|
||||
'azure_region': 'global',
|
||||
'client_id': 'test_value_5',
|
||||
'client_secret': 'test_value_6',
|
||||
'compartment_id': 'test_value_7',
|
||||
'gcp_project': 'test_value_8',
|
||||
'key_passwd': 'test_value_9',
|
||||
'login_endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci_cert': 'test_value_12',
|
||||
'oci_fingerprint': 'test_value_13',
|
||||
'oci_region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private_key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource_group': 'test_value_18',
|
||||
'resource_url': 'test_value_19',
|
||||
'secret_key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server_port': '22',
|
||||
'service_account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription_id': 'test_value_25',
|
||||
'tenant_id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update_interval': '28',
|
||||
'use_metadata_iam': 'disable',
|
||||
'user_id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc_id': 'test_value_32'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_sdn_connector.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'access-key': 'test_value_3',
|
||||
'azure-region': 'global',
|
||||
'client-id': 'test_value_5',
|
||||
'client-secret': 'test_value_6',
|
||||
'compartment-id': 'test_value_7',
|
||||
'gcp-project': 'test_value_8',
|
||||
'key-passwd': 'test_value_9',
|
||||
'login-endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci-cert': 'test_value_12',
|
||||
'oci-fingerprint': 'test_value_13',
|
||||
'oci-region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private-key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource-group': 'test_value_18',
|
||||
'resource-url': 'test_value_19',
|
||||
'secret-key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server-port': '22',
|
||||
'service-account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription-id': 'test_value_25',
|
||||
'tenant-id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update-interval': '28',
|
||||
'use-metadata-iam': 'disable',
|
||||
'user-id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc-id': 'test_value_32'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'sdn-connector', 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_system_sdn_connector_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',
|
||||
'system_sdn_connector': {
|
||||
'access_key': 'test_value_3',
|
||||
'azure_region': 'global',
|
||||
'client_id': 'test_value_5',
|
||||
'client_secret': 'test_value_6',
|
||||
'compartment_id': 'test_value_7',
|
||||
'gcp_project': 'test_value_8',
|
||||
'key_passwd': 'test_value_9',
|
||||
'login_endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci_cert': 'test_value_12',
|
||||
'oci_fingerprint': 'test_value_13',
|
||||
'oci_region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private_key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource_group': 'test_value_18',
|
||||
'resource_url': 'test_value_19',
|
||||
'secret_key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server_port': '22',
|
||||
'service_account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription_id': 'test_value_25',
|
||||
'tenant_id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update_interval': '28',
|
||||
'use_metadata_iam': 'disable',
|
||||
'user_id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc_id': 'test_value_32'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_sdn_connector.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'sdn-connector', 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_system_sdn_connector_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',
|
||||
'system_sdn_connector': {
|
||||
'access_key': 'test_value_3',
|
||||
'azure_region': 'global',
|
||||
'client_id': 'test_value_5',
|
||||
'client_secret': 'test_value_6',
|
||||
'compartment_id': 'test_value_7',
|
||||
'gcp_project': 'test_value_8',
|
||||
'key_passwd': 'test_value_9',
|
||||
'login_endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci_cert': 'test_value_12',
|
||||
'oci_fingerprint': 'test_value_13',
|
||||
'oci_region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private_key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource_group': 'test_value_18',
|
||||
'resource_url': 'test_value_19',
|
||||
'secret_key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server_port': '22',
|
||||
'service_account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription_id': 'test_value_25',
|
||||
'tenant_id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update_interval': '28',
|
||||
'use_metadata_iam': 'disable',
|
||||
'user_id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc_id': 'test_value_32'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_sdn_connector.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'sdn-connector', 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_system_sdn_connector_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',
|
||||
'system_sdn_connector': {
|
||||
'access_key': 'test_value_3',
|
||||
'azure_region': 'global',
|
||||
'client_id': 'test_value_5',
|
||||
'client_secret': 'test_value_6',
|
||||
'compartment_id': 'test_value_7',
|
||||
'gcp_project': 'test_value_8',
|
||||
'key_passwd': 'test_value_9',
|
||||
'login_endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci_cert': 'test_value_12',
|
||||
'oci_fingerprint': 'test_value_13',
|
||||
'oci_region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private_key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource_group': 'test_value_18',
|
||||
'resource_url': 'test_value_19',
|
||||
'secret_key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server_port': '22',
|
||||
'service_account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription_id': 'test_value_25',
|
||||
'tenant_id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update_interval': '28',
|
||||
'use_metadata_iam': 'disable',
|
||||
'user_id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc_id': 'test_value_32'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_sdn_connector.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'access-key': 'test_value_3',
|
||||
'azure-region': 'global',
|
||||
'client-id': 'test_value_5',
|
||||
'client-secret': 'test_value_6',
|
||||
'compartment-id': 'test_value_7',
|
||||
'gcp-project': 'test_value_8',
|
||||
'key-passwd': 'test_value_9',
|
||||
'login-endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci-cert': 'test_value_12',
|
||||
'oci-fingerprint': 'test_value_13',
|
||||
'oci-region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private-key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource-group': 'test_value_18',
|
||||
'resource-url': 'test_value_19',
|
||||
'secret-key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server-port': '22',
|
||||
'service-account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription-id': 'test_value_25',
|
||||
'tenant-id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update-interval': '28',
|
||||
'use-metadata-iam': 'disable',
|
||||
'user-id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc-id': 'test_value_32'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'sdn-connector', 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_system_sdn_connector_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',
|
||||
'system_sdn_connector': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'access_key': 'test_value_3',
|
||||
'azure_region': 'global',
|
||||
'client_id': 'test_value_5',
|
||||
'client_secret': 'test_value_6',
|
||||
'compartment_id': 'test_value_7',
|
||||
'gcp_project': 'test_value_8',
|
||||
'key_passwd': 'test_value_9',
|
||||
'login_endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci_cert': 'test_value_12',
|
||||
'oci_fingerprint': 'test_value_13',
|
||||
'oci_region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private_key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource_group': 'test_value_18',
|
||||
'resource_url': 'test_value_19',
|
||||
'secret_key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server_port': '22',
|
||||
'service_account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription_id': 'test_value_25',
|
||||
'tenant_id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update_interval': '28',
|
||||
'use_metadata_iam': 'disable',
|
||||
'user_id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc_id': 'test_value_32'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_sdn_connector.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'access-key': 'test_value_3',
|
||||
'azure-region': 'global',
|
||||
'client-id': 'test_value_5',
|
||||
'client-secret': 'test_value_6',
|
||||
'compartment-id': 'test_value_7',
|
||||
'gcp-project': 'test_value_8',
|
||||
'key-passwd': 'test_value_9',
|
||||
'login-endpoint': 'test_value_10',
|
||||
'name': 'default_name_11',
|
||||
'oci-cert': 'test_value_12',
|
||||
'oci-fingerprint': 'test_value_13',
|
||||
'oci-region': 'phoenix',
|
||||
'password': 'test_value_15',
|
||||
'private-key': 'test_value_16',
|
||||
'region': 'test_value_17',
|
||||
'resource-group': 'test_value_18',
|
||||
'resource-url': 'test_value_19',
|
||||
'secret-key': 'test_value_20',
|
||||
'server': '192.168.100.21',
|
||||
'server-port': '22',
|
||||
'service-account': 'test_value_23',
|
||||
'status': 'disable',
|
||||
'subscription-id': 'test_value_25',
|
||||
'tenant-id': 'test_value_26',
|
||||
'type': 'aci',
|
||||
'update-interval': '28',
|
||||
'use-metadata-iam': 'disable',
|
||||
'user-id': 'test_value_30',
|
||||
'username': 'test_value_31',
|
||||
'vpc-id': 'test_value_32'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'sdn-connector', 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_system_vdom
|
||||
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_system_vdom.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_vdom_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',
|
||||
'system_vdom': {
|
||||
'name': 'default_name_3',
|
||||
'short_name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster_id': '6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_vdom.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'name': 'default_name_3',
|
||||
'short-name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster-id': '6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'vdom', 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_system_vdom_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',
|
||||
'system_vdom': {
|
||||
'name': 'default_name_3',
|
||||
'short_name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster_id': '6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_vdom.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'name': 'default_name_3',
|
||||
'short-name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster-id': '6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'vdom', 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_system_vdom_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',
|
||||
'system_vdom': {
|
||||
'name': 'default_name_3',
|
||||
'short_name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster_id': '6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_vdom.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'vdom', 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_system_vdom_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',
|
||||
'system_vdom': {
|
||||
'name': 'default_name_3',
|
||||
'short_name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster_id': '6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_vdom.fortios_system(input_data, fos_instance)
|
||||
|
||||
delete_method_mock.assert_called_with('system', 'vdom', 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_system_vdom_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',
|
||||
'system_vdom': {
|
||||
'name': 'default_name_3',
|
||||
'short_name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster_id': '6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_vdom.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'name': 'default_name_3',
|
||||
'short-name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster-id': '6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'vdom', 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_system_vdom_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',
|
||||
'system_vdom': {
|
||||
'random_attribute_not_valid': 'tag',
|
||||
'name': 'default_name_3',
|
||||
'short_name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster_id': '6'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_vdom.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {
|
||||
'name': 'default_name_3',
|
||||
'short-name': 'test_value_4',
|
||||
'temporary': '5',
|
||||
'vcluster-id': '6'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'vdom', 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_system_virtual_wan_link
|
||||
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_system_virtual_wan_link.Connection')
|
||||
return connection_class_mock
|
||||
|
||||
|
||||
fos_instance = FortiOSHandler(connection_mock)
|
||||
|
||||
|
||||
def test_system_virtual_wan_link_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',
|
||||
'system_virtual_wan_link': {'fail_detect': 'enable',
|
||||
'load_balance_mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_virtual_wan_link.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {'fail-detect': 'enable',
|
||||
'load-balance-mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'virtual-wan-link', 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_system_virtual_wan_link_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',
|
||||
'system_virtual_wan_link': {'fail_detect': 'enable',
|
||||
'load_balance_mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_virtual_wan_link.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {'fail-detect': 'enable',
|
||||
'load-balance-mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'virtual-wan-link', 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_system_virtual_wan_link_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',
|
||||
'system_virtual_wan_link': {'fail_detect': 'enable',
|
||||
'load_balance_mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_virtual_wan_link.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {'fail-detect': 'enable',
|
||||
'load-balance-mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'virtual-wan-link', 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_system_virtual_wan_link_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',
|
||||
'system_virtual_wan_link': {
|
||||
'random_attribute_not_valid': 'tag', 'fail_detect': 'enable',
|
||||
'load_balance_mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
},
|
||||
'vdom': 'root'}
|
||||
|
||||
is_error, changed, response = fortios_system_virtual_wan_link.fortios_system(input_data, fos_instance)
|
||||
|
||||
expected_data = {'fail-detect': 'enable',
|
||||
'load-balance-mode': 'source-ip-based',
|
||||
'status': 'disable'
|
||||
}
|
||||
|
||||
set_method_mock.assert_called_with('system', 'virtual-wan-link', 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