mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
revert others changes
This commit is contained in:
parent
27ea311e07
commit
fe2bbd3b3e
2 changed files with 52 additions and 1 deletions
|
@ -576,7 +576,10 @@ def send_config(
|
|||
config_commands = [line for line in file_str.splitlines() if line.strip()]
|
||||
kwargs = clean_kwargs(**kwargs)
|
||||
if "netmiko.conn" in __proxy__:
|
||||
conn = __proxy__["netmiko.conn"]()
|
||||
if __proxy__["netmiko.conn"]().is_alive():
|
||||
conn = __proxy__["netmiko.conn"]()
|
||||
else:
|
||||
conn, kwargs = _prepare_connection(**__proxy__["netmiko.args"]())
|
||||
else:
|
||||
conn, kwargs = _prepare_connection(**kwargs)
|
||||
if commit:
|
||||
|
|
48
tests/unit/modules/test_netmiko_mod.py
Normal file
48
tests/unit/modules/test_netmiko_mod.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import salt.modules.netmiko_mod as netmiko_mod
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
||||
class MockNetmikoConnection:
|
||||
def is_alive(self):
|
||||
return False
|
||||
|
||||
def send_config_set(self, *args, **kwargs):
|
||||
return args, kwargs
|
||||
|
||||
|
||||
def mock_netmiko_args():
|
||||
return {"user": "salt", "password": "password"}
|
||||
|
||||
|
||||
def mock_prepare_connection(**kwargs):
|
||||
return MockNetmikoConnection(), kwargs
|
||||
|
||||
|
||||
def mock_file_apply_template_on_contents(*args):
|
||||
return args[0]
|
||||
|
||||
|
||||
class NetmikoTestCase(TestCase, LoaderModuleMockMixin):
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
netmiko_mod: {
|
||||
"__salt__": {
|
||||
"file.apply_template_on_contents": mock_file_apply_template_on_contents
|
||||
},
|
||||
"__proxy__": {
|
||||
"netmiko.conn": MockNetmikoConnection,
|
||||
"netmiko.args": mock_netmiko_args,
|
||||
},
|
||||
"_prepare_connection": mock_prepare_connection,
|
||||
}
|
||||
}
|
||||
|
||||
def test_send_config(self):
|
||||
"""
|
||||
Test netmiko.send_config function
|
||||
"""
|
||||
_, ret = netmiko_mod.send_config(config_commands=["ls", "echo hello world"])
|
||||
self.assertEqual(ret.get("config_commands"), ["ls", "echo hello world"])
|
||||
self.assertEqual(ret.get("user"), "salt")
|
||||
self.assertEqual(ret.get("password"), "password")
|
Loading…
Add table
Reference in a new issue