unicon.plugins icon indicating copy to clipboard operation
unicon.plugins copied to clipboard

sros md-cli: premature end when issuing command

Open nskalis opened this issue 2 years ago • 7 comments

Hi,

And thank you for making unicon available. I encountered an issue when trying to dump the configuration of a sros router using md-cli. More specifically,

  • the connection object is defined like:
uni_conn = unicon.Connection(
    hostname="some-name",
    os="sros",
    start=["{} {}".format("ssh", "x.x.x.x")],
    learn_hostname=True,
    credentials={
        "default": {
            "username": os.environ["NETWORK_USERNAME"],
            "password": os.environ["NETWORK_PASSWORD"],
        }
    },
    init_config_commands=[],
    log_stdout=True,
    debug=True,
    connection_timeout=10,
    overwrite_settings=False,
    settings={"DEFAULT_CLI_ENGINE": "mdcli"},
)
  • The command issued is: (the purpose is to dump the router's configuration)
uni_conn.execute("admin show configuration flat | no-more", timeout=10)
  • But, the output stops being produced, the last lines look like this:
...
    configure { policy-options as-path-group "BOGON_ASNS_IN" }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 1 }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 1 expression ".* 0 .*" }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 2 }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 2 expression ".* 23456 .*" }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 3 }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 3 expression ".*

While the router's configuration is:

...
    configure { policy-options as-path-group "BOGON_ASNS_IN" }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 1 }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 1 expression ".* 0 .*" }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 2 }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 2 expression ".* 23456 .*" }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 3 }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 3 expression ".* [64496-64511] .*" }
    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 4 }
...

