Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial syntax matches are scored the same as variables, resulting in ambiguous or incorrect matches #663

Closed
joewesch opened this issue May 27, 2022 · 4 comments
Assignees

Comments

@joewesch
Copy link

While evaluating using Genie with Netmiko I discovered that I was able to use abbreviated syntax such as sh ip int instead of show ip interface. However, if I did sh ip int br it would not work. After doing some digging it looks like the _fuzzy_search_command function was raising an exception and Netmiko was just swallowing it:

Search for 'sh ip int br' is ambiguous. Please be more specific in your keywords.

Results matched:
> show ip interface brief
> show ip interface {interface}

It looks like this happens because the score weight for a partial match (100) is the same as for a variable (100).

This also causes some interesting anomalies any time the position of a token in the command could be either syntax or a variable.

For example:

>>> from genie.libs.parser.utils import common
>>> common._fuzzy_search_command('show interfaces transceiver detail', False)[0][0]
'show interfaces transceiver detail'
>>> common._fuzzy_search_command('show interfaces transceive detail', False)[0][0]
'show interfaces {interface} detail'
>>>

Even though transceive is over 90% of transceiver the function instead returns the parser with a variable instead of a partial syntax match.

My initial thought was maybe weighing partial syntax as slightly higher (101) than variables, but that broke down when doing commands like show ip prefix-list as ip is short for ipv6 even though it was meant to match on show {af} prefix-list instead. This can probably be overcome by changing the show {af} prefix-list (and all similar show {af} commands) to instead use exact syntax of show ip/show ipv6 instead of the {af} variable, but there may be other similar issues by changing the weight of partial matches that aren't apparent. I only was able to easily identify that discrepancy due to a unit test written for it.

@joewesch
Copy link
Author

After reviewing further it seems that I should be using fuzzy=True. As this flag is not exposed in Netmiko, maybe this is better handled as an issue in that repo to expose the option.

I'll leave this issue open for now if anyone else has any input on how to better handle partial syntax matches without explicitly enabling fuzzy.

@stevedhn
Copy link

stevedhn commented Jun 9, 2022

Hi @joewesch do you have any updates on this?

@joewesch
Copy link
Author

joewesch commented Jun 9, 2022

No, I think the solution for now will be to enable fuzzy in Netmiko. I will go ahead and close this issue for now. Thanks.

@joewesch joewesch closed this as completed Jun 9, 2022
@stevedhn
Copy link

stevedhn commented Jun 9, 2022

Thanks Joe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants