mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
Redirect and Remove sap modules (#5592)
* redirect and remove sap modules * remove botmeta redirect * add changelog fragment * revert runtime.yml changes and add new entries * Update meta/runtime.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/5592-redirect-remove-sap-modules.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/5592-redirect-remove-sap-modules.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update 5592-redirect-remove-sap-modules.yml Fix indentation * Fix RST syntax. * Update meta/runtime.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update meta/runtime.yml Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
a3b748a15e
commit
b1094d840f
9 changed files with 19 additions and 1032 deletions
|
@ -1,103 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2021, Rainer Leber (@rainerleber) <rainerleber@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.plugins.modules import hana_query
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import (
|
||||
AnsibleExitJson,
|
||||
AnsibleFailJson,
|
||||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible.module_utils import basic
|
||||
|
||||
|
||||
def get_bin_path(*args, **kwargs):
|
||||
"""Function to return path of hdbsql"""
|
||||
return "/usr/sap/HDB/HDB01/exe/hdbsql"
|
||||
|
||||
|
||||
class Testhana_query(ModuleTestCase):
|
||||
"""Main class for testing hana_query module."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup."""
|
||||
super(Testhana_query, self).setUp()
|
||||
self.module = hana_query
|
||||
self.mock_get_bin_path = patch.object(basic.AnsibleModule, 'get_bin_path', get_bin_path)
|
||||
self.mock_get_bin_path.start()
|
||||
self.addCleanup(self.mock_get_bin_path.stop) # ensure that the patching is 'undone'
|
||||
|
||||
def tearDown(self):
|
||||
"""Teardown."""
|
||||
super(Testhana_query, self).tearDown()
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
"""Failure must occurs when all parameters are missing."""
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({})
|
||||
self.module.main()
|
||||
|
||||
def test_hana_query(self):
|
||||
"""Check that result is processed."""
|
||||
set_module_args({
|
||||
'sid': "HDB",
|
||||
'instance': "01",
|
||||
'encrypted': False,
|
||||
'host': "localhost",
|
||||
'user': "SYSTEM",
|
||||
'password': "1234Qwer",
|
||||
'database': "HDB",
|
||||
'query': "SELECT * FROM users;"
|
||||
})
|
||||
with patch.object(basic.AnsibleModule, 'run_command') as run_command:
|
||||
run_command.return_value = 0, 'username,name\n testuser,test user \n myuser, my user \n', ''
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
hana_query.main()
|
||||
self.assertEqual(result.exception.args[0]['query_result'], [[
|
||||
{'username': 'testuser', 'name': 'test user'},
|
||||
{'username': 'myuser', 'name': 'my user'},
|
||||
]])
|
||||
self.assertEqual(run_command.call_count, 1)
|
||||
|
||||
def test_hana_userstore_query(self):
|
||||
"""Check that result is processed with userstore."""
|
||||
set_module_args({
|
||||
'sid': "HDB",
|
||||
'instance': "01",
|
||||
'encrypted': False,
|
||||
'host': "localhost",
|
||||
'user': "SYSTEM",
|
||||
'userstore': True,
|
||||
'database': "HDB",
|
||||
'query': "SELECT * FROM users;"
|
||||
})
|
||||
with patch.object(basic.AnsibleModule, 'run_command') as run_command:
|
||||
run_command.return_value = 0, 'username,name\n testuser,test user \n myuser, my user \n', ''
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
hana_query.main()
|
||||
self.assertEqual(result.exception.args[0]['query_result'], [[
|
||||
{'username': 'testuser', 'name': 'test user'},
|
||||
{'username': 'myuser', 'name': 'my user'},
|
||||
]])
|
||||
self.assertEqual(run_command.call_count, 1)
|
||||
|
||||
def test_hana_failed_no_passwd(self):
|
||||
"""Check that result is failed with no password."""
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({
|
||||
'sid': "HDB",
|
||||
'instance': "01",
|
||||
'encrypted': False,
|
||||
'host': "localhost",
|
||||
'user': "SYSTEM",
|
||||
'database': "HDB",
|
||||
'query': "SELECT * FROM users;"
|
||||
})
|
||||
self.module.main()
|
|
@ -1,91 +0,0 @@
|
|||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import sys
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch, MagicMock
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
|
||||
|
||||
sys.modules['pyrfc'] = MagicMock()
|
||||
sys.modules['pyrfc.Connection'] = MagicMock()
|
||||
sys.modules['xmltodict'] = MagicMock()
|
||||
sys.modules['xmltodict.parse'] = MagicMock()
|
||||
|
||||
from ansible_collections.community.general.plugins.modules import sap_task_list_execute
|
||||
|
||||
|
||||
class TestSAPRfcModule(ModuleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSAPRfcModule, self).setUp()
|
||||
self.module = sap_task_list_execute
|
||||
|
||||
def tearDown(self):
|
||||
super(TestSAPRfcModule, self).tearDown()
|
||||
|
||||
def define_rfc_connect(self, mocker):
|
||||
return mocker.patch(self.module.call_rfc_method)
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
"""Failure must occurs when all parameters are missing"""
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({})
|
||||
self.module.main()
|
||||
|
||||
def test_error_no_task_list(self):
|
||||
"""tests fail to exec task list"""
|
||||
|
||||
set_module_args({
|
||||
"conn_username": "DDIC",
|
||||
"conn_password": "Test1234",
|
||||
"host": "10.1.8.9",
|
||||
"task_to_execute": "SAP_BASIS_SSL_CHECK"
|
||||
})
|
||||
|
||||
with patch.object(self.module, 'Connection') as conn:
|
||||
conn.return_value = ''
|
||||
with self.assertRaises(AnsibleFailJson) as result:
|
||||
self.module.main()
|
||||
self.assertEqual(result.exception.args[0]['msg'], 'The task list does not exsist.')
|
||||
|
||||
def test_success(self):
|
||||
"""test execute task list success"""
|
||||
|
||||
set_module_args({
|
||||
"conn_username": "DDIC",
|
||||
"conn_password": "Test1234",
|
||||
"host": "10.1.8.9",
|
||||
"task_to_execute": "SAP_BASIS_SSL_CHECK"
|
||||
})
|
||||
with patch.object(self.module, 'xml_to_dict') as XML:
|
||||
XML.return_value = {'item': [{'TASK': {'CHECK_STATUS_DESCR': 'Check successfully',
|
||||
'STATUS_DESCR': 'Executed successfully', 'TASKNAME': 'CL_STCT_CHECK_SEC_CRYPTO',
|
||||
'LNR': '1', 'DESCRIPTION': 'Check SAP Cryptographic Library', 'DOCU_EXIST': 'X',
|
||||
'LOG_EXIST': 'X', 'ACTION_SKIP': None, 'ACTION_UNSKIP': None, 'ACTION_CONFIRM': None,
|
||||
'ACTION_MAINTAIN': None}}]}
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
sap_task_list_execute.main()
|
||||
self.assertEqual(result.exception.args[0]['out'], {'item': [{'TASK': {'CHECK_STATUS_DESCR': 'Check successfully',
|
||||
'STATUS_DESCR': 'Executed successfully', 'TASKNAME': 'CL_STCT_CHECK_SEC_CRYPTO',
|
||||
'LNR': '1', 'DESCRIPTION': 'Check SAP Cryptographic Library', 'DOCU_EXIST': 'X',
|
||||
'LOG_EXIST': 'X', 'ACTION_SKIP': None, 'ACTION_UNSKIP': None,
|
||||
'ACTION_CONFIRM': None, 'ACTION_MAINTAIN': None}}]})
|
||||
|
||||
def test_success_no_log(self):
|
||||
"""test execute task list success without logs"""
|
||||
|
||||
set_module_args({
|
||||
"conn_username": "DDIC",
|
||||
"conn_password": "Test1234",
|
||||
"host": "10.1.8.9",
|
||||
"task_to_execute": "SAP_BASIS_SSL_CHECK"
|
||||
})
|
||||
with patch.object(self.module, 'xml_to_dict') as XML:
|
||||
XML.return_value = "No logs available."
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
sap_task_list_execute.main()
|
||||
self.assertEqual(result.exception.args[0]['out'], 'No logs available.')
|
|
@ -1,54 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2021, Rainer Leber (@rainerleber) <rainerleber@gmail.com>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.plugins.modules import sapcar_extract
|
||||
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
|
||||
from ansible_collections.community.general.tests.unit.compat.mock import patch
|
||||
from ansible.module_utils import basic
|
||||
|
||||
|
||||
def get_bin_path(*args, **kwargs):
|
||||
"""Function to return path of SAPCAR"""
|
||||
return "/tmp/sapcar"
|
||||
|
||||
|
||||
class Testsapcar_extract(ModuleTestCase):
|
||||
"""Main class for testing sapcar_extract module."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup."""
|
||||
super(Testsapcar_extract, self).setUp()
|
||||
self.module = sapcar_extract
|
||||
self.mock_get_bin_path = patch.object(basic.AnsibleModule, 'get_bin_path', get_bin_path)
|
||||
self.mock_get_bin_path.start()
|
||||
self.addCleanup(self.mock_get_bin_path.stop) # ensure that the patching is 'undone'
|
||||
|
||||
def tearDown(self):
|
||||
"""Teardown."""
|
||||
super(Testsapcar_extract, self).tearDown()
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
"""Failure must occurs when all parameters are missing."""
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
set_module_args({})
|
||||
self.module.main()
|
||||
|
||||
def test_sapcar_extract(self):
|
||||
"""Check that result is changed."""
|
||||
set_module_args({
|
||||
'path': "/tmp/HANA_CLIENT_REV2_00_053_00_LINUX_X86_64.SAR",
|
||||
'dest': "/tmp/test2",
|
||||
'binary_path': "/tmp/sapcar"
|
||||
})
|
||||
with patch.object(basic.AnsibleModule, 'run_command') as run_command:
|
||||
run_command.return_value = 0, '', '' # successful execution, no output
|
||||
with self.assertRaises(AnsibleExitJson) as result:
|
||||
sapcar_extract.main()
|
||||
self.assertTrue(result.exception.args[0]['changed'])
|
||||
self.assertEqual(run_command.call_count, 1)
|
Loading…
Add table
Add a link
Reference in a new issue