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

sros md-cli: premature end when issuing command #67

Open
nskalis opened this issue Oct 29, 2022 · 7 comments
Open

sros md-cli: premature end when issuing command #67

nskalis opened this issue Oct 29, 2022 · 7 comments
Assignees

Comments

@nskalis
Copy link

nskalis commented Oct 29, 2022

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
Copy link
Author

nskalis commented Nov 14, 2022

@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?

self.mdcli_prompt = r'^(.*?)\[.*\][\r\n]+[AB]:.*@%N#\s?$'

Would you be so kind to advise on it?

@Alexpf20210007
Copy link
Contributor

Alexpf20210007 commented Nov 14, 2022 via email

@Taarini
Copy link
Contributor

Taarini commented Feb 23, 2023

Thanks for your contribution.

I will work with the team on getting the approval

@Taarini
Copy link
Contributor

Taarini commented Feb 24, 2023

Hi

Can you please address the review comments provided by the reviewer

@nskalis
Copy link
Author

nskalis commented Feb 25, 2023

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

@Taarini
Copy link
Contributor

Taarini commented Mar 3, 2023

Hi

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

@maureenschaar
Copy link

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

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

4 participants