saparikh / bf_snapshot_collector

Batfish Snapshot Collector

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add logic to validate netmiko.base_prompt

saparikh opened this issue · comments

There are situations in which the base prompt detection logic in netmiko fails to return a valid prompt. This can result in the output getting truncated or a read timeout since it cannot find the prompt in the output.

You can explicitly set the pattern you want netmiko to use by setting the expect_string when calling send_command, but this doesn't deal with a number of common scenarios that could arise:

  1. device name in inventory is FOO, but on the box it is FOO.mgmt
  2. device name in inventory is foo.bar.com but on the box it is just foo
  3. case mis-match of name
  4. case mis-match plus either 1) or 2)

To cover all of the bases, need to check the prompt netmiko finds to ensure that either:

  1. inventory name is in prompt (try both cases)
    example:
    • FOO would be in FOO.mgmt
    • FOO.lower() would be in FOO.mgmt.lower()
    • FOO.upper() would be in FOO.mgmt.upper()
  2. prompt is in inventory name (try both cases)
    example:
    • foo would be in foo.bar.com
    • foo.lower() would be in foo.bar.com.lower()
    • foo.upper() would be in foo.bar.com.upper()

this will cover the 4 scenarios. if these conditions are met, you can just use the prompt netmiko finds. if not, need to use an expect_string and until ktbyers/netmiko#2589 is resolved, will likely need to create one that can generate a case-insensitive match

I missed a case - device name in inventory is FOO.mgmt and on the box it is foo.bar.com (or vice-versa). I guess this can be solved by just splitting the inventory name on .