It seems there is a problem with the [ character.

  • What the debug option prints out is:
\r\n    configure { policy-options as-path-group "BOGON_ASNS_IN" }\r\n    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 1 }\r\n    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 1 expression ".* 0 .*" }\r\n    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 2 }\r\n    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 2 expression ".* 23456 .*" }\r\n    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 3 }\r\n    configure { policy-options as-path-group "BOGON_ASNS_IN" entry 3 expression ".* ',)


2022-10-29 19:46:43,132: %UNICON-DEBUG: Statement matched: '[pattern='^(.*?)\[.*\][\r\n]+[AB]:.*@some-name#\s?$', action=None, args=None, loop_continue=False, continue_timer=False, trim_buffer=True]'
2022-10-29 19:46:43,206: %UNICON-DEBUG: Statement matched: '[pattern='^(.*?)\[.*\][\r\n]+[AB]:.*@some-name#\s?$', action=None, args=None, loop_continue=False, continue_timer=False, trim_buffer=True]'
2022-10-29 19:46:43,211: %UNICON-DEBUG: >>> Unicon Sending (target=some-name):: '\r'
2022-10-29 19:46:43,229: %UNICON-DEBUG: <<< Unicon Got (target=some-name):: '\r\n'
2022-10-29 19:46:43,229: %UNICON-DEBUG: *** Pattern List (target=some-name):: 
2022-10-29 19:46:43,229: %UNICON-DEBUG: 	'.+$'
2022-10-29 19:46:43,230: %UNICON-DEBUG: 
2022-10-29 19:46:43,230: %UNICON-DEBUG: *** Pattern Matched (target=some-name):: '.+$'
2022-10-29 19:46:43,230: %UNICON-DEBUG: <unicon.eal.MatchMode mode_id=0, mode_name='search multi-line re.S'>
2022-10-29 19:46:43,230: %UNICON-DEBUG: 
[]
A:user_awesome@some-name# 
2022-10-29 19:46:43,230: %UNICON-DEBUG: <<< Unicon Got (target=some-name):: '\r\n\r\n[]\r\nA:user_awesome@some-name# '
2022-10-29 19:46:43,230: %UNICON-DEBUG: *** Pattern List (target=some-name):: 
2022-10-29 19:46:43,230: %UNICON-DEBUG: 	'^(.*?)\\*?[AB]:some-name(>.*)?#\\s?$'
2022-10-29 19:46:43,230: %UNICON-DEBUG: 	'^(.*?)\\[.*\\][\\r\\n]+[AB]:.*@some-name#\\s?$'
2022-10-29 19:46:43,230: %UNICON-DEBUG: 
2022-10-29 19:46:43,230: %UNICON-DEBUG: *** Pattern Matched (target=some-name):: '^(.*?)\\[.*\\][\\r\\n]+[AB]:.*@some-name#\\s?$'
2022-10-29 19:46:43,230: %UNICON-DEBUG: <unicon.eal.MatchMode mode_id=0, mode_name='search multi-line re.S'>
2022-10-29 19:46:43,230: %UNICON-DEBUG: *** Match Groups:: ('\r\n\r\n',)
2022-10-29 19:46:43,230: %UNICON-DEBUG: Statement matched: '[pattern='^(.*?)\[.*\][\r\n]+[AB]:.*@some-name#\s?$', action=update_cur_state, args={'transition': <unicon.statemachine.statetransition.AnyStateTransition object at 0x7f4e9ffa94f0>, 'state': mdcli}, loop_continue=False, continue_timer=False, trim_buffer=True]'
2022-10-29 19:46:43,237: %UNICON-DEBUG: >>> Unicon Sending (target=some-name):: '\x1a'
[]
A:user_awesome@some-name# 
2022-10-29 19:46:43,259: %UNICON-DEBUG: <<< Unicon Got (target=some-name):: '\r\n\r\n[]\r\nA:user_awesome@some-name# '
2022-10-29 19:46:43,259: %UNICON-DEBUG: *** Pattern List (target=some-name):: 
2022-10-29 19:46:43,259: %UNICON-DEBUG: 	'Discard uncommitted changes\\? \\[y,n\\]'
2022-10-29 19:46:43,259: %UNICON-DEBUG: 	'^(.*?)\\[.*\\][\\r\\n]+[AB]:.*@some-name#\\s?$'
2022-10-29 19:46:43,259: %UNICON-DEBUG: 
2022-10-29 19:46:43,260: %UNICON-DEBUG: *** Pattern Matched (target=some-name):: '^(.*?)\\[.*\\][\\r\\n]+[AB]:.*@some-name#\\s?$'
2022-10-29 19:46:43,260: %UNICON-DEBUG: <unicon.eal.MatchMode mode_id=0, mode_name='search multi-line re.S'>
2022-10-29 19:46:43,260: %UNICON-DEBUG: *** Match Groups:: ('\r\n\r\n',)
2022-10-29 19:46:43,260: %UNICON-DEBUG: Statement matched: '[pattern='^(.*?)\[.*\][\r\n]+[AB]:.*@some-name#\s?$', action=None, args=None, loop_continue=False, continue_timer=False, trim_buffer=True]'

Would you be so kind to look into it and advise what is going wrong?

nskalis avatar Oct 29 '22 18:10 nskalis

@Alexpf20210007 @tahigash you appear to be the most recent contributors to this repository. I am sorry for drawing your attention, I don't know what else to do to get some help on this.

As you seem to be familiar with the codebase, can you pinpoint what is wrong in this case? Do you think this is regex-related?https://github.com/CiscoTestAutomation/unicon.plugins/blob/50a99423bb5d55095837bdf65fdbd787a5ac2edf/src/unicon/plugins/sros/patterns.py#L12

Would you be so kind to advise on it?

nskalis avatar Nov 14 '22 12:11 nskalis

Nikos,

Not sure if this helps. When I had issues with the ArubaOS, it was all RegEx related. You can easily comment out code and then re-run a script in order to see where the problem is. What helped me the most, is looking at the scripts on other Cisco plugins and checking the RegEx in those.


American Family Mutual Insurance Company, S.I. | American Family Insurance Company | American Family Life Insurance Company | American Standard Insurance Company of Ohio | American Standard Insurance Company of Wisconsin | Midvale Indemnity Company | Home Office - 6000 American Parkway Madison, WI 53783Permanent General Assurance Corporation | Permanent General Assurance Corporation of Ohio | The General Automobile Insurance Company, Inc. DBA The General® Home Office - 2636 Elm Hill Pike Nashville, TN 37214 wholly owned subsidiaries of American Family Mutual Insurance Company, S.I.*If you are not the intended recipient, please contact the sender and delete this e-mail, any attachments and all copies..

Alexpf20210007 avatar Nov 14 '22 13:11 Alexpf20210007

Thanks for your contribution.

I will work with the team on getting the approval

Taarini avatar Feb 23 '23 19:02 Taarini

Hi

Can you please address the review comments provided by the reviewer

Taarini avatar Feb 24 '23 21:02 Taarini

(yes, sure, I am back from holidays next week, it will be among the first things I'll work on)

nskalis avatar Feb 25 '23 12:02 nskalis

Hi

Did you get a chance to resolve the merge conflict and address the comment provided by the reviewer

Taarini avatar Mar 03 '23 18:03 Taarini

Hi, I also noticed this and could fix the prompt in patterns.py Until this is fixed in unicon plugin, is there a way to update the pattern during execution (testbed device connection)? I have not been able to find out to what object the patterns attributes apply. I tried setting the MDCLI_PROMPT to the connection object, but that did not work.

FYI I temporarily used this prompt to at least make it return all output: r'^(.*?)[AB]:.*@%N[#$]\s?$'

Maureen

maureenschaar avatar Aug 14 '23 11:08 maureenschaar