-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file_copy.py error #22
Comments
@aroramanish2009 Thanks for finding this. We are having trouble reproducing this. Can you give some more information about your environment? What platform and software version are you using on the Nexus switch? |
hi @mzbenami |
@aroramanish2009 Hmm, we tested on that platform with no errors. I see you are using the Ansible module. Can you share what parameters you are passing for source_file and dest_file? Are there any special characters or spaces in those parameters? The device should always return a 'body' tag, even if the file doesn't exist. The only time it wouldn't, from our testing, is if there's an error. The only way we can see an error being generated on the command is if the file name has something unexpected about it, like special characters or spaces. |
Here's the Error again: File: nxos.7.0.3.I2.2.bin Here's Ansible Task: The above task works just fine when I changed your to : Also, the content of body was just the MD5 of the file. |
@aroramanish2009 Are you able to go to the API sandbox through your browser and try the command in the screenshot below and let me know your output. As you see in the shot below, we have the same file on the same software version, and the md5sum is returned in the Are you saying your fix works even when the file is already copied, meaning that Ansible doesn't transfer the file if it is already there? I can see your fix working, but causing Ansible to always transfer the file no matter what. |
@aroramanish2009 Sorry can you do it one more time with message format set to "XML" and and command type set to "cli_show". The library is using XML. |
It is confirmed that the code breaks when using "NXOS: version 7.0(3)I1(2)" even though NXAPI version is same for I1(2) and I2(2).
The code fails to work when file is already present and I am using "NXOS: version 7.0(3)I1(2)", for now I am using the work around to check for file. |
Latest update to fix the code for both versions, might not be completely optimal but works well :-)
Please let me know if you come up with better solution. |
@aroramanish2009 I put a fix in this branch https://github.com/jedelman8/pycsco/tree/file_copy_bug_fix. Are you able to test it? |
@mzbenami |
@mzbenami
|
@aroramanish2009 It's not clear for whether a I understand that fix you gave works for you, but it would break the idempotency of the Ansible module. In the case of the How did you install the fix I provided? You would need to clone the whole branch and run |
I can try to clone the repo and use setup.py ( yes, it would help a lot if you can provide some detailed instructions). |
@aroramanish2009 No problem it would be something like this:
|
@mzbenami |
I'm seeing this issue as well when trying to copy a file that doesn't already exist on the switch. I just pulled the latest copy of pycsco, and I still have the issue. Upgrading NXOS on our switches is planned, but not going to happen right now. What are my options? |
I'm going to try the ugly hack of having an ansible task that ensures the file is absent, then remove the |
I'd actually recommend checking out one of these (plan is to maintain these more going forward): https://github.com/networktocode/pyntc (uses pynxos below)
Supports NXOS and IOS too:
Can you try this? |
Any luck @robertwatson3 ? |
I'm using nxos-ansible, so I'd need to switch to ntc-ansible. My hack works for now, so I'm going to roll with it. I'll move on to ntc-ansible (and therefore pyntc) on the next project. |
Hi,
I was getting the following error when trying to use file_copy.py.
'''
failed: [10.x.x.55] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File "/home/manish/.ansible/tmp/ansible-tmp-1450376959.58-153940520304606/nxos_file_copy", line 1761, in
main()
File "/home/manish/.ansible/tmp/ansible-tmp-1450376959.58-153940520304606/nxos_file_copy", line 136, in main
if not fc.file_already_exists():
File "/usr/lib/python2.7/site-packages/pycsco/nxos/utils/file_copy.py", line 57, in file_already_exists
dst_hash = self.get_remote_md5()
File "/usr/lib/python2.7/site-packages/pycsco/nxos/utils/file_copy.py", line 82, in get_remote_md5
md5_body = md5_dict['ins_api']['outputs']['output']['body']
KeyError: 'body'
'''
Resolved by making following changes :
'''
def get_remote_md5(self):
"""Return the md5 sum of the remote file,
if it exists.
"""
md5_dict = xmltodict.parse(self.device.show(
'show file {0} md5sum'.format(self.dst), text=False)[1])
#md5_body = md5_dict['ins_api']['outputs']['output']['body']
md5_body = md5_dict['ins_api']['outputs']['output']
if md5_body:
#return md5_body['file_content_md5sum']
return md5_body
'''
Thanks
The text was updated successfully, but these errors were encountered: