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:
- device name in inventory is
FOO
, but on the box it isFOO.mgmt
- device name in inventory is
foo.bar.com
but on the box it is justfoo
- case mis-match of name
- 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:
- inventory name is in prompt (try both cases)
example:FOO
would be inFOO.mgmt
FOO
.lower() would be inFOO.mgmt
.lower()FOO
.upper() would be inFOO.mgmt
.upper()
- prompt is in inventory name (try both cases)
example:foo
would be infoo.bar.com
foo
.lower() would be infoo.bar.com
.lower()foo
.upper() would be infoo.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 .