napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.26k stars 554 forks source link

Issues replacing device config using NAPALM #1499

Closed parth995 closed 2 years ago

parth995 commented 3 years ago

Description of Issue/Question

I am facing error replacing whole running config on IOS network device.

Note: Please check https://guides.github.com/features/mastering-markdown/ to see how to properly format your request.

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

(Place an x between the square brackets where applicable)

Setup

I have a cisco sandbox device running IOS XE and python script to restore device config from one pre-existing file storing running config of a device.

Code is as below : ` from napalm import get_network_driver import json

driver = get_network_driver('ios') device = driver(hostname='ios-xe-mgmt-latest.cisco.com', username='developer', password='C1sco12345', )

device.open()

device.load_replace_candidate(filename='run_config') print('\n Diff:') diff = device.compare_config() print(diff)

if len(diff) < 1: print('\nNo Changes Required Closing...') device.discard_config() exit()

try: choice = input("\nWould you like to Replace the Configuration file? [yN]: ") except NameError: choice = input("\nWould you like to Replace the Configuration file? [yN]: ") if choice == 'y': print('Committing ...') device.commit_config() else: print('Discarding ...') device.discard_config()

print('Done.') `

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

**napalm==3.3.1**

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

**Cisco IOS XE Software, Version 17.03.01a**

Steps to Reproduce the Issue

  1. Run python script using python3 test.py

Error Traceback

(Paste the complete traceback of the exception between quotes below)

Would you like to Replace the Configuration file? [yN]: y
Committing ...
Traceback (most recent call last):
  File "/Users/config-replace/test.py", line 29, in <module>
    device.commit_config()
  File "/Users/config-replace/lib/python3.9/site-packages/napalm/ios/ios.py", line 539, in commit_config
    raise ReplaceConfigException(msg)
napalm.base.exceptions.ReplaceConfigException: Candidate config could not be applied
Failed to apply command Welcome to the DevNet Sandbox for CSR1000v and IOS XE2
Aborting Rollback.

Rollback failed.Reverting back to the original configuration: bootflash:-Sep-20-17-13-29.123-2 ...

Total number of passes: 1
Rollback Done

The original configuration has been successfully restored.
ktbyers commented 3 years ago

Have you tried to manually execute a configure replace with the file ('run_config') that you are uploading?

parth995 commented 3 years ago

Hey @ktbyers , Thanks for your reply. I am not getting how you would like to test it manually. I have noticed a thing that it isn't able to apply banner motd which contains special chars symbols (^C).

Tried with one more device :-

napalm.base.exceptions.ReplaceConfigException: Candidate config could not be applied
Failed to apply command ^C
Aborting Rollback.
parth995 commented 3 years ago

I suspect issue is due to mentioned at https://napalm.readthedocs.io/en/latest/support/ios.html#banner Would you be able to share some way to tackle this ?

parth995 commented 3 years ago

So I tried it using ansible too. I got same error mentioned above (most probably due to banner motd message and special char ^C)

`

If I try to remove banner motd message from config file that i wanted to push and give a try it works like a charm

ktbyers commented 3 years ago

Have you removed the banner and observed whether the configuration change works or fails?

Also did you follow the instructions here for properly formatting the banner (it is tricky).

https://napalm.readthedocs.io/en/latest/support/ios.html#banner

parth995 commented 3 years ago

Yeah by removing banner it works fine and config is getting replaced. Let me try steps in that doc too

parth995 commented 3 years ago

Worried as this steps just appends a different banner motd message in file. How about eliminating existing banner motd message in our stored config which contains (^C) ?