New FortiManager Module: fmgr_fwobj_ippool (#53031)

* Auto Commit for: fmgr_fwobj_ippool

* Auto Commit for: fmgr_fwobj_ippool
This commit is contained in:
ftntcorecse
2019-03-04 05:39:56 -05:00
committed by Nilashish Chakraborty
parent 0e9bf838ff
commit 8888faf716
3 changed files with 925 additions and 0 deletions

View File

@@ -0,0 +1,388 @@
{
"fmgr_fwobj_ippool_modify": [
{
"paramgram_used": {
"source-endip": null,
"arp-intf": null,
"num-blocks-per-user": null,
"name": "Ansible_pool4_overload",
"adom": "ansible",
"startip": "10.10.10.10",
"dynamic_mapping": {
"endip": null,
"num-blocks-per-user": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"associated-interface": null,
"source-startip": null,
"permit-any-host": null,
"type": null
},
"comments": "Created by ansible",
"permit-any-host": null,
"arp-reply": "enable",
"pba-timeout": null,
"endip": "10.10.10.100",
"associated-interface": null,
"mode": "add",
"source-startip": null,
"type": "overload",
"block-size": null
},
"datagram_sent": {
"endip": "10.10.10.100",
"name": "Ansible_pool4_overload",
"startip": "10.10.10.10",
"comments": "Created by ansible",
"arp-reply": "enable",
"type": "overload"
},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool"
},
"post_method": "add"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool"
},
"datagram_sent": {
"endip": "10.10.20.100",
"name": "Ansible_pool4_121",
"startip": "10.10.20.10",
"comments": "Created by ansible",
"arp-reply": "enable",
"type": "one-to-one"
},
"paramgram_used": {
"permit-any-host": null,
"dynamic_mapping": {
"endip": null,
"num-blocks-per-user": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"associated-interface": null,
"source-startip": null,
"permit-any-host": null,
"type": null
},
"num-blocks-per-user": null,
"name": "Ansible_pool4_121",
"adom": "ansible",
"startip": "10.10.20.10",
"arp-intf": null,
"comments": "Created by ansible",
"source-endip": null,
"arp-reply": "enable",
"pba-timeout": null,
"endip": "10.10.20.100",
"associated-interface": null,
"mode": "add",
"source-startip": null,
"type": "one-to-one",
"block-size": null
},
"post_method": "add"
},
{
"paramgram_used": {
"source-endip": "192.168.20.20",
"arp-intf": null,
"num-blocks-per-user": null,
"name": "Ansible_pool4_fixed_port",
"adom": "ansible",
"startip": "10.10.40.10",
"dynamic_mapping": {
"endip": null,
"num-blocks-per-user": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"associated-interface": null,
"source-startip": null,
"permit-any-host": null,
"type": null
},
"comments": "Created by ansible",
"permit-any-host": null,
"arp-reply": "enable",
"pba-timeout": null,
"endip": "10.10.40.100",
"associated-interface": null,
"mode": "add",
"source-startip": "192.168.20.1",
"type": "fixed-port-range",
"block-size": null
},
"datagram_sent": {
"endip": "10.10.40.100",
"name": "Ansible_pool4_fixed_port",
"startip": "10.10.40.10",
"comments": "Created by ansible",
"source-endip": "192.168.20.20",
"arp-reply": "enable",
"source-startip": "192.168.20.1",
"type": "fixed-port-range"
},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool"
},
"post_method": "add"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool"
},
"datagram_sent": {
"endip": "10.10.30.100",
"num-blocks-per-user": 1,
"name": "Ansible_pool4_port_block_allocation",
"startip": "10.10.30.10",
"comments": "Created by ansible",
"arp-reply": "enable",
"type": "port-block-allocation",
"block-size": 128
},
"paramgram_used": {
"permit-any-host": null,
"dynamic_mapping": {
"endip": null,
"num-blocks-per-user": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"associated-interface": null,
"source-startip": null,
"permit-any-host": null,
"type": null
},
"num-blocks-per-user": 1,
"name": "Ansible_pool4_port_block_allocation",
"adom": "ansible",
"startip": "10.10.30.10",
"arp-intf": null,
"comments": "Created by ansible",
"source-endip": null,
"arp-reply": "enable",
"pba-timeout": null,
"endip": "10.10.30.100",
"associated-interface": null,
"mode": "add",
"source-startip": null,
"type": "port-block-allocation",
"block-size": 128
},
"post_method": "add"
},
{
"paramgram_used": {
"source-endip": null,
"arp-intf": null,
"num-blocks-per-user": null,
"name": "Ansible_pool4_overload",
"adom": "ansible",
"startip": null,
"dynamic_mapping": {
"endip": null,
"num-blocks-per-user": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"associated-interface": null,
"source-startip": null,
"permit-any-host": null,
"type": null
},
"comments": "Created by ansible",
"permit-any-host": null,
"arp-reply": null,
"pba-timeout": null,
"endip": null,
"associated-interface": null,
"mode": "delete",
"source-startip": null,
"type": null,
"block-size": null
},
"datagram_sent": {},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool/Ansible_pool4_overload"
},
"post_method": "delete"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool/Ansible_pool4_121"
},
"datagram_sent": {},
"paramgram_used": {
"permit-any-host": null,
"dynamic_mapping": {
"endip": null,
"num-blocks-per-user": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"associated-interface": null,
"source-startip": null,
"permit-any-host": null,
"type": null
},
"num-blocks-per-user": null,
"name": "Ansible_pool4_121",
"adom": "ansible",
"startip": null,
"arp-intf": null,
"comments": "Created by ansible",
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"endip": null,
"associated-interface": null,
"mode": "delete",
"source-startip": null,
"type": null,
"block-size": null
},
"post_method": "delete"
},
{
"paramgram_used": {
"source-endip": null,
"arp-intf": null,
"num-blocks-per-user": null,
"name": "Ansible_pool4_fixed_port",
"adom": "ansible",
"startip": null,
"dynamic_mapping": {
"endip": null,
"num-blocks-per-user": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"associated-interface": null,
"source-startip": null,
"permit-any-host": null,
"type": null
},
"comments": "Created by ansible",
"permit-any-host": null,
"arp-reply": null,
"pba-timeout": null,
"endip": null,
"associated-interface": null,
"mode": "delete",
"source-startip": null,
"type": null,
"block-size": null
},
"datagram_sent": {},
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool/Ansible_pool4_fixed_port"
},
"post_method": "delete"
},
{
"raw_response": {
"status": {
"message": "OK",
"code": 0
},
"url": "/pm/config/adom/ansible/obj/firewall/ippool/Ansible_pool4_port_block_allocation"
},
"datagram_sent": {},
"paramgram_used": {
"permit-any-host": null,
"dynamic_mapping": {
"num-blocks-per-user": null,
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"endip": null,
"block-size": null,
"startip": null,
"arp-intf": null,
"comments": null,
"permit-any-host": null,
"associated-interface": null,
"source-startip": null,
"type": null
},
"num-blocks-per-user": null,
"name": "Ansible_pool4_port_block_allocation",
"adom": "ansible",
"startip": null,
"arp-intf": null,
"comments": "Created by ansible",
"source-endip": null,
"arp-reply": null,
"pba-timeout": null,
"endip": null,
"associated-interface": null,
"mode": "delete",
"source-startip": null,
"type": null,
"block-size": null
},
"post_method": "delete"
}
]
}

