ktbyers / nornir_netmiko

Netmiko Plugins for Nornir
Apache License 2.0
80 stars 24 forks source link

Replace config on a Huawei CE6850 switch #71

Closed rgrueebler closed 6 months ago

rgrueebler commented 6 months ago

Hi

I am trying to replace the config of a Huawei CE6850-48T4Q switch using this code:

result = device.run(task=netmiko_send_config, config_file=config_file, enable=True)

I kept the config_file as simple as possible. At the moment there is only one command in it:

sysname HUAWEI

When i execute the code I get the following error message:

Pattern not detected: '>' in output.

I don't understand if we are looking for '>' or if we are looking for something else but received '>'. My understanding is that with 'enable=True' we switch into system view, so we need to look for ']'. When I enter the command from the config_file into the CLI I get the following output:

<Huawei>system-view 
Enter system view, return user view with return command.
[~Huawei]sysname HUAWEI
[*Huawei]commit
[~HUAWEI]

Is there a debug mode where I can see the exact communication between nornir/netmiko and the device?

Thank you Remo

ktbyers commented 6 months ago

Can you do your code in straight Netmiko (i.e. with the equivalent Netmiko code) so I can see the exception? Alternatively, you can try to get the exception stack trace from Nornir logging (though probably easier/better to just test in Netmiko).

rgrueebler commented 6 months ago

Hi I've tried this code:

connection = ConnectHandler(
            host='10.0.0.1',
            port='22',
            username='test',
            password='test123',
            device_type='huawei',
            session_log='netmiko.log',
        )
        enable_mode = connection.enable()
        output = connection.send_command('sysname huawei')
        connection.disconnect()

This are the error logs:

Info: The max number of VTY users is 5, the number of current VTY users online is 1, and total number of terminal users online is 1.
      The current login time is 2024-03-01 10:48:55.
      The last login time is 2024-03-01 10:47:00 from 10.0.0.101 through SSH.
<HUAWEI>
<HUAWEI>
<HUAWEI>screen-length 0 temporary
Info: The configuration takes effect on the current user terminal interface only.
<HUAWEI>
<HUAWEI>sysname huawei
        ^
Error: Unrecognized command found at '^' position.
<HUAWEI>
<HUAWEI>quit

It looks like we don't enter enable mode (system-view). I've also tried this:

enable_mode = connection.enable()
        output = connection.send_config_set(['sysname huawei'])
        connection.disconnect()

which gives me the following logs:

<HUAWEI>
<HUAWEI>screen-length 0 temporary
Info: The configuration takes effect on the current user terminal interface only.
<HUAWEI>
<HUAWEI>system-view
Enter system view, return user view with return command.
[~HUAWEI]
[~HUAWEI]sysname huawei
[*HUAWEI]
[*HUAWEI]return
Warning: Uncommitted configurations found. Are you sure to commit them before exiting? [Y(yes)/N(no)/C(cancel)]:

Here we enter system-view but we don't commit the candidate config. So I've also tried this code:

enable_mode = connection.enable()
        output = connection.send_config_set(['sysname huawei', 'commit'])
        connection.disconnect()

And this are the logs:

<HUAWEI>
<HUAWEI>screen-length 0 temporary
Info: The configuration takes effect on the current user terminal interface only.
<HUAWEI>
<HUAWEI>system-view
Enter system view, return user view with return command.
[~HUAWEI]
[~HUAWEI]sysname huawei
[*HUAWEI]commit
[~huawei]

And this is the value of the 'output' variable:

netmiko.exceptions.ReadTimeout: 

Pattern not detected: '(?:HUAWEI.*$|#.*$)' in output.

Things you might try to fix this:
1. Adjust the regex pattern to better identify the terminating string. Note, in
many situations the pattern is automatically based on the network device's prompt.
2. Increase the read_timeout to a larger value.

The commit would work like this but we can't find the pattern so we hit a timeout. I've found a solution which kind of works:

enable_mode = connection.enable()
        output = connection.send_config_set(config_commands=['sysname HUAWEI', 'commit'], exit_config_mode=True)
        connection.disconnect()

The 'output' variable still contains 'Pattern not detected: '(?:huawei.$|#.$)' in output.' but the config change works on the switch.

Thanks Remo

ktbyers commented 6 months ago

@rgrueebler

Try using the 'huawei_vrpv8' device_type

          device_type='huawei_vrpv8',

And then

connection = ConnectHandler(
            host='10.0.0.1',
            port='22',
            username='test',
            password='test123',
            device_type='huawei_vrpv8',        # Change to vrpv8 to support 'commit'
            session_log='netmiko.log',
)
connection.enable()
output = connection.send_config_set(['sysname huawei'])
output += connection.commit()
connection.disconnect()

Let me know if that works.

rgrueebler commented 6 months ago

I've tested the device_type 'huawei_vrpv8' and it works.

Thank you for your help Remo