MemoryError when using netmiko_file_transfer task

Hi,

I was testing netmiko_file_transfer task on 10 switches but with some errors. The IOS file size is about 500mb and all devices are within the campus network with 10GB up-link to the core switch. Out of 12 devices, some encountered below error and the rest had “Socket is closed” exception. For those with “Socket is closed” exception, i suspect it’s due to exec-timeout of 5 mins.

The code I used is almost the same as the link below. I am using Nornir 2.3.0.

https://pynet.twb-tech.com/blog/nornir/os-upgrade-p1.html

SW1
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\nornir\core\task.py", line 85, in start
    r = self.task(self, **self.params)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\nornir\plugins\tasks\networking\netmiko_file_transfer.py", line 28, in netmiko_file_transfer
    net_connect, source_file=source_file, dest_file=dest_file, **kwargs
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\scp_functions.py", line 77, in file_transfer
    with TransferClass(**scp_args) as scp_transfer:
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\ssh_dispatcher.py", line 261, in FileTransfer
    return FileTransferClass(*args, **kwargs)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\scp_handler.py", line 80, in __init__
    self.source_md5 = self.file_md5(source_file)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\scp_handler.py", line 258, in file_md5
    file_contents = f.read()
MemoryError
--------------------------------------------------
--------------------------------------------------
Sw2
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\nornir\core\task.py", line 85, in start
    r = self.task(self, **self.params)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\nornir\plugins\tasks\networking\netmiko_file_transfer.py", line 28, in netmiko_file_transfer
    net_connect, source_file=source_file, dest_file=dest_file, **kwargs
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\scp_functions.py", line 77, in file_transfer
    with TransferClass(**scp_args) as scp_transfer:
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\ssh_dispatcher.py", line 261, in FileTransfer
    return FileTransferClass(*args, **kwargs)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\scp_handler.py", line 80, in __init__
    self.source_md5 = self.file_md5(source_file)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\netmiko\scp_handler.py", line 258, in file_md5
    file_contents = f.read()
MemoryError

I think the Memory Error issue was probably fixed in this Netmiko PR:

So you would need re-test using the Netmiko develop branch.

Thank you. It works.

1 Like