Skip to content
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

Ensure proper conversion while backing up of junos config #28958

Merged
merged 3 commits into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ansible/module_utils/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def load_configuration(module, candidate=None, action='merge', rollback=None, fo
if format == 'xml':
cfg.append(fromstring(candidate))
else:
cfg.text = to_text(candidate, encoding='latin1')
cfg.text = to_text(candidate, encoding='latin-1')
else:
cfg.append(candidate)
return send_request(module, obj)
Expand Down Expand Up @@ -187,7 +187,7 @@ def get_diff(module):

output = reply.find('.//configuration-output')
if output is not None:
return to_text(output.text, encoding='latin1').strip()
return to_text(output.text, encoding='latin-1').strip()


def load_config(module, candidate, warnings, action='merge', format='xml'):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/network/junos/junos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def filter_delete_statements(module, candidate):
if match is None:
# Could not find configuration-set in reply, perhaps device does not support it?
return candidate
config = to_native(match.text, encoding='latin1')
config = to_native(match.text, encoding='latin-1')

modified_candidate = candidate[:]
for index, line in reversed(list(enumerate(candidate))):
Expand Down
5 changes: 3 additions & 2 deletions lib/ansible/plugins/action/junos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ansible.plugins.action.junos import ActionModule as _ActionModule
from ansible.module_utils._text import to_text
from ansible.module_utils.six.moves.urllib.parse import urlsplit
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_bytes
from ansible.utils.vars import merge_hash

PRIVATE_KEYS_RE = re.compile('__.+__')
Expand Down Expand Up @@ -75,7 +75,8 @@ def _write_backup(self, host, contents):
os.remove(fn)
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
open(filename, 'w').write(to_native(contents, encoding='latin1'))
with open(filename, 'wb') as f:
f.write(to_bytes(to_text(contents, encoding='latin-1'), encoding='utf-8'))
return filename

def _handle_template(self):
Expand Down