ktbyers / netmiko_tools

Command line tools built on Netmiko to simplify information gathering
Apache License 2.0
93 stars 32 forks source link

Avaya VSP script hangup??? #13

Open boxs3lli opened 8 years ago

boxs3lli commented 8 years ago

Greetings Kirk,

Love your work. Noted u r still in dev for Avaya boxes (i assume nm-grep tested OK against CIsco - haven't tried it yet) Came across following issue which looks like script not coping with avaya output (sample below) let me know if u need more debug or testing ...

is script expecting a password prompt post enable command? running voss 5.1.1.0 on vsp 4xxx and 8xxx - enable gets # (with no password)

[x@x vspShowCommands]$ python netmiko-grep.py --cmd "show isis adjacencies" "UP" lab
In disable_paging
Command: terminal more disable

In disable_paging
Command: terminal more disable

In disable_paging
Command: terminal more disable

8404Lab3:1>

Exiting disable_paging
4450Lab1:1>

Exiting disable_paging
4450Lab2:1>

Exiting disable_paging
^CTraceback (most recent call last):    <<<<<< interrupt <ctrl> C
  File "netmiko-grep.py", line 185, in <module>
    sys.exit(main(sys.argv[1:]))
  File "netmiko-grep.py", line 169, in main
    grepx(my_files, pattern, grep_options)
  File "netmiko-grep.py", line 50, in grepx
    proc.communicate()
  File "/usr/lib64/python2.7/subprocess.py", line 797, in communicate
    self.wait()
  File "/usr/lib64/python2.7/subprocess.py", line 1376, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib64/python2.7/subprocess.py", line 478, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt
###Versions####################################################
[x@x vspShowCommands]$ python netmiko-grep.py --version
netmiko-grep v0.0.3
[x@x vspShowCommands]$ pip show netmiko

---
Metadata-Version: 1.1
Name: netmiko
Version: 0.5.1
Summary: Multi-vendor library to simplify Paramiko SSH connections to network devices
Home-page: https://github.com/ktbyers/netmiko
Author: Kirk Byers
Author-email: ktbyers@twb-tech.com
License: MIT
Location: /usr/lib/python2.7/site-packages
Requires: paramiko, scp, pyyaml
Classifiers:
  Development Status :: 4 - Beta
  License :: OSI Approved :: MIT License
  Programming Language :: Python :: 2
  Programming Language :: Python :: 2.6
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3
  Programming Language :: Python :: 3.3
  Programming Language :: Python :: 3.4
  Programming Language :: Python :: 3.5
[x@x vspShowCommands]$ pip show python

---
Metadata-Version: 1.1
Name: Python
Version: 2.7.5
Summary: A high-level object-oriented programming language
Home-page: http://www.python.org/2.7
Author: Guido van Rossum and the Python community
Author-email: python-dev@python.org
License: PSF license
Location: /usr/lib64/python2.7/lib-dynload
Requires:
Classifiers:
  Development Status :: 6 - Mature
  License :: OSI Approved :: Python Software Foundation License
  Natural Language :: English
  Programming Language :: C
  Programming Language :: Python
  Topic :: Software Development
boxs3lli commented 8 years ago

think i lied about the enable ('sho isis adj' works at > prompt)

fulll debug below with all 7 debugs set to True

[x@x vspShowCommands]$  ./netmiko-grep.py --cmd 'show isis adjacencies' UP lab
aaa:
bbb: 8404Lab3:1>
ddd: 8404Lab3:1>
aaa:
bbb: 4450Lab1:1>
ddd: 4450Lab1:1>
aaa:
bbb: 4450Lab2:1>
ddd: 4450Lab2:1>
In disable_paging
Command: terminal more disable

Pattern is: 8404Lab3\:1
In disable_paging
Command: terminal more disable

Pattern is: 4450Lab1\:1
Pattern found: 4450Lab1\:1 4450Lab1:1>

4450Lab1:1>

Exiting disable_paging
Pattern is: 4450Lab1\:1
In disable_paging
Command: terminal more disable

Pattern is: 4450Lab2\:1
Pattern found: 4450Lab2\:1 4450Lab2:1>

4450Lab2:1>

Exiting disable_paging
Pattern is: 4450Lab2\:1
Pattern found: 8404Lab3\:1 8404Lab3:1>

8404Lab3:1>

Exiting disable_paging
Pattern is: 8404Lab3\:1
Pattern found: 4450Lab1\:1 4450Lab1:1>

Pattern found: 4450Lab2\:1 4450Lab2:1>

Pattern found: 8404Lab3\:1 8404Lab3:1>

Pattern is: 4450Lab1\:1
Pattern is: 4450Lab2\:1
Pattern is: 8404Lab3\:1
Pattern found: 4450Lab1\:1 4450Lab1:1>
Pattern is: 4450Lab1\:1
Pattern found: 4450Lab2\:1 4450Lab2:1>terminal more d
Pattern is: 4450Lab2\:1
Pattern found: 8404Lab3\:1 isable
8404Lab3:1>

Pattern is: 8404Lab3\:1
Pattern found: 4450Lab1\:1 terminal more disable
4450Lab1:1>

Pattern found: 4450Lab2\:1 isable
4450Lab2:1>

Pattern found: 8404Lab3\:1 8404Lab3:1>enable

^CTraceback (most recent call last):
  File "./netmiko-grep.py", line 185, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./netmiko-grep.py", line 169, in main
    grepx(my_files, pattern, grep_options)
  File "./netmiko-grep.py", line 50, in grepx
    proc.communicate()
  File "/usr/lib64/python2.7/subprocess.py", line 797, in communicate
    self.wait()
  File "/usr/lib64/python2.7/subprocess.py", line 1376, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib64/python2.7/subprocess.py", line 478, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt

##############################################

[x@x netmiko]# grep debug *.py
base_connection.py:        debug = True
base_connection.py:        if debug:
base_connection.py:        if debug:
base_connection.py:        debug = True
base_connection.py:        if debug:
base_connection.py:        if debug:
base_connection.py:                if debug:
base_connection.py:        if debug:
base_connection.py:        debug = True
base_connection.py:        if debug:
base_connection.py:        if debug:
base_connection.py:        if debug:
base_connection.py:        debug = True
base_connection.py:        if debug:
base_connection.py:                    if debug:
base_connection.py:        debug = True
base_connection.py:                if debug:
base_connection.py:        if debug:
base_connection.py:                if debug:
base_connection.py:        debug = True
base_connection.py:        if debug:
base_connection.py:        debug = True
base_connection.py:        if debug:
base_connection.py:        if debug:
boxs3lli commented 8 years ago

sample output (no grep in VOSS yet)

4450Lab1:1>sho isis adj

====================================================================================================
                                ISIS Adjacencies

====================================================================================================
INTERFACE         L STATE        UPTIME PRI HOLDTIME SYSID             HOST-NAME
----------------------------------------------------------------------------------------------------
Port1/12          1 UP      4d 22:32:32 127       23 646a.52aa.a884    Lab3
ToLab2viaIP       1 UP      4d 22:32:16 127       25 b447.5e3b.b565    Lab2

--------------------------------------------------------------------------------
 2 out of 2 interfaces have formed an adjacency
--------------------------------------------------------------------------------
ktbyers commented 8 years ago

@boxs3lli What happens if you try this against your Avaya device:

#!/usr/bin/env python
from netmiko import ConnectHandler
from getpass import getpass

ip_addr = raw_input("Enter IP Address: ")

device = {
    'device_type': 'avaya_vsp',
    'ip': ip_addr,
    'username': 'pyclass',
    'password': getpass(),
    'port': 22,
} 

net_connect = ConnectHandler(**device)
net_connect.enable()
output = net_connect.send_command_expect("sho isis adj")

print
print '#' * 50
print output
print '#' * 50
print

Does this work or generate an error? If an error can you send it to me?

boxs3lli commented 8 years ago

Kirk

debug follows - enjoy ....

[ib33@coomd vspShowCommands]$ python test1.py Enter IP Address: 10.3.1.10 Password: aaa: bbb: 4450Lab1:1> ddd: 4450Lab1:1> In disable_paging Command: terminal more disable

Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>

4450Lab1:1>

Exiting disable_paging Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>

Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>terminal more disable

Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>

Traceback (most recent call last): File "test1.py", line 16, in net_connect.enable() File "/usr/lib/python2.7/site-packages/netmiko/ssh_connection.py", line 15, in enable return super(SSHConnection, self).enable(cmd=cmd, pattern=pattern, re_flags=re_flags) File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 548, in enable raise ValueError("Failed to enter enable mode.") ValueError: Failed to enter enable mode.

On 24 June 2016 at 03:26, Kirk Byers notifications@github.com wrote:

@boxs3lli https://github.com/boxs3lli What happens if you try this against your Avaya device:

!/usr/bin/env python

from netmiko import ConnectHandler from getpass import getpass

ip_addr = raw_input("Enter IP Address: ")

device = { 'device_type': 'avaya_vsp', 'ip': ip_addr, 'username': 'pyclass', 'password': getpass(), 'port': 22, }

net_connect = ConnectHandler(**device) net_connect.enable() output = net_connect.send_command_expect("show version")

print print '#' * 50 print output print '#' * 50 print

Does this work or generate an error? If an error can you send it to me?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ktbyers/netmiko_tools/issues/13#issuecomment-228121694, or mute the thread https://github.com/notifications/unsubscribe/ATFQ_CAzjY-TbkGJ6oOZgHhJBWw-dNBSks5qOsHMgaJpZM4I43sj .


boxs3lli commented 8 years ago

Kirk

apologies re brevity of last reply - was a bit rushed at the time but wanted to get data to u have a younger gentleman here with some python skills who is interested in having a look at the issue

are there any coding guidelines and/or a code schematic/diagram he should be aware of??

THX

IB

Kirk

debug follows - enjoy ....

[ib33@coomd vspShowCommands]$ python test1.py Enter IP Address: 10.3.1.10 Password: aaa: bbb: 4450Lab1:1> ddd: 4450Lab1:1> In disable_paging Command: terminal more disable

Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>

4450Lab1:1>

Exiting disable_paging Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>

Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>terminal more disable

Pattern is: 4450Lab1:1 Pattern found: 4450Lab1:1 4450Lab1:1>

Traceback (most recent call last): File "test1.py", line 16, in net_connect.enable() File "/usr/lib/python2.7/site-packages/netmiko/ssh_connection.py", line 15, in enable return super(SSHConnection, self).enable(cmd=cmd, pattern=pattern, re_flags=re_flags) File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 548, in enable raise ValueError("Failed to enter enable mode.") ValueError: Failed to enter enable mode.

On 24 June 2016 at 03:26, Kirk Byers notifications@github.com wrote:

@boxs3lli https://github.com/boxs3lli What happens if you try this against your Avaya device:

!/usr/bin/env python

from netmiko import ConnectHandler from getpass import getpass

ip_addr = raw_input("Enter IP Address: ")

device = { 'device_type': 'avaya_vsp', 'ip': ip_addr, 'username': 'pyclass', 'password': getpass(), 'port': 22, }

net_connect = ConnectHandler(**device) net_connect.enable() output = net_connect.send_command_expect("show version")

print print '#' * 50 print output print '#' * 50 print

Does this work or generate an error? If an error can you send it to me?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ktbyers/netmiko_tools/issues/13#issuecomment-228121694, or mute the thread https://github.com/notifications/unsubscribe/ATFQ_CAzjY-TbkGJ6oOZgHhJBWw-dNBSks5qOsHMgaJpZM4I43sj .

ktbyers commented 8 years ago

@boxs3lli You should look at it in Netmiko first and not in netmiko-grep. It will be easier to troubleshoot there. Once it works in Netmiko; it should work in netmiko-grep.

You can see the following:

https://github.com/ktbyers/netmiko/blob/master/VENDOR.md https://github.com/ktbyers/netmiko/blob/master/README.md

If you have questions, just post to this issue.

khorramic commented 8 years ago

Hi Kirk,

My name is Cameron and I've been working with @boxs3lli on this issue.

Originally we couldn't get the net_connect.enable() to enable correctly during the SSHConnection stage of the netmiko-grep.py; this is due to the fact that the original netmiko code was looking for an privileged exec password when 'enabling', however as avaya devices do not support this function (yet), it would always fail. By reprogramming the avaya_vsp_ssh.py code as below (appended and modified the 'enable' function from the base_connection.py), we were able to establish a working connection; below is the diff between the original and my modified script:

def enable(self, cmd='', pattern='', re_flags=re.IGNORECASE):
    """Enter enable mode."""
    output = ""
    if not self.check_enable_mode():
        self.remote_conn.sendall(self.normalize_cmd(cmd))
        output += self.read_until_prompt_or_pattern(pattern=pattern, re_flags=re_flags)
        #self.remote_conn.sendall(self.normalize_cmd(self.secret)
        output += self.read_until_prompt()
        #below if statement always causes the function to exit as an error, regardless of if it is successful
        #if not self.check_enable_mode():
        #    raise ValueError("Failed to enter enable mode.")
        return output

Now however, I've discovered that netmiko-grep.py is not passing complete information to the grepx function, see below for a debug log (NOTE: shell=True is set for the time being to prevent suppression of the grep error messages):

debug: output_q is initialised to Queue.Queue instance at 0x1311710

aaa:
bbb: name-ommitted1:1>
ddd: name-ommitted1:1>
aaa:
bbb: name-ommitted3:1>
ddd: name-ommitted3:1>
aaa:
bbb: name-ommitted2:1>
ddd: name-ommitted2:1>

<--- ommitted --->

Found prompt: name-ommitted2:1>
Command is: show isis adjacencies

Search to stop receiving data is: 'name-ommitted2\:1\>'
Found prompt: name-ommitted1:1>
Command is: show isis adjacencies

Search to stop receiving data is: 'name-ommitted1\:1\>'
Found prompt: name-ommitted3:1>
Command is: show isis adjacencies

Search to stop receiving data is: 'name-ommitted3\:1\>'

<--- ommitted --->

4:show isis adjacencies

<--- ommitted --->

                                ISIS Adjacencies

<--- ommitted --->

name-ommitted3:1>
Pattern is: name-ommitted3\:1
Pattern found: name-ommitted2\:1
name-ommitted2:1>
Pattern found: name-ommitted1\:1
name-ommitted1:1>
Pattern found: name-ommitted3\:1
name-ommitted3:1>

debug: kirk, after processing, output_q =  Queue.Queue instance at 0x1311710
debug: kirk, after processing, my_files =  []
Usage: /bin/grep [OPTION]... PATTERN [FILE]...
Try '/bin/grep --help' for more information.

I believe the issue lies with the queuing and/or threading. Output_q always remains empty, as a result the 'while not output_q.empty()' is always skipped, hence why 'my_files' remains empty as well because no information will ever fill it. Excuse however if I'm understanding the whole process incorrectly as I've had to bring out my python programming books after quite a while, so I'm a bit rusty.

I've attached copies of the avaya_vsp_ssh.py and netmiko-grep.py scripts that we are using and have modified so it might make it easier to debug.

Best Regards

Cameron

netmiko-grep.txt avaya_vsp_ssh.txt

ktbyers commented 7 years ago

@khorramic Are you still having this issue?

khorramic commented 7 years ago

Hi, a contractor came in and had a look at the programming. He managed to resolve the issue and if I remember correctly it had to do with the dictionary not filling correctly.

If I can get in contact with him I'll request that he provides diffed code so you can integrate it into your main release if you wish.

Regards,

Cameron