mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Fortinet FortiManager Scripting Module (#34518)
* Adding new code for new module and new module_utils with the pip pyfmg package * Changed login and logout functionality and renamed mod_utils file as well as cleaned up PEP8 syntax * Removing extra Ansible parameters and fixing more syntax issues * Fixing more syntax issues and comparing against previous FTNT script module * Changing import location to pass syntax checks * Fixing pylint errors * Removing test files * Add unit tests and enabling a login session check within main in order to throw error if network connection exception * Fixing syntax issues for adding unit tests * Changing case for pip package requirements * adding comments * adding version restriction on pip package for testing * adding version restriction on pip package for testing * More comments * Fixing documentation errors and add the ability to skip a test if it isn't present * Fixing Pep8 error with whitespace (tab) in the row
This commit is contained in:
parent
d32c4ab62e
commit
60d2a8b6a1
8 changed files with 482 additions and 0 deletions
0
test/units/modules/network/fortimanager/__init__.py
Normal file
0
test/units/modules/network/fortimanager/__init__.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
# (c) 2016 Red Hat Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible 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.
|
||||
#
|
||||
# Ansible 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
|
||||
|
||||
|
||||
class TestFortimanagerModule(ModuleTestCase):
|
||||
|
||||
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
||||
|
||||
self.load_fixtures(commands)
|
||||
|
||||
if failed:
|
||||
result = self.failed()
|
||||
self.assertTrue(result['failed'], result)
|
||||
else:
|
||||
result = self.changed(changed)
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
|
||||
if commands is not None:
|
||||
if sort:
|
||||
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
|
||||
else:
|
||||
self.assertEqual(commands, result['commands'], result['commands'])
|
||||
|
||||
return result
|
||||
|
||||
def failed(self):
|
||||
with self.assertRaises(AnsibleFailJson) as exc:
|
||||
self.module.main()
|
||||
|
||||
result = exc.exception.args[0]
|
||||
self.assertTrue(result['failed'], result)
|
||||
return result
|
||||
|
||||
def changed(self, changed=False):
|
||||
with self.assertRaises(AnsibleExitJson) as exc:
|
||||
self.module.main()
|
||||
|
||||
result = exc.exception.args[0]
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
return result
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
pass
|
55
test/units/modules/network/fortimanager/test_fmgr_script.py
Normal file
55
test/units/modules/network/fortimanager/test_fmgr_script.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
# (c) 2016 Red Hat Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible 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.
|
||||
#
|
||||
# Ansible 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from nose.plugins.skip import SkipTest
|
||||
|
||||
try:
|
||||
from ansible.modules.network.fortimanager import fmgr_script
|
||||
from .fortimanager_module import TestFortimanagerModule
|
||||
from units.modules.utils import set_module_args
|
||||
except ImportError:
|
||||
raise SkipTest("Could not load required modules for testing")
|
||||
|
||||
|
||||
class TestFmgrScriptModule(TestFortimanagerModule):
|
||||
|
||||
module = fmgr_script
|
||||
|
||||
def test_fmg_script_fail_connect(self):
|
||||
set_module_args(dict(host='1.1.1.1', username='admin', password='admin', adom='root', script_name='TestScript',
|
||||
script_type='cli', script_target='remote_device', script_description='AnsibleTest',
|
||||
script_content='get system status'))
|
||||
result = self.execute_module(failed=True)
|
||||
self.assertEqual(result['msg'], 'Connection to FortiManager Failed')
|
||||
|
||||
def test_fmg_script_login_fail_host(self):
|
||||
set_module_args(dict(username='admin', password='admin', adom='root', script_name='TestScript',
|
||||
script_type='cli', script_target='remote_device', script_description='AnsibleTest',
|
||||
script_content='get system status'))
|
||||
result = self.execute_module(failed=True)
|
||||
self.assertEqual(result['msg'], 'missing required arguments: host')
|
||||
|
||||
def test_fmg_script_login_fail_username(self):
|
||||
set_module_args(dict(host='1.1.1.1', password='admin', adom='root', script_name='TestScript',
|
||||
script_type='cli', script_target='remote_device', script_description='AnsibleTest',
|
||||
script_content='get system status'))
|
||||
result = self.execute_module(failed=True)
|
||||
self.assertEqual(result['msg'], 'Host and username are required for connection')
|
Loading…
Add table
Add a link
Reference in a new issue