carlmontanari / scrapli

Fast, flexible, sync/async, Python 3.7+ screen scraping client specifically for network devices
https://carlmontanari.github.io/scrapli/
MIT License
587 stars 63 forks source link

Problem with command 'clear cli logical-system' on JUNOS #315

Closed jakovlev54 closed 10 months ago

jakovlev54 commented 10 months ago

Hello, Carl!

Can you help me find out why in Scrapli, when using the "clear cli logical-system" command, a line break occurs after the word "cli"?

Fragment of scrapli.log:

32    | 2024-01-19 10:34:06,138 | INFO     | 10.12.1.10:22           | connection to '10.12.1.10' on port '22' opened successfully
33    | 2024-01-19 10:34:06,138 | INFO     | 10.12.1.10:22           | sending channel input: set cli logical-system TEST; strip_prompt: True; eager: False
34    | 2024-01-19 10:34:06,138 | DEBUG    | 10.12.1.10:22           | write: 'set cli logical-system TEST'
35    | 2024-01-19 10:34:06,141 | DEBUG    | 10.12.1.10:22           | read : b'set cli logical-system TEST'
36    | 2024-01-19 10:34:06,142 | DEBUG    | 10.12.1.10:22           | write: '\n'
37    | 2024-01-19 10:34:06,145 | DEBUG    | 10.12.1.10:22           | read : b' \nLogical system: TEST\n\nnetconf@router_1_re1:TEST> '
38    | 2024-01-19 10:34:06,147 | INFO     | 10.12.1.10:22           | sending channel input: show interfaces descriptions; strip_prompt: True; eager: False
39    | 2024-01-19 10:34:06,147 | DEBUG    | 10.12.1.10:22           | write: 'show interfaces descriptions'
40    | 2024-01-19 10:34:06,149 | DEBUG    | 10.12.1.10:22           | read : b'show interfaces descriptions'
41    | 2024-01-19 10:34:09,374 | DEBUG    | 10.12.1.10:22           | write: '\n'
42    | 2024-01-19 10:34:09,394 | DEBUG    | 10.12.1.10:22           | read : b' \nInterface       Admin Link Description\nxe-3/2/9.0      up    down Test_for_LS\n\nnetconf@router_1_re1:TEST> '
43    | 2024-01-19 10:34:09,409 | INFO     | 10.12.1.10:22           | sending channel input: clear cli logical-system; strip_prompt: True; eager: False
44    | 2024-01-19 10:34:09,409 | DEBUG    | 10.12.1.10:22           | write: 'clear cli logical-system'
45    | 2024-01-19 10:34:09,413 | DEBUG    | 10.12.1.10:22           | read : b'clear cli\n                                                      ^\nsyntax error, expecting <command>.\nnetconf@router_1_re1:TEST> clear cli   \x08\x08\x08logical-system'
46    | 2024-01-19 10:34:10,387 | DEBUG    | 10.12.1.10:22           | write: '\n'
47    | 2024-01-19 10:34:10,390 | DEBUG    | 10.12.1.10:22           | read : b'\n                                                      ^\nsyntax error, expecting <command>.\n\nnetconf@router_1_re1:TEST> '
48    | 2024-01-19 10:34:10,390 | INFO     | 10.12.1.10:22           | sending channel input: show route instance MSN; strip_prompt: True; eager: False

Fragment of code:

device = 
    {
        "host": "10.12.1.10",
        "port": 22,
        "auth_username": USER,
        "auth_password": PASSWORD,
        "platform": "juniper_junos",
        "auth_strict_key": False,
        "transport": "asyncssh",
        "ssh_config_file": "../.ssh/config",

    }
async with AsyncScrapli(**device, channel_log=True) as conn:
            result = await conn.send_command("set cli logical-system TEST")
            result = await conn.send_command("show interfaces descriptions")
            result = await conn.send_command("clear cli logical-system")
            result = await conn.send_command("show route instance MMM")
jakovlev54 commented 10 months ago

This command is required to exit the logical system to the main device.

jakovlev54 commented 10 months ago

When entering commands manually everything is ok:

netconf@router_1_re1> set cli logical-system TEST    
Logical system: TEST

netconf@router_1_re1:TEST> show interfaces descriptions                
Interface       Admin Link Description
xe-3/2/9.0      up    down Test_for_LS

netconf@router_1_re1:TEST> clear cli logical-system                    
Cleared default logical system

netconf@router_1_re1> show route instance MMM                     
Instance             Type
         Primary RIB                                     Active/holddown/hidden
MSN                  vrf            
         MMM.inet.0                                      968/0/0
netconf@router_1_re1> 
carlmontanari commented 10 months ago

no idea! but we almost certainly aren't sending an extra newline just for fun!

45 | 2024-01-19 10:34:09,413 | DEBUG | 10.12.1.10:22 | read : b'clear cli\n ^\nsyntax error, expecting command>.\nnetconf@router_1_re1:TEST clear cli \x08\x08\x08logical-system'

I don't Junos but seems like you're upsetting it somewhere/someway (maybe in some previous command??) based on the syntax error output. Logs look like we correctly write it and then the error is pointing to the "cli" or after the cli part. is complete on space not disabled maybe for some reason? is there "more" to that command -- like "clear clis logical-system" or something?

jakovlev54 commented 10 months ago

JUNOS responds ambiguously - reason is again in authorization. Thanks for the answer!