mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
5b1a8ee1e8
* Adding slx_command module and supporting module_utils. This commit adds the slx_command module and tests as well as the required slxos module_utils. * Update copyright in header * Adding missing module init * Cleaning up shebangs/licensing. * Incorporating feedback Removing reference to `waitfor` alias in `slxos_command` module. Adding `Extreme Networks` to `short_description` of `slxos_command` module. * Adding cliconf tests * Fixing 3.X tests * Adding docstrings to test methods for slxos cliconf tests * Adding slxos terminal tests * Adding slxos module_utils tests * Adding Extreme Networks team members to BOTMETA.yml
131 lines
4.1 KiB
Python
131 lines
4.1 KiB
Python
#
|
|
# (c) 2018 Extreme Networks 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/>.
|
|
#
|
|
from __future__ import (absolute_import, division, print_function)
|
|
__metaclass__ = type
|
|
|
|
from os import path
|
|
import json
|
|
|
|
from mock import MagicMock, patch, call
|
|
|
|
from ansible.compat.tests import unittest
|
|
from ansible.module_utils.network.slxos import slxos
|
|
|
|
|
|
class TestPluginCLIConfSLXOS(unittest.TestCase):
|
|
""" Test class for SLX-OS CLI Conf Methods
|
|
"""
|
|
|
|
def test_get_connection_established(self):
|
|
""" Test get_connection with established connection
|
|
"""
|
|
module = MagicMock()
|
|
connection = slxos.get_connection(module)
|
|
self.assertEqual(connection, module.slxos_connection)
|
|
|
|
@patch('ansible.module_utils.network.slxos.slxos.Connection')
|
|
def test_get_connection_new(self, connection):
|
|
""" Test get_connection with new connection
|
|
"""
|
|
socket_path = "little red riding hood"
|
|
module = MagicMock(spec=[
|
|
'fail_json',
|
|
])
|
|
module._socket_path = socket_path
|
|
|
|
connection().get_capabilities.return_value = '{"network_api": "cliconf"}'
|
|
returned_connection = slxos.get_connection(module)
|
|
connection.assert_called_with(socket_path)
|
|
self.assertEqual(returned_connection, module.slxos_connection)
|
|
|
|
@patch('ansible.module_utils.network.slxos.slxos.Connection')
|
|
def test_get_connection_incorrect_network_api(self, connection):
|
|
""" Test get_connection with incorrect network_api response
|
|
"""
|
|
socket_path = "little red riding hood"
|
|
module = MagicMock(spec=[
|
|
'fail_json',
|
|
])
|
|
module._socket_path = socket_path
|
|
module.fail_json.side_effect = TypeError
|
|
|
|
connection().get_capabilities.return_value = '{"network_api": "nope"}'
|
|
|
|
with self.assertRaises(TypeError):
|
|
slxos.get_connection(module)
|
|
|
|
@patch('ansible.module_utils.network.slxos.slxos.Connection')
|
|
def test_get_capabilities(self, connection):
|
|
""" Test get_capabilities
|
|
"""
|
|
socket_path = "little red riding hood"
|
|
module = MagicMock(spec=[
|
|
'fail_json',
|
|
])
|
|
module._socket_path = socket_path
|
|
module.fail_json.side_effect = TypeError
|
|
|
|
capabilities = {'network_api': 'cliconf'}
|
|
|
|
connection().get_capabilities.return_value = json.dumps(capabilities)
|
|
|
|
capabilities_returned = slxos.get_capabilities(module)
|
|
|
|
self.assertEqual(capabilities, capabilities_returned)
|
|
|
|
@patch('ansible.module_utils.network.slxos.slxos.Connection')
|
|
def test_run_commands(self, connection):
|
|
""" Test get_capabilities
|
|
"""
|
|
module = MagicMock()
|
|
|
|
commands = [
|
|
'hello',
|
|
'dolly',
|
|
'well hello',
|
|
'dolly',
|
|
'its so nice to have you back',
|
|
'where you belong',
|
|
]
|
|
|
|
responses = [
|
|
'Dolly, never go away again1',
|
|
'Dolly, never go away again2',
|
|
'Dolly, never go away again3',
|
|
'Dolly, never go away again4',
|
|
'Dolly, never go away again5',
|
|
'Dolly, never go away again6',
|
|
]
|
|
|
|
module.slxos_connection.get.side_effect = responses
|
|
|
|
run_command_responses = slxos.run_commands(module, commands)
|
|
|
|
calls = []
|
|
|
|
for command in commands:
|
|
calls.append(call(
|
|
command,
|
|
None,
|
|
None
|
|
))
|
|
|
|
module.slxos_connection.get.assert_has_calls(calls)
|
|
|
|
self.assertEqual(responses, run_command_responses)
|