View File

@@ -0,0 +1,90 @@
# Copyright 2018 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
from ansible.module_utils.network.fortimanager.fortimanager import FortiManagerHandler
import pytest
try:
from ansible.modules.network.fortimanager import fmgr_fwobj_ippool
except ImportError:
pytest.skip("Could not load required modules for testing", allow_module_level=True)
def load_fixtures():
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') + "/{filename}.json".format(
filename=os.path.splitext(os.path.basename(__file__))[0])
try:
with open(fixture_path, "r") as fixture_file:
fixture_data = json.load(fixture_file)
except IOError:
return []
return [fixture_data]
@pytest.fixture(autouse=True)
def module_mock(mocker):
connection_class_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule')
return connection_class_mock
@pytest.fixture(autouse=True)
def connection_mock(mocker):
connection_class_mock = mocker.patch('ansible.modules.network.fortimanager.fmgr_fwobj_ippool.Connection')
return connection_class_mock
@pytest.fixture(scope="function", params=load_fixtures())
def fixture_data(request):
func_name = request.function.__name__.replace("test_", "")
return request.param.get(func_name, None)
fmg_instance = FortiManagerHandler(connection_mock, module_mock)
def test_fmgr_fwobj_ippool_modify(fixture_data, mocker):
mocker.patch("ansible.module_utils.network.fortimanager.fortimanager.FortiManagerHandler.process_request",
side_effect=fixture_data)
# Test using fixture 1 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[0]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 2 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[1]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 3 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[2]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 4 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[3]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 5 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[4]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 6 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[5]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 7 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[6]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0
# Test using fixture 8 #
output = fmgr_fwobj_ippool.fmgr_fwobj_ippool_modify(fmg_instance, fixture_data[7]['paramgram_used'])
assert output['raw_response']['status']['code'] == 0