mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-16 09:55:26 -07:00
updates iosxr modules to support socket (#21231)
* updates all iosxr modules to support persistent socket * adds iosxr action plugin to connect to device * adds exec_command() to iosxr shared module * fixes iosxr_config and iosxr_template local action * update all unit test cases * adds base test module for iosxr module testing
This commit is contained in:
parent
635e3fe9ee
commit
eb1453a366
17 changed files with 466 additions and 623 deletions
|
@ -19,43 +19,16 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import patch, MagicMock
|
||||
from ansible.errors import AnsibleModuleExit
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.iosxr import iosxr_command
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
def set_module_args(args):
|
||||
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
|
||||
basic._ANSIBLE_ARGS = to_bytes(args)
|
||||
class TestIosxrCommandModule(TestIosxrModule):
|
||||
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
fixture_data = {}
|
||||
|
||||
def load_fixture(name):
|
||||
path = os.path.join(fixture_path, name)
|
||||
|
||||
if path in fixture_data:
|
||||
return fixture_data[path]
|
||||
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
|
||||
try:
|
||||
data = json.loads(data)
|
||||
except:
|
||||
pass
|
||||
|
||||
fixture_data[path] = data
|
||||
return data
|
||||
|
||||
|
||||
class TestIosxrCommandModule(unittest.TestCase):
|
||||
module = iosxr_command
|
||||
|
||||
def setUp(self):
|
||||
self.mock_run_commands = patch('ansible.modules.network.iosxr.iosxr_command.run_commands')
|
||||
|
@ -64,7 +37,7 @@ class TestIosxrCommandModule(unittest.TestCase):
|
|||
def tearDown(self):
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def execute_module(self, failed=False, changed=False):
|
||||
def load_fixtures(self, commands=None):
|
||||
|
||||
def load_from_file(*args, **kwargs):
|
||||
module, commands = args
|
||||
|
@ -82,18 +55,6 @@ class TestIosxrCommandModule(unittest.TestCase):
|
|||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
with self.assertRaises(AnsibleModuleExit) as exc:
|
||||
iosxr_command.main()
|
||||
|
||||
result = exc.exception.result
|
||||
|
||||
if failed:
|
||||
self.assertTrue(result.get('failed'))
|
||||
else:
|
||||
self.assertEqual(result.get('changed'), changed, result)
|
||||
|
||||
return result
|
||||
|
||||
def test_iosxr_command_simple(self):
|
||||
set_module_args(dict(commands=['show version']))
|
||||
result = self.execute_module()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue