scrapli: TimeoutError('Timed out reading from transport') for Junos

Scrapli works well for cases when configuration is error free, but if there is a typo - it will hang for a while untill Timeout is reached, but the session would be still connected

Here is a basic configuration that I used:

from scrapli.driver.core import JunosDriver my_device = { “host”: “192.168.226.139”, “auth_username”: “test”, “auth_password”: “~!QAZXSW@”, “auth_strict_key”: False } conn = JunosDriver(**my_device) conn.open() print(conn.send_command(“configure exclusive”).result) commands = [“set system services ssh”,“set system services nestconf ssh”] for command in commands: print("sending line - "+command) response = conn.send_config(command, strip_prompt=False) print(response.result) conn.close()

To Reproduce Steps to reproduce the behavior:

  1. run the script with several commands and one of them should contain typo
  2. Junos vMX with VCP/VFP v 17.2R1.13

Expected behavior I would expect to have it like “set system services nestconfssh” as Junos parser would not recognize command and get an error from parser, but I don’t see that command was ever entered (by using - “show log interactive-commands” on vMX)

Stack Trace

/home/python/PycharmProjects/config_deploy/venv/bin/python /home/python/PycharmProjects/config_deploy/scrapli_test.py
warning: uncommitted changes will be discarded on exit
Entering configuration mode

[edit]
sending line - set system services ssh
[edit]
test@LAB-ROUTER#
sending line - set system services nestconf ssh
Traceback (most recent call last):
  File "/home/python/PycharmProjects/config_deploy/scrapli_test.py", line 16, in <module>
    response = conn.send_config(command, strip_prompt=False)
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/driver/network_driver.py", line 392, in send_config
    multi_response = self.send_configs(
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/driver/network_driver.py", line 445, in send_configs
    response = super().send_command(
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/driver/generic_driver.py", line 75, in send_command
    raw_response, processed_response = self.channel.send_input(
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/channel/channel.py", line 165, in send_input
    raw_result, processed_result = self._send_input(
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/decorators.py", line 77, in timeout_wrapper
    return future.result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/channel/channel.py", line 192, in _send_input
    self._read_until_input(channel_input=bytes_channel_input)
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/channel/channel.py", line 82, in _read_until_input
    output += self._read_chunk()
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/channel/channel.py", line 47, in _read_chunk
    new_output = self.transport.read()
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/decorators.py", line 104, in requires_open_session_wrapper
    return wrapped_func(*args, **kwargs)
  File "/home/python/PycharmProjects/config_deploy/venv/lib/python3.8/site-packages/scrapli/decorators.py", line 76, in timeout_wrapper
    raise TimeoutError(message)
TimeoutError: Timed out reading from transport


OS:

  • OS: Ubuntu 20.04
  • scrapli version 2020.7.12

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

updated develop branch with the fix. still doing some testing locally but I think it should be good to try!

Hopefully I’ll merge/release next weekend – I’ve got a few other things I’m working on I’d like to include in the next release!

Haha 😄 no worries, I will test as soon as you push it to develop branch. Thank you for helping me with it 😃

Hello again @ilyapetrashkevich – I think I’ve got a workaround for this I am relatively happy with. Could you give this script a try with the develop branch and let me know if it fixes things for you?

You can install the develop branch like so:

pip install -e git+https://github.com/carlmontanari/scrapli.git@develop#egg=scrapli

Thanks for working with me on this!

Carl

Since we disable complete on space w/ junos you’ll have to send the “full” commands – not the abbreviations. set policy-options policy-statement test from community test should work.

vrnetlab> set cli complete-on-space off 
Disabling complete-on-space

vrnetlab> configure private 
warning: uncommitted changes will be discarded on exit
Entering configuration mode

[edit]
vrnetlab# set poli poli
              ^
syntax error.
vrnetlab# set poli poli   
error: syntax error: poli

[edit]
vrnetlab# set policy-options policy-statement test from community test" 

[edit]
vrnetlab#

^ you can see w/ the abbreviated commands that junos does the “interrupting” thing and thus causes the same issue.

I’ll keep ya posted on if/how I decide to “fix” this!

Hello, Marc. Yeah, I meant that I would like to have same aproach for Junos as for IOSXE 😃 Luckily I’m using core driver 😄 Okay, as of now I will tell my team-members that they should verify configuration before providing it to scrapli, but you never know for sure…