Skip to content

Commit

Permalink
Backport nxos_file_copy fixes (#70075)
Browse files Browse the repository at this point in the history
Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
  • Loading branch information
NilashishC committed Jun 17, 2020
1 parent 1f3185d commit 7b1e2d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/fix_nxos_file_copy.yaml
@@ -0,0 +1,2 @@
bugfixes:
- Fix content encoding/decoding and do not fail when key based auth is used (https://github.com/ansible-collections/cisco.nxos/pull/59/).
13 changes: 9 additions & 4 deletions lib/ansible/plugins/action/nxos_file_copy.py
Expand Up @@ -144,14 +144,17 @@ def md5sum_check(self, dst, file_system):
filecontent = to_bytes(filecontent, errors='surrogate_or_strict')
local_filehash = hashlib.md5(filecontent).hexdigest()

if local_filehash == remote_filehash:
decoded_rhash = remote_filehash.decode("UTF-8")

if local_filehash == decoded_rhash:
return True
else:
return False

def remote_file_exists(self, remote_file, file_system):
command = 'dir {0}/{1}'.format(file_system, remote_file)
body = self.conn.exec_command(command)

if 'No such file' in body:
return False
else:
Expand Down Expand Up @@ -239,7 +242,7 @@ def copy_file_from_remote(self, local, local_file_directory, file_system):
self.results['failed'] = False
nxos_hostname = self.play_context.remote_addr
nxos_username = self.play_context.remote_user
nxos_password = self.play_context.password
nxos_password = self.play_context.password or ""
port = self.playvals['connect_ssh_port']

# Build copy command components that will be used to initiate copy from the nxos device.
Expand Down Expand Up @@ -318,8 +321,10 @@ def process_outcomes(session, timeout=None):
outcome['existing_file_with_same_name'] = True
return outcome
elif index in [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]:
before = session.before.strip().replace(' \x08', '')
after = session.after.strip().replace(' \x08', '')
decoded_before = session.before.decode("UTF-8")
decoded_after = session.after.decode("UTF-8")
before = decoded_before.strip().replace(" \x08", "")
after = decoded_after.strip().replace(" \x08", "")
outcome['error'] = True
outcome['error_data'] = 'COMMAND {0} ERROR {1}'.format(before, after)
return outcome
Expand Down

0 comments on commit 7b1e2d7

Please sign in to comment.