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

False positives on _base_pattern, can't override. #50

Open spdkils opened 3 years ago

spdkils commented 3 years ago

Describe the bug

The send_command function allows for a pattern to be input to stop the parse, however the default pattern is used as an optional stop point regardless.

This causes issues if you have a comment with the switch name and a > or # following it.

The regular expression should probably be anchored ^ $ to confirm that it is not found in the middle of a line, or other erronous location causing the send_command to prematurely return.

General Information

Debug information

Reading pattern "WAS-SF02-1-119-DC#" or "WAS-SF02-1-1.?((.?))?[>|#]" was found

^^^^ WHOOOPS!!!

My startup has this line...

description VPC Peerlink<Chassis1 WAS-SF01-1-119-DC | Chassis2 WAS-SF02-1-119-DC>

Additional context

So, without line anchors, I have to limit what descriptions I have, and I'm not sure if it's catching a truncating other commands.

The fix???

Well there are a few approaches. First if I override a pattern, it should respect that pattern, and timeout otherwise, not use both my pattern and the default pattern.

Second I think anchors in most cases would be appropriate to ensure the base prompt is found on a "clean" line, not as a mishap of some port description if I have some network admin getting fancy with their descriptions.

spdkils commented 3 years ago

I would NORMALLY just get more picky, and override the pattern... However I can't override the pattern because the defaults, it always looks for the default pattern in the code. So I'm sunk. I have to edit this package to get around this, or search every config we have (28,000+) and ensure we never do this, and put out a memo ugh. Much prefer to make the pattern search more restrictive.

spdkils commented 3 years ago

Sadly this version of NXOS spits out \r\n\r\n\rROUTER% So using ^ won't anchor it, so you would have to use [\r\n] to simulate the ^ since it's out of order. (Thanks Cisco)