Netmiko: Huawei SmartAX 5800 - How to get around no terminal width

Created on 19 Mar 2020  路  20Comments  路  Source: ktbyers/netmiko

Hey, firstly: Thanks so much for your time and investment into Netmiko, did you wonder if it would be used this much? 馃槃

Unfortunately, Huawei SmartAX (not so smart) do not support to disable paging and I always run into issues because I need to send a space (enter will only output another line of config). I've managed to easily figure out how to overcome this issue and get around it manually but would like to implement it in my base class that I've created for the SmartAX.

The problem also occurs sometimes when sending a command, I might get an output like this:

mydevice.test.lab#display current-configuration
{ <cr>|ont<K>|port<K>|section<K>|service-port<K>|simple<K>||<K> }:

So I have to manually send an enter. I'm looking how to implement this possibly in the send_command function, would you recommend that? or in the find_prompt function? Mainly to match '{

When I hit the paging limit (I know, they should just be able to properly implement SSH with no paging, but I'm trying my best here to work around it haha), I see things like:

"---- More ( Press 'Q' to break ) ----"

Which I need to send a space (not return because it only shows 1 line at a time with return)... I've got round this all by simply using the read_channel and catching if these appear in the output, then send enter/or space depending on which one appears...

I've looked a little into it myself but hope you don't mind me posting this to point me in the right direction so I can figure out the rest? Thanks again for all your fantastic work

All 20 comments

Excuse me for not giving any examples of my workarounds, here is an example I use to get past those two above I mentioned to run

display current-configuration
            cmd = "display current-configuration"
            output = session.send_command_timing(cmd)

            if r"{ <cr>" in output:
                output += session.send_command_timing(" ")

            #Manual loop through until SSH channel no longer displays "---- More" output
            #Max loops of 20 assumes a couple thousand lines of configuration which should be more than enough...
            max_loops = 20
            loop_counter = 0

            while loop_counter < max_loops:
                session.write_channel(" ") #Manually write space to ssh channel to produce more output
                time.sleep(1) #Sleep for 1 second, since data will not appear in the read_channel straight away
                new_data = session.read_channel()

                if r"---- More" in new_data: #--- More string means more configuration is yet to be displayed...
                    print("============ FOUND NEW DATA ============")
                    output += new_data #append new data to previous data we already have
                    loop_counter += 1
                else:
                    output += new_data #Get last output
                    break

            return output

Excuse the awful code 馃槀

After a bit of playing around, I copied the send_command from the base_connection into my new device type in huawei.py

During the while loop that tries to keep reading until search_pattern is found, I've added 2 if statements where the comments regarding SmartAX are located:

# Keep reading data until search_pattern is found or until max_loops is reached.
        while i <= max_loops:
            if new_data:
                output += new_data
                past_three_reads.append(new_data)

                # Case where we haven't processed the first_line yet (there is a potential issue
                # in the first line (in cases where the line is repainted).
                if not first_line_processed:
                    output, first_line_processed = self._first_line_handler(
                        output, search_pattern
                    )
                    # Check if we have already found our pattern
                    if re.search(search_pattern, output):
                        break

                else:
                    # Check if pattern is in the past three reads
                    if re.search(search_pattern, "".join(past_three_reads)):
                        break

            if r"{ <cr" in new_data:
                log.debug("Found pattern { <cr in read_channel")
                self.write_channel("\n") #Send Enter to continue in Huawei SmartAX Prompt

            if r"---- More" in new_data:
                log.debug("Found pattern '---- More' in read_channel")
                self.write_channel(" ") #Send Space to continue getting output... This is required on SmartAX devices because they can't fully disable the Paging

            time.sleep(delay_factor * loop_delay)
            i += 1
            new_data = self.read_channel()

That seems to handle most things I chuck at it, however not sure if there is a better way to catch this kind of stuff...

I also run into issues running the py.test with send_command_timing -

(venv_netmiko) [brandon@server cfl_netmiko]$ py.test -v netmiko/tests/test_netmiko_show.py --test_device huawei_olt

TypeError: send_command_timing() got an unexpected keyword argument 'cmd_verify'

If I remove cmd_verify=True from the test_netmiko_show.py, It works and I have 1 more error to figure out regarding the base_prompt...

I'm obviously doing something wrong? :joy:

I don't think I am willing to support this platform on the Netmiko side. It just looks too fundamentally broken (as far as their OS implementation). Not having a way to disable output paging causes a lot of things to break.

You are obviously welcome to create and maintain your own driver.

cmd_verify is a new argument that was recently added to send_command. You should probably do something like **kwargs in the set of arguments you allow (so you can allow additional new arguments as they are added).

Regards, Kirk

Hello,

I am from Huawei. I can ask our R&D to support the disable paging feature.
First of all, I will confirm if the feature is really unsupported. (I guess there is another command to do it). Anyhow, I do agree with the config and display output structure is far behind VRP.

Please try to apply the command: " scroll " without any arguments. This is the equivalent to " screen-length 0 temporary "

disable paging:
huawei>scroll

enable paging:
huawei>undo scroll

@stvnkem Okay, great...yeah, if we can do that...then we should be able to create a reasonable Netmiko driver.

@ktbyers @stvnkem I've just tried this and it works as intended on a range of MA5800s and MA5603Ts

However with netmiko, when you disable_paging, still need to send a return after scroll because of the prompt as shown below:

huawei.test-lab.xyz>scroll
{ <cr>|number<U><10,512> }:

@BSpendlove Can you expand on that? I am not sure I understand that?

@ktbyers Of course!

It seems that if you type a command in the terminal that could have additional input, eg. scroll it won't send the command until you send a carriage return. Take this command for example:

huawei.test-lab.xyz>display version ?
---------------------------------------------
  Command of user Mode:
---------------------------------------------
<cr>                  Please press ENTER to execute command 
backplane             Backplane version
frameid/slotid<S><Length 1-15>
                      Parameter: FrameID/SlotID

Sending the command:

huawei.test-lab.xyz>display version 
{ <cr>|backplane<K>|frameid/slotid<S><Length 1-15> }:

After sending display version, you kind of need to confirm the command by pressing enter which will then work if that makes more sense? So in terms of the disable_paging, it's like you have to:
1) write_channel("scroll")
2) Get the output and check if <cr> appears
3) If <cr> does appear in the output, write_channel("\n")

