Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
vnitinv authored Aug 27, 2018
2 parents da95e03 + c351bb7 commit cce1a66
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
15 changes: 14 additions & 1 deletion lib/jnpr/junos/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,25 @@ def open(self, *vargs, **kvargs):
# ---------------------------------------------------------------
# validate device hostname or IP address
# ---------------------------------------------------------------
if ((self._mode and self._mode.upper() == 'TELNET') or self.cs_user is not None) and self._hostname is None:
if ((self._mode and self._mode.upper() == 'TELNET') or
self.cs_user is not None) and self._hostname is None:
self.results['failed'] = True
self.results[
'errmsg'] = 'ERROR: Device hostname/IP not specified !!!'
return self.results

# ---------------------------------------------------------------
# validate console server and password. Password-less connection
# is not supported
# ---------------------------------------------------------------
if self.cs_user is not None and self.cs_passwd is None:
self.results['failed'] = True
self.results[
'errmsg'] = 'ERROR: Console SSH, Password-less connection is ' \
'not supported !!!'
logger.error(self.results['errmsg'])
return self.results

# --------------------
# login to the CONSOLE
# --------------------
Expand Down
3 changes: 2 additions & 1 deletion lib/jnpr/junos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ def transform(self, func):
# -----------------------------------------------------------------------

def __new__(cls, *args, **kwargs):
if kwargs.get('port') in [23, '23'] or kwargs.get('mode'):
if kwargs.get('port') in [23, '23'] or kwargs.get('mode') or \
kwargs.get('cs_user') is not None:
from jnpr.junos.console import Console
instance = object.__new__(Console, *args, **kwargs)
# Python only calls __init__() if the object returned from
Expand Down
7 changes: 4 additions & 3 deletions lib/jnpr/junos/transport/tty_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SSH(Terminal):
RETRY_BACKOFF = 2 # seconds to wait between retries
MAX_BUFFER = 65535
READ_PROMPT_DELAY = 10.0
RECVSZ = 1024

def __init__(self, host, port, **kvargs):
"""
Expand Down Expand Up @@ -151,7 +152,7 @@ def read(self):
""" read a single line """
rxb = six.b('')
while True:
data = self._ssh.recv(1)
data = self._ssh.recv(self.RECVSZ)
if data is None or len(data) <= 0:
raise ValueError('Unable to detect device prompt')
elif PY6.NEW_LINE in data:
Expand All @@ -178,14 +179,14 @@ def read_prompt(self):
rd, _, _ = select.select([self._ssh], [], [], 0.1)
sleep(0.05)
if rd:
rxb += self._ssh.recv(1)
rxb += self._ssh.recv(self.RECVSZ)
found = _PROMPT.search(rxb)
if found is not None:
break
timeout = time() + self.READ_PROMPT_DELAY
else:
return None, None

logger.debug('Got: %s' % rxb)
return rxb, found.lastgroup

def _read_until(self, match, timeout=None):
Expand Down
33 changes: 13 additions & 20 deletions tests/unit/utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,22 +634,18 @@ def test_commit_configuration_multi_rpc_error(self):
self.dev.rpc.commit_configuration()
except Exception as ex:
self.assertTrue(isinstance(ex, RpcError))
if ncclient.__version__ > (0, 4, 5):
self.assertEqual(ex.message,
"error: interface-range 'axp' is not defined\n"
"error: interface-ranges expansion failed")
self.assertEqual(ex.errs, [
{'source': None, 'message':
"interface-range 'axp' is not defined",
'bad_element': None, 'severity': 'error',
'edit_path': None},
{'source': None,
'message': 'interface-ranges expansion failed',
'bad_element': None, 'severity': 'error',
'edit_path': None}])
else:
self.assertEqual(ex.message,
"interface-range 'axp' is not defined")
self.assertEqual(ex.message,
"error: interface-range 'axp' is not defined\n"
"error: interface-ranges expansion failed")
self.assertEqual(ex.errs, [
{'source': None, 'message':
"interface-range 'axp' is not defined",
'bad_element': None, 'severity': 'error',
'edit_path': None},
{'source': None,
'message': 'interface-ranges expansion failed',
'bad_element': None, 'severity': 'error',
'edit_path': None}])

@patch('jnpr.junos.utils.config.Config.lock')
@patch('jnpr.junos.utils.config.Config.unlock')
Expand Down Expand Up @@ -823,10 +819,7 @@ def _read_file(self, fname):
raw = etree.XML(foo)
obj = RPCReply(raw)
obj.parse()
if ncclient.__version__ > (0, 4, 5):
raise RPCError(etree.XML(foo), errs=obj._errors)
else:
raise RPCError(etree.XML(foo))
raise RPCError(etree.XML(foo), errs=obj._errors)

def _mock_manager(self, *args, **kwargs):
if kwargs:
Expand Down

0 comments on commit cce1a66

Please sign in to comment.