updates eos modules to use socket (#21197)

* updates eos modules to use persistent connection socket
* removes split eos shared module and combines into one
* adds singular eos doc frag (eos_local to be removed after module updates)
* updates unit test cases
This commit is contained in:
Peter Sprygada 2017-02-13 20:22:10 -05:00 committed by GitHub
parent 9937e604f5
commit 14b942f3fb
23 changed files with 837 additions and 1348 deletions

View file

@ -19,43 +19,15 @@
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.eos import eos_command
from ansible.module_utils import basic
from ansible.module_utils._text import to_bytes
from .eos_module import TestEosModule, load_fixture, set_module_args
class TestEosCommandModule(TestEosModule):
def set_module_args(args):
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
basic._ANSIBLE_ARGS = to_bytes(args)
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 test_EosCommandModule(unittest.TestCase):
module = eos_command
def setUp(self):
self.mock_run_commands = patch('ansible.modules.network.eos.eos_command.run_commands')
@ -64,8 +36,7 @@ class test_EosCommandModule(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
output = list()
@ -83,18 +54,6 @@ class test_EosCommandModule(unittest.TestCase):
self.run_commands.side_effect = load_from_file
with self.assertRaises(AnsibleModuleExit) as exc:
eos_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_eos_command_simple(self):
set_module_args(dict(commands=['show version']))
result = self.execute_module()