selfuryon / netdev

Asynchronous multi-vendor library for interacting with network devices
http://netdev.readthedocs.io/
Apache License 2.0
213 stars 44 forks source link

sample script pauses indefinitely after connectin #11

Closed ajwillo closed 6 years ago

ajwillo commented 6 years ago

new to netdev. just wanted to test it with an existing script and it kept pausing after initial connecting and then waiting indefitnley, so I tried using the sample script to see if it was something I was doing. and I get the same result.

sample script:

#!/usr/bin/env python
from django_setup import setup
setup()
import re, argparse, time, ipaddress, asyncio, netdev, logging
from home.models import Credentials

logging.basicConfig(level=logging.INFO)
netdev.logger.setLevel(logging.DEBUG)

async def task(param):
    async with netdev.create(**param) as ios:
        # Testing sending simple command
        out = await ios.send_command("show ver")
        print(out)
        # Testing sending configuration set
        commands = ["line console 0", "exit"]
        out = await ios.send_config_set(commands)
        print(out)
        # Testing sending simple command with long output
        out = await ios.send_command("show run")
        print(out)
        # Testing interactive dialog
        out = await ios.send_command("conf", pattern=r'\[terminal\]\?', strip_command=False)
        out += await ios.send_command("term", strip_command=False)
        out += await ios.send_command("exit", strip_command=False, strip_prompt=False)
        print(out)

async def run():
    dev1 = { 
        'username': 'autoconfiguration',
        'password': 'xxxxxxxx',
        'device_type': 'cisco_ios',
        'host': '10.10.10.2',
    }
    devices = [dev1]
    tasks = [task(dev) for dev in devices]
    await asyncio.wait(tasks)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

output from the script is:

INFO:netdev.vendors:Host 10.10.10.2: Trying to connect to the device
INFO:netdev.vendors:Host 10.10.10.2: Establishing connection to port 22
INFO:asyncssh:Opening SSH connection to 10.10.10.2, port 22
INFO:asyncssh:[conn=0] Connection to 10.10.10.2, port 22 succeeded
INFO:asyncssh:[conn=0]   Local address: 172.17.0.2, port 48790
INFO:asyncssh:[conn=0] Beginning auth for user autoconfiguration
INFO:asyncssh:[conn=0] Auth for user autoconfiguration succeeded
INFO:asyncssh:[conn=0, chan=0] Requesting new SSH session
INFO:asyncssh:[conn=0, chan=0]   Interactive shell requested
INFO:netdev.vendors:Host 10.10.10.2: Connection is established
INFO:netdev.vendors:Host 10.10.10.2: Reading until pattern
DEBUG:netdev.vendors:Host 10.10.10.2: Reading pattern: \>|\#
DEBUG:netdev.vendors:Host 10.10.10.2: Reading pattern '\>|\#xxxxx
DEBUG:netdev.vendors:Host 110.10.10.2: Establish Connection Output: xxxx
INFO:netdev.vendors:Host 110.10.10.2: Setting base prompt
INFO:netdev.vendors:Host 10.10.10.2 Finding prompt
INFO:netdev.vendors:Host 10.10.10.2: Reading until pattern
DEBUG:netdev.vendors:Host 10.10.10.2: Reading pattern: \>|\#
DEBUG:netdev.vendors:Host 10.10.10.2: Reading pattern '\>|\xxxx
DEBUG:netdev.vendors:Host 10.10.10.2: Base Prompt: xxxx
STR-LAB-01-RTR-01
DEBUG:netdev.vendors:Host 10.10.10.2: Base Pattern: \$\$\$\$\$\$\ \ \ \ \ \ .*?(\(.*?\))?[\>|\#]
INFO:netdev.vendors:Host 10.10.10.2: Entering to privilege exec
INFO:netdev.vendors:Host 10.10.10.2: Checking privilege exec
INFO:netdev.vendors:Host 10.10.10.2: Reading until pattern
DEBUG:netdev.vendors:Host 10.10.10.2: Reading pattern: \$\$\$\$\$\$\ \ \ \ \ \ .*?(\(.*?\))?[\>|\#]

it stops here and never continues

selfuryon commented 6 years ago

Hello! Thank you for trying use my library and sorry for long time answer! I think that you have the same problem like in #10 case: do you have '>' or '#' in your banner?

ajwillo commented 6 years ago

Hi thanks for responding. Yes we have > in our banners. Is the fix to remove this from banners for now? Thanks

selfuryon commented 6 years ago

@ajwillo Yes, It would be the best solution right now! In case #10 I wrote why it's a problem and why I chose this tradeoff.