So you have to send enter twice? Just to verify.

Yeah that's correct, 1st enter is the initial command and then 2nd enter is to get past that curley brace prompt

@BSpendlove And you have to do this for every command and there is no way to disable this behavior?

Adding @stvnkem also.

Pretty much any command that has optional inputs:

I hope my below example is clear enough

huawei.test-lab.xyz(config)#sysname test   !Enter once works

test(config)#display time  !Enter once
{ <cr>|date-format<K>|dst<K>|time-stamp<K> }:  !Enter twice
!output shows here after 2nd enter

This isn't just on display commands, I lot of commands that I've tried have this behaviour and I don't know a way to disable the behaviour, hopefully @stvnkem does? 馃槂

@BSpendlove I am trying to find a solution. Please post the full display version output.
Is it 5800 or 5600?

@stvnkem Fantastic, please see below (MA5603T):

ma5603test>enable

ma5603test#display version
{ <cr>|backplane<K>|frameid/slotid<S><Length 1-15> }:

  Command:
          display version 

  VERSION : MA5600V800R018C10
  PATCH   : SPH206 HP2013
  PRODUCT : MA5603T

  Active Mainboard Running Area Information: 
  --------------------------------------------------
  Current Program Area : Area B 
  Current Data Area : Area B 

  Program Area A Version : MA5600V800R018C10 
  Program Area B Version : MA5600V800R018C10 

  Data Area A Version : MA5600V800R018C10 
  Data Area B Version : MA5600V800R018C10 
  --------------------------------------------------

  Uptime is 116 day(s), 20 hour(s), 1 minute(s), 50 second(s)

and an MA5800-X7 as shown below:
```ma5800test>enable

ma5800test#display version
{ |backplane|frameid/slotid|| }:

Command:
display version
VERSION : MA5800V100R017C00
PATCH : SPC202
PRODUCT : MA5800-X7

Active Mainboard Running Area Information:


Current Program Area : Area B
Current Data Area : Area B

Program Area A Version : MA5800V100R017C00
Program Area B Version : MA5800V100R017C00

Data Area A Version : MA5800V100R017C00
Data Area B Version : MA5800V100R017C00


Standby Mainboard Running Area Information:


Current Program Area : Area B
Current Data Area : Area B

Program Area A Version : MA5800V100R017C00
Program Area B Version : MA5800V100R017C00

Data Area A Version : MA5800V100R017C00
Data Area B Version : MA5800V100R017C00


Uptime is 423 day(s), 19 hour(s), 36 minute(s), 1 second(s)
```

