napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

Second Deployment will fail if merge_config.txt or rollback_config.txt already exist #163

Closed sincerywaing closed 7 years ago

sincerywaing commented 7 years ago

Description of Issue/Question

The first time deployment works fine, however it leaves two files in flash: merge_config.txt rollback_config.txt if one want to do diff and rollback. Then above two files are never got deleted? Same code coming with a different command line deployment: code will crash if above two files are not deleted -

so is there a way to delete above two files before we do compare?

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

Setup

napalm-ios version

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

napalm-ios==0.6.2 napalm-iosxr==0.5.0

IOS version

(Paste verbatim output from show version between quotes below)

any ios

Steps to Reproduce the Issue

  1. open connection
  2. load merge candidate
  3. compare config
  4. commit config run same code again.

    Error Traceback

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

File "/usr/local/lib/python2.7/dist-packages/napalm_ios/ios.py", line 223, in load_merge_candidate file_system=self.dest_file_system) File "/usr/local/lib/python2.7/dist-packages/napalm_ios/ios.py", line 193, in _load_candidate_wrapper file_system=file_system) File "/usr/local/lib/python2.7/dist-packages/napalm_ios/ios.py", line 430, in _scp_file file_system=file_system, TransferClass=FileTransfer) File "/usr/local/lib/python2.7/dist-packages/napalm_ios/ios.py", line 481, in _xfer_file return (False, '') File "/usr/local/lib/python2.7/dist-packages/netmiko/scp_handler.py", line 87, in exit raise exc_type(exc_value) paramiko.ssh_exception.SSHException: SSH session not active

sincerywaing commented 7 years ago

I mean I can run delete command blindly before compare, but it just sounds not quite efficient? another idea would be append a date/time to the file name so it won't be same?

ktbyers commented 7 years ago

@sincerywaing Okay, I just did this and don't see an issue:

#!/usr/bin/env python

from netmiko import ConnectHandler
from napalm_base import get_network_driver
from getpass import getpass
from pprint import pprint as pp

def main():
    ip_addr = '10.10.10.70'
    username = 'pyclass'
    password = getpass()

    driver = get_network_driver('ios')
    device = driver(ip_addr, username, password)

    print()
    print(">>>Test device open")
    device.open()

    print()
    print(">>>Merge")
    device.load_merge_candidate(filename='merge.conf')
    print() 

    print(device.compare_config())

    print()
    print(">>>Commit config change (merge config)")
    device.commit_config()
    print()

    print()
    print(">>>Merge")
    device.load_merge_candidate(filename='merge2.conf')
    print() 

    print(device.compare_config())

    print()
    print(">>>Commit config change (merge config)")
    device.commit_config()
    print()

if __name__ == "__main__":
    main()
$ python ios_test_merge.py 
Password: 

>>>Test device open

>>>Merge

+logging buffered 7300

>>>Commit config change (merge config)

>>>Merge

+logging buffered 7200

>>>Commit config change (merge config)
ktbyers commented 7 years ago

Also your SSH session above indicates that the SSH session closed, it doesn't look like a file transfer issue?

File "/usr/local/lib/python2.7/dist-packages/netmiko/scp_handler.py", line 87, in exit
raise exc_type(exc_value)
paramiko.ssh_exception.SSHException: SSH session not active

It shouldn't care the files already exist, it will just overwrite them.

sincerywaing commented 7 years ago

thanks Kirk. Looks like ssh issue.