Netmiko: Huawei has ANSI escape codes in the output that need stripped (on long commands)

Created on 5 Mar 2020  路  28Comments  路  Source: ktbyers/netmiko

Dears,

I use threading to check 50-500 devices at the same time. I had a lot of exception when the returned output was only the timestamp or only the (expected)prompt which should be ommitted by default.

I have added some extra check to my function to send commands on a very reliable way.
It seems that checking whether the returned output type is List, when TextFSM is turned on.

However, I have met 1 exception that I do not know why it happened.
The returned output was a list, but only with 1 line (expected 3) and the key values were all empty.
Running the script again returns the expected output. Probably, I could add another check, if the output is list, I could check if the keys are not empty, but sometimes an empty key is a valid output.

How do I know why TextFSM(or Netmiko) failed in this particular case. I have not tried to reproduce it. The check ran for 2280 devices, only this case returned a partially empty output, but in the correct List structure.

WARNING :: 2020-03-04 17:38:23,477 :: 197 :: Thread-2854 :: def_send_single_cmd_txtfsm :: Sending "display isis peer verbose | exclude Eth-Trunk10" command to masked_device_name.
WARNING :: 2020-03-04 17:38:25,402 :: 235 :: Thread-2854 :: def_send_single_cmd_txtfsm :: Recording the output: display isis peer verbose | exclude Eth-Trunk10 | masked_device_name | [{'isisinterface': 'Vlanif4060', 'isisuptimeh': '', 'isisuptimem': ''}]
CRITICAL :: 2020-03-04 17:38:26,891 :: 24 :: Thread-2854 :: _Def_Log_Exceptions :: Unhandled exception: Traceback (most recent call last):
File "hcheck_tre.py", line 42, in run
run_old(args, *kwargs)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/threading.py", line 864, in run
self._target(self._args, *self._kwargs)
File "hcheck_tre.py", line 1625, in ssh_session
ztpL2AL_list): PIMNeiCount, ISISNeiCount, ISISUpTimeStatus = def_pim_n_isis_nei_count_nal(ssh_session, hostname)
File "hcheck_tre.py", line 708, in def_pim_n_isis_nei_count_nal
if def_isis_peer_uptime(line, ISIS_Peer_Uptime_Hours):
File "hcheck_tre.py", line 312, in def_isis_peer_uptime
if int(line['isisuptimeh']) > minisisuptimeh:
ValueError: invalid literal for int() with base 10: ''

The correct output is:
[{'isisinterface': 'Vlanif4060', 'isisuptimeh': '5573', 'isisuptimem': '40'},
{'isisinterface': 'Eth-Trunk1', 'isisuptimeh': '5573', 'isisuptimem': '40'},
{'isisinterface': 'Eth-Trunk3', 'isisuptimeh': '5574', 'isisuptimem': '03'}]

Thanks!

PS:
In General I could check if the keys are empty, but sometimes it is a valid output, so I would need to check per command basis.

However, the number of expected lines can vary per device (EG: if one of the peer is missing due to failure, there will never be 3 lines).

bug

Most helpful comment

Netmiko in Netmiko 3.0.0 tries to verify the command echo. For example if you send something like:

show ip interface brief

It tries to verify this is properly echoed to the screen before moving on. This helps with a bunch of issues pertaining to slowness and to Netmiko losing the proper state of the session (i.e. thinking it is one state when it is not).

But it causes other problems (like the one here).

Consequently, you can add this argument to send_command to disable this behavior (i.e. it will no longer verify the command echo).

net_connect.send_command(command, cmd_verify=False)

All 28 comments

Which version of Netmiko are you using?

Also can you send over the relevant section of your Python code where you are doing the Netmiko + Textfsm.

Which version of Netmiko are you using?

Also can you send over the relevant section of your Python code where you are doing the Netmiko + Textfsm.

Thanks for your reply!

netmiko 2.4.2
textfsm 1.1.0

This is the send command code:

https://codeshare.io/5Nvbwo

Okay, can you test if it works on Netmiko 3.0.0?

Kirk

Okay, can you test if it works on Netmiko 3.0.0?

Kirk

Do you mean to try reproducing the missing or partially missing outputs?
I could upgrade to 3.0.0, but the send command set feature did not work on (Huawei VRP8).

Okay, then we need to work on that the 'send_command' not working on Huawei VRP8 (which issue was that)?

Any fix/research needs to be based on Netmiko 3.0.0

Kirk

Okay, then we need to work on that the 'send_command' not working on Huawei VRP8 (which issue was that)?

Any fix/research needs to be based on Netmiko 3.0.0

Kirk

Okay. I am going to upgrade amd test both of the features.
Send cmd set is only used when the script needs to enter to diag view or to change configuration. In 99% I send single commands to query info.

I used to separate commands in the list with " \n ". In 3.0.0 only the 1st command of the list was sent, but it never hit enter. I replaced "n" with "r", all the commands were sent, but the last one was sent w/o hitting enter, so the timeou just expired.

I will be back soon.

Sounds good.

Kirk

Sounds good.

Kirk

I after upgrading to 3.0.0 and I met another issue.
As you can see this command failed to retrive the output. However, the device log shows that the command was succesfully received/ran.

WARNING :: 2020-03-06 04:59:16,059 :: 158 :: Thread-1 :: def_send_single_cmd_plain :: Sending "display dfs-group m-lag brief | i Down\s+inactive(*)-inactive" command to hostname.
ERROR :: 2020-03-06 04:59:38,280 :: 167 :: Thread-1 :: def_send_single_cmd_plain :: Retry send command 0 | display dfs-group m-lag brief | i Down\s+inactive(*)-inactive | hostname
ERROR :: 2020-03-06 05:00:00,373 :: 167 :: Thread-1 :: def_send_single_cmd_plain :: Retry send command 1 | display dfs-group m-lag brief | i Down\s+inactive(*)-inactive | hostname

This is how the plain text output looks like. (no TextFSM):

display dfs-group m-lag brief | i Down\s+inactive(*)-inactive
2020-03-06 05:06:14.995 +01:00


    • Local node

M-Lag ID Interface Port State Status Consistency-check
123 Eth-Trunk 123 Down inactive(*)-inactive --

Can you get rid of the threading and just run it against a single device?

I need the Python exception stack track and the Netmiko log:

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

Can you get rid of the threading and just run it against a single device?

I need the Python exception stack track and the Netmiko log:

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

Okay, This is how it looks like.

The command what I sent is:
display dfs-group m-lag brief | i Down\s+inactive(*)-inactive
However, the last few characters look different in the log.

( I tried to change the command to " display dfs-group m-lag brief | include Down\s+inactive.*inactive " , did not help)

WARNING:root:Connecting to device: hostname
DEBUG:paramiko.transport:starting thread (client mode): 0x1d36b2e8
DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_2.6.0
DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0--
INFO:paramiko.transport:Connected (version 2.0, client -)
DEBUG:paramiko.transport:kex algos:['diffie-hellman-group-exchange-sha256', 'ecdh-sha2-nistp521', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp256', 'diffie-hellman-group-exchange-sha1', 'sm2kep-sha2-nistp256'] server key:['ssh-dss', 'ssh-rsa', 'ecdsa-sha2-nistp521'] client encrypt:['aes256-ctr', 'aes128-ctr', 'aes256-cbc', 'aes128-cbc', 'arcfour256', 'arcfour128', 'blowfish-cbc', '3des-cbc', 'des-cbc'] server encrypt:['aes256-ctr', 'aes128-ctr', 'aes256-cbc', 'aes128-cbc', 'arcfour256', 'arcfour128', 'blowfish-cbc', '3des-cbc', 'des-cbc'] client mac:['hmac-sha2-256', 'hmac-sha2-256-96', 'hmac-sha1-96'] server mac:['hmac-sha2-256', 'hmac-sha2-256-96', 'hmac-sha1-96'] client compress:['none', 'zlib'] server compress:['none', 'zlib'] client lang:[''] server lang:[''] kex follows?False
DEBUG:paramiko.transport:Kex agreed: ecdh-sha2-nistp256
DEBUG:paramiko.transport:HostKey agreed: ecdsa-sha2-nistp521
DEBUG:paramiko.transport:Cipher agreed: aes128-ctr
DEBUG:paramiko.transport:MAC agreed: hmac-sha2-256
DEBUG:paramiko.transport:Compression agreed: none
DEBUG:paramiko.transport:kex engine KexNistp256 specified hash_algo
DEBUG:paramiko.transport:Switch to new keys ...
DEBUG:paramiko.transport:Adding ecdsa-sha2-nistp521 host key for hostname: b'70112f0fa6707c108a1b08ccb913727f'
DEBUG:paramiko.transport:userauth is OK
INFO:paramiko.transport:Authentication (password) successful!
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:netmiko:Pattern is: (|(Change now|Please choose 'YES' or 'NO').+)
DEBUG:netmiko:_read_channel_expect read_data:


  • UNAUTHORIZED ACCESS STRICTLY PROHIBITED *
  • Access to this device is restricted to authorized agents of *
  • Swisscom only. Accessing this device for any reason without *
  • appropriate authorization is not permitted *

DEBUG:netmiko:Pattern found: (|(Change now|Please choose 'YES' or 'NO').+)


  • UNAUTHORIZED ACCESS STRICTLY PROHIBITED *
  • Access to this device is restricted to authorized agents of *
  • Swisscom only. Accessing this device for any reason without *
  • appropriate authorization is not permitted *

DEBUG:netmiko:read_channel: Info: The max number of VTY users is 21, the number of current VTY users online is 3, and total number of terminal users online is 3.
The current login time is 2020-03-06 17:15:50+01:00.

DEBUG:netmiko:read_channel:
DEBUG:netmiko:read_channel:
DEBUG:netmiko:In set_base_prompt
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:

DEBUG:netmiko:prompt: hostname
DEBUG:netmiko:read_channel:
DEBUG:netmiko:In disable_paging
DEBUG:netmiko:Command: screen-length 0 temporary

DEBUG:netmiko:write_channel: b'screen-length 0 temporary\n'
DEBUG:netmiko:Pattern is: screen-length\ 0\ temporary
DEBUG:netmiko:_read_channel_expect read_data: screen-length 0 temporary

DEBUG:netmiko:Pattern found: screen-length\ 0\ temporary screen-length 0 temporary

DEBUG:netmiko:screen-length 0 temporary

DEBUG:netmiko:Exiting disable_paging
DEBUG:netmiko:read_channel: Info: The configuration takes effect on the current user terminal interface only.

DEBUG:netmiko:Clear buffer detects data in the channel
DEBUG:netmiko:read_channel:
WARNING:root:Check 15: LAG Unselected Members Count - > AL.
WARNING:root:Sending "display eth-trunk brief" command to hostname.
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:

DEBUG:netmiko:read_channel:
DEBUG:netmiko:[find_prompt()]: prompt is
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'display eth-trunk brief\n'
DEBUG:netmiko:Pattern is: display\ eth-trunk\ brief
DEBUG:netmiko:_read_channel_expect read_data: display eth-trunk brief

DEBUG:netmiko:Pattern found: display\ eth-trunk\ brief display eth-trunk brief

DEBUG:netmiko:read_channel: 2020-03-06 17:15:56.334 +01:00
Status: Operate status
Role: E-Trunk status
Act: Active link number
Inact: Inactive link number
Cfgd: Configured link number
BW: Bandwidth
Interface Mode Status Role Act/Inact/Cfgd BW(Mbps)
Eth-Trunk0 STATIC Up - 2/0/2 80000
Eth-Trunk1 STATIC Up - 1/0/1 10000
Eth-Trunk3 STATIC Up - 4/0/4 40000
Eth-Trunk10 STATIC Up - 1/0/1 40000
Eth-Trunk61 NORMAL Up - 1/0/1 1000
Eth-Trunk100 STATIC Up - 1/0/1 10000
Eth-Trunk101 STATIC Up - 1/0/1 10000
Eth-Trunk102 STATIC Up - 1/0/1 10000
Eth-Trunk103 STATIC Up - 1/0/1 10000
Eth-Trunk104 STATIC Up - 1/0/1 10000
Eth-Trunk105 STATIC Down - 0/1/1 0
Eth-Trunk106 STATIC Up - 1/0/1 10000
Eth-Trunk107 STATIC Up - 2/0/2 2000
Eth-Trunk108 STATIC Up - 1/1/2 1000
Eth-Trunk109 STATIC Up - 1/0/1 10000

DEBUG:netmiko:read_channel: Eth-Trunk110 STATIC Up - 1/0/1 10000
Eth-Trunk111 STATIC Up - 1/0/1 1000
Eth-Trunk112 STATIC Up - 1/0/1 10000
Eth-Trunk113 STATIC Up - 1/0/1 1000
Eth-Trunk114 STATIC Up - 1/0/1 1000
Eth-Trunk115 STATIC Up - 1/0/1 10000
Eth-Trunk116 STATIC Up - 1/0/1 10000
Eth-Trunk117 STATIC Up - 1/0/1 10000
Eth-Trunk118 STATIC Up - 1/0/1 1000
Eth-Trunk119 STATIC Up - 1/0/1 1000
Eth-Trunk120 STATIC Up - 1/0/1 10000
Eth-Trunk121 STATIC Up - 1/0/1 10000
Eth-Trunk122 STATIC Up - 1/0/1 1000
Eth-Trunk123 STATIC Down - 0/1/1 0
Eth-Trunk124 STATIC Up - 1/0/1 10000

WARNING:root:Recording the output: display eth-trunk brief | hostname | [{'lagid': '0', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '2', 'inactive': '0', 'configured': '2', 'bwmbps': '80000'}, {'lagid': '1', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '3', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '4', 'inactive': '0', 'configured': '4', 'bwmbps': '40000'}, {'lagid': '10', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '40000'}, {'lagid': '61', 'type': 'NORMAL', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '1000'}, {'lagid': '100', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '101', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '102', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '103', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '104', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '105', 'type': 'STATIC', 'lagstatus': 'Down', 'active': '0', 'inactive': '1', 'configured': '1', 'bwmbps': '0'}, {'lagid': '106', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '107', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '2', 'inactive': '0', 'configured': '2', 'bwmbps': '2000'}, {'lagid': '108', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '1', 'configured': '2', 'bwmbps': '1000'}, {'lagid': '109', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '110', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '111', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '1000'}, {'lagid': '112', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '113', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '1000'}, {'lagid': '114', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '1000'}, {'lagid': '115', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '116', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '117', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '118', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '1000'}, {'lagid': '119', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '1000'}, {'lagid': '120', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '121', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}, {'lagid': '122', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '1000'}, {'lagid': '123', 'type': 'STATIC', 'lagstatus': 'Down', 'active': '0', 'inactive': '1', 'configured': '1', 'bwmbps': '0'}, {'lagid': '124', 'type': 'STATIC', 'lagstatus': 'Up', 'active': '1', 'inactive': '0', 'configured': '1', 'bwmbps': '10000'}]
WARNING:root:Sending "display dfs-group m-lag brief | i Down\s+inactive(*)-inactive" command to hostname.
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:

DEBUG:netmiko:read_channel:
DEBUG:netmiko:[find_prompt()]: prompt is
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'display dfs-group m-lag brief | i Down\s+inactive\(\*\)-inactive\n'
DEBUG:netmiko:Pattern is: display\ dfs-group\ m-lag\ brief\ \|\ i\ Down\s+inactive\(\*\)-inactive
DEBUG:netmiko:_read_channel_expect read_data: display dfs-group m-lag brief | i Down\s+inactive(*)-inac tive

DEBUG:netmiko:_read_channel_expect read_data: 2020-03-06 17:15:57.495 +01:00


    • Local node

M-Lag ID Interface Port State Status Consistency-check

DEBUG:netmiko:_read_channel_expect read_data: 123 Eth-Trunk 123 Down inactive(*)-inactive --

DEBUG:netmiko:_read_channel_expect read_data:
ERROR:root:Retry send command 0 | display dfs-group m-lag brief | i Down\s+inactive(*)-inactive | hostname
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:

DEBUG:netmiko:read_channel:
DEBUG:netmiko:[find_prompt()]: prompt is
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'display dfs-group m-lag brief | i Down\s+inactive\(\*\)-inactive\n'
DEBUG:netmiko:Pattern is: display\ dfs-group\ m-lag\ brief\ \|\ i\ Down\s+inactive\(\*\)-inactive
DEBUG:netmiko:_read_channel_expect read_data: display dfs-group m-lag brief | i Down\s+inactive(*)-inac tive

DEBUG:netmiko:_read_channel_expect read_data: 2020-03-06 17:16:19.593 +01:00


    • Local node

M-Lag ID Interface Port State Status Consistency-check
123 Eth-Trunk 123 Down inactive(*)-inactive --

DEBUG:netmiko:_read_channel_expect read_data:
ERROR:root:Retry send command 1 | display dfs-group m-lag brief | i Down\s+inactive(*)-inactive | hostname
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'\n'
DEBUG:netmiko:read_channel:

DEBUG:netmiko:read_channel:
DEBUG:netmiko:[find_prompt()]: prompt is
DEBUG:netmiko:read_channel:
DEBUG:netmiko:write_channel: b'display dfs-group m-lag brief | i Down\s+inactive\(\*\)-inactive\n'
DEBUG:netmiko:Pattern is: display\ dfs-group\ m-lag\ brief\ \|\ i\ Down\s+inactive\(\*\)-inactive
DEBUG:netmiko:_read_channel_expect read_data: display dfs-group m-lag brief | i Down\s+inactive(*)-inac tive

DEBUG:netmiko:_read_channel_expect read_data: 2020-03-06 17:16:41.655 +01:00


    • Local node

M-Lag ID Interface Port State Status Consistency-check
123 Eth-Trunk 123 Down inactive(*)-inactive --

DEBUG:netmiko:_read_channel_expect read_data:
ERROR:root:Retry send command 2 | display dfs-group m-lag brief | i Down\s+inactive(*)-inactive | hostname
ERROR:root:Exception happened while executing display dfs-group m-lag brief | i Down\s+inactive(*)-inactive on hostname and returned None

Which platform/device_type is this?

It looks like there are ANSI escape codes in the output:

DEBUG:netmiko:_read_channel_expect read_data: display dfs-group m-lag brief | i Down\s+inactive(*)-inac 锟絒1Dtive

This also could be due to line wrapping (potentially).

Which platform/device_type is this?

It looks like there are ANSI escape codes in the output:

DEBUG:netmiko:_read_channel_expect read_data: display dfs-group m-lag brief | i Down\s+inactive(*)-inac 锟絒1Dtive

This also could be due to line wrapping (potentially).

CE12808S/CE6875EI V5R5. VRP8.
It worked with 2.4.2.

What can we do? I can downgrade to 2.4.2 and get the same debug. Would it help?

huawei_vrpv8 device_type

Does Netmiko 3.0.0 work if you do this?

# Where net_connect is your Netmiko object
net_connect.ansi_escape_codes = True

Do this prior to sending this command:

display dfs-group m-lag brief | i Down\s+inactive(*)-inactive

Does Netmiko 3.0.0 work if you do this?

# Where net_connect is your Netmiko object
net_connect.ansi_escape_codes = True

Do this prior to sending this command:

display dfs-group m-lag brief | i Down\s+inactive(*)-inactive

Unfortunately not.

DEBUG:netmiko:write_channel: b'display dfs-group m-lag brief | include Down\s+inactive.inactive\n'
DEBUG:netmiko:Pattern is: display\ dfs-group\ m-lag\ brief\ \|\ include\ Down\s+inactive.*inactive
DEBUG:netmiko:In strip_ansi_escape_codes
DEBUG:netmiko:repr = 'display dfs-group m-lag brief | include Down\s+inactive.
ina \x1b[1Dctive\r\n'
DEBUG:netmiko:Stripping ANSI escape codes
DEBUG:netmiko:new_output = display dfs-group m-lag brief | include Down\s+inactive.*ina ctive

DEBUG:netmiko:repr = 'display dfs-group m-lag brief | include Down\s+inactive.ina \x1b[1Dctive\r\n'
DEBUG:netmiko:_read_channel_expect read_data: display dfs-group m-lag brief | include Down\s+inactive.
ina ctive

DEBUG:netmiko:In strip_ansi_escape_codes
DEBUG:netmiko:repr = '2020-03-06 21:24:11.230 +01:00\r\n* - Local node\r\n\r\nM-Lag ID Interface Port State Status Consistency-check\r\n 123 Eth-Trunk 123 Down inactive(*)-inactive -- \r\n'
DEBUG:netmiko:Stripping ANSI escape codes
DEBUG:netmiko:new_output = 2020-03-06 21:24:11.230 +01:00


    • Local node

M-Lag ID Interface Port State Status Consistency-check
123 Eth-Trunk 123 Down inactive(*)-inactive --

DEBUG:netmiko:repr = '2020-03-06 21:24:11.230 +01:00\r\n* - Local node\r\n\r\nM-Lag ID Interface Port State Status Consistency-check\r\n 123 Eth-Trunk 123 Down inactive(*)-inactive -- \r\n'
DEBUG:netmiko:_read_channel_expect read_data: 2020-03-06 21:24:11.230 +01:00


    • Local node

M-Lag ID Interface Port State Status Consistency-check
123 Eth-Trunk 123 Down inactive(*)-inactive --

DEBUG:netmiko:In strip_ansi_escape_codes
DEBUG:netmiko:repr = ''
DEBUG:netmiko:Stripping ANSI escape codes
DEBUG:netmiko:new_output =
DEBUG:netmiko:repr = ''
DEBUG:netmiko:_read_channel_expect read_data:

Okay, it looks like it is doing this for some reason (this ANSI escape code):

Esc[ValueD  Cursor Backward:
Moves the cursor back by the specified number of columns without changing 
lines. If the cursor is already in the leftmost column, ANSI.SYS ignores this sequence.

I will have to look into a fix.

Is this send_command() that you are using to execute the long command?

Okay, it looks like it is doing this for some reason (this ANSI escape code):

Esc[ValueD    Cursor Backward:
Moves the cursor back by the specified number of columns without changing 
lines. If the cursor is already in the leftmost column, ANSI.SYS ignores this sequence.

I will have to look into a fix.

Is this send_command() that you are using to execute the long command?

Yes, correct. I have found a workaround though.
I am checking if the interfaces in the first list are IN the second command's (the long command) plain text output.
What I have done to overcome this issue: I turned on TextFSM and removed the "| i long argument".
I created a function to put the stuff I was looking for in the plain text into a list, so I can get the same result. It's fine for now. I think only this long command breaks Netmiko.

PS: the send list of commands feature works now.

Thank you for your help!

@stvnkem You could also add the argument cmd_verify=False to send_command(). You would need to use the Netmiko develop branch for this, however.

That should also be included in the next release of Netmiko.

To Do:

  1. Enable ANSI code stripping.
  2. Add this ANSI escape code to the standard code stripping process:

Esc[ValueD Cursor Backward:

What does it do? Shall I add it to both TextFSM, and plain?
cmd_verify=False

BTW If you have some questions or need support/testing regarding Huawei VRP, I can help you in the future. I work for them. I have been in contact with R&D.

Netmiko in Netmiko 3.0.0 tries to verify the command echo. For example if you send something like:

show ip interface brief

It tries to verify this is properly echoed to the screen before moving on. This helps with a bunch of issues pertaining to slowness and to Netmiko losing the proper state of the session (i.e. thinking it is one state when it is not).

But it causes other problems (like the one here).

Consequently, you can add this argument to send_command to disable this behavior (i.e. it will no longer verify the command echo).

net_connect.send_command(command, cmd_verify=False)

Netmiko in Netmiko 3.0.0 tries to verify the command echo. For example if you send something like:

show ip interface brief

It tries to verify this is properly echoed to the screen before moving on. This helps with a bunch of issues pertaining to slowness and to Netmiko losing the proper state of the session (i.e. thinking it is one state when it is not).

But it causes other problems (like the one here).

Consequently, you can add this argument to send_command to disable this behavior (i.e. it will no longer verify the command echo).

net_connect.send_command(command, cmd_verify=False)

It broke the script. All commands were retried 3 times and eventually finished failed output.

Using the netmiko develop branch?

What exception did you get?

Using the netmiko develop branch?

What exception did you get?

Not sure. I do catch any exception.
How can I install it? netmiko develop branc

Also possibly add screen-width 512 (if it isn't already set...note, to myself).

It prompts though :-(

[eis-tze-02]screen-width 512   
Warning: This command will change the default screen width. Continue? [Y/N]:y
Info: Succeeded in setting the screen width to 512.
[eis-tze-02]

I probably ran into the same issue and tried the suggested cmd_verify=False which worked for me.

How can I install it? netmiko develop branch

run pip3 install git+https://github.com/ktbyers/netmiko.git to install the default/develop branch.

ktbyers is trying to fix this and I will test the fix.

Potential fix...if someone could test and post the results here:

https://github.com/ktbyers/netmiko/pull/1626

I think this PR should fix the issue...

https://github.com/ktbyers/netmiko/pull/1626

Was this page helpful?
0 / 5 - 0 ratings