-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import salt.proxy.junos as junos | ||
|
||
import sys | ||
|
||
# Import Salt Testing Libs | ||
from tests.support.mixins import LoaderModuleMockMixin | ||
from tests.support.mock import MagicMock, patch | ||
from tests.support.unit import TestCase, skipIf | ||
|
||
if sys.version < "3": | ||
from six import StringIO | ||
else: | ||
from io import BytesIO as StringIO | ||
|
||
try: | ||
from jnpr.junos.device import Device | ||
from jnpr.junos.exception import ConnectError | ||
import jxmlease # pylint: disable=unused-import | ||
from ncclient.transport.ssh import SSHSession | ||
from ncclient.devices.junos import JunosDeviceHandler | ||
|
||
HAS_JUNOS = True | ||
except ImportError: | ||
HAS_JUNOS = False | ||
|
||
|
||
@skipIf(not HAS_JUNOS, "The junos-eznc and jxmlease modules are required") | ||
class JunosProxyTestCase(TestCase, LoaderModuleMockMixin): | ||
def setup_loader_modules(self): | ||
return { | ||
junos: { | ||
"__virtual__": MagicMock(return_value="junos"), | ||
"DETAILS": {}, | ||
"__pillar__": {}, | ||
} | ||
} | ||
|
||
def setUp(self): | ||
self.opts = {"proxy": {"username": "xxxx", "password]": "xxx", "host": "junos"}} | ||
|
||
@patch("ncclient.manager.connect") | ||
def test_init(self, mock_connect): | ||
junos.init(self.opts) | ||
self.assertTrue(junos.thisproxy.get("initialized")) | ||
|
||
@patch("ncclient.manager.connect") | ||
def test_init_err(self, mock_connect): | ||
mock_connect.side_effect = ConnectError | ||
junos.init(self.opts) | ||
self.assertFalse(junos.thisproxy.get("initialized")) | ||
|
||
@patch("ncclient.manager.connect") | ||
def test_alive(self, mock_connect): | ||
junos.init(self.opts) | ||
junos.thisproxy["conn"]._conn._session._buffer = StringIO() | ||
self.assertTrue(junos.alive(self.opts)) | ||
self.assertTrue(junos.thisproxy.get("initialized")) |