The smart command is used to enable interactive operation. After that, if you input a command and press Enter, the system determines whether the keywords and parameters of the command are complete. If not, the system prompts you to enter the complete parameters. Meanwhile, the system displays the value range of the current parameters. If yes, the system runs the command.
The "undo smart" command is used to disable the interactive operation. After that, the system runs the command instantly after you input a command and press Enter.

@BSpendlove Please have a try!

@stvnkem Fantastic, that looks like it is working as expected.

@ktbyers This seems to solve it, I've deleted everything I had and just implemented a function disable_smart_interaction which runs before disable_paging in the session preparation. Very handy that the undo smart command doesn't actually have any interactive operation so it works without having to send a 2nd return 馃榾

Just have to figure out returning the output after a wrong command/or config that already exist on the device. running into _read_channel_expect errors even though I can see the prompt:

  Failure: The traffic table exists already

huawei.test-lab.xyz(config)#
File "/home/brandon/dev/git/netmiko/netmiko/netmiko/base_connection.py", line 561, in _read_channel_expect
    "Timed-out reading channel, data not available."
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

@ktbyers Hey hope you are doing well, just wondering if you've seen this anywhere?

I can use send_command or send_config_set which succeeds in sending the first command to the device but when it tries to read the channel, I can see the prompt but looks like it gets stuck at _read_channel_expect.

If I stick to normal global_delay_factor I get back this:

DEBUG:netmiko:write_channel: b'traffic table ip index 110 name "test_001" cir 123 fix 123 pir 123 color-mode color-blind priority 0 priority-policy local-setting\n'
DEBUG:netmiko:Pattern is: traffic\ table\ ip\ index\ 110\ name\ \"test_001\"\ cir\ 123\ fix\ 123\ pir\ 123\ color\-mode\ color\-blind\ priority\ 0\ priority\-policy\ local\-setting
DEBUG:netmiko:_read_channel_expect read_data: t
DEBUG:netmiko:_read_channel_expect read_data: raffic table ip
DEBUG:netmiko:_read_channel_expect read_data:  index 110 name
DEBUG:netmiko:_read_channel_expect read_data:  "test_001" cir 
DEBUG:netmiko:_read_channel_expect read_data:  123 fix 12
DEBUG:netmiko:_read_channel_expect read_data: 3 pir 123 c
DEBUG:netmiko:_read_channel_expect read_data: olor-mode color-blind
DEBUG:netmiko:_read_channel_expect read_data:  priority 0 prio
DEBUG:netmiko:_read_channel_expect read_data: rity-policy local-setting
  Failure: The traffic table exists already
DEBUG:netmiko:_read_channel_expect read_data: 

huawei.test-lab.xyz(config)#

However, if I increase the global_delay_factor to something like 10, I get this:

DEBUG:netmiko:write_channel: b'traffic table ip index 110 name "test_001" cir 123 fix 123 pir 123 color-mode color-blind priority 0 priority-policy local-setting\n'
DEBUG:netmiko:Pattern is: traffic\ table\ ip\ index\ 110\ name\ \"test_001\"\ cir\ 123\ fix\ 123\ pir\ 123\ color\-mode\ color\-blind\ priority\ 0\ priority\-policy\ local\-setting
DEBUG:netmiko:_read_channel_expect read_data: tr
DEBUG:netmiko:_read_channel_expect read_data: affic table ip index 110 name "test_001" cir 123 fix 123 pir 123
DEBUG:netmiko:_read_channel_expect read_data:  color-mode color-blind priority 0 priority-policy local-setting
  Failure: The traffic table exists already

huawei.test-lab.xyz(config)#

I can see the prompt but don't understand where the _read_channel_expect is timing out...

Apologies! I've managed to get it working now :D Same issue as in the HuaweiBase class with the strip_ansi_escape_codes. After fixing some of the pattern/check_string for the different modes, it works as expected. Going to do some intensive testing 馃憤

Okay, great...thanks @BSpendlove and @stvnkem !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

edurguti picture edurguti  路  7Comments

ktbyers picture ktbyers  路  5Comments

ktbyers picture ktbyers  路  7Comments

MichalTaratuta picture MichalTaratuta  路  7Comments

Rooster-OC picture Rooster-OC  路  5Comments