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

Junos_config unicode #23369

Merged
merged 6 commits into from
Apr 27, 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
6 changes: 3 additions & 3 deletions lib/ansible/module_utils/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ansible.module_utils.netconf import send_request, children
from ansible.module_utils.netconf import discard_changes, validate
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_text

ACTIONS = frozenset(['merge', 'override', 'replace', 'update', 'set'])
JSON_ACTIONS = frozenset(['merge', 'override', 'update'])
Expand Down Expand Up @@ -111,7 +112,7 @@ def load_configuration(module, candidate=None, action='merge', rollback=None, fo
if format == 'xml':
cfg.append(fromstring(candidate))
else:
cfg.text = candidate
cfg.text = to_text(candidate, encoding='latin1')
else:
cfg.append(candidate)
return send_request(module, obj)
Expand Down Expand Up @@ -163,7 +164,7 @@ def get_diff(module):
reply = get_configuration(module, compare=True, format='text')
output = reply.find('.//configuration-output')
if output is not None:
return output.text
return to_text(output.text, encoding='latin1').strip()

def load_config(module, candidate, warnings, action='merge', commit=False, format='xml',
comment=None, confirm=False, confirm_timeout=None):
Expand All @@ -180,7 +181,6 @@ def load_config(module, candidate, warnings, action='merge', commit=False, forma
diff = get_diff(module)

if diff:
diff = str(diff).strip()
if commit:
commit_configuration(module, confirm=confirm, comment=comment,
confirm_timeout=confirm_timeout)
Expand Down
5 changes: 3 additions & 2 deletions lib/ansible/modules/network/junos/junos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
from ansible.module_utils.junos import check_args as junos_check_args
from ansible.module_utils.netconf import send_request
from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_text, to_native

USE_PERSISTENT_CONNECTION = True
DEFAULT_COMMENT = 'configured by junos_config'
Expand Down Expand Up @@ -231,7 +232,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 = str(match.text)
config = to_native(match.text, encoding='latin1')

modified_candidate = candidate[:]
for index, line in enumerate(candidate):
Expand Down Expand Up @@ -324,7 +325,7 @@ def main():
else:
module.fail_json(msg='unable to retrieve device configuration')

result['__backup__'] = str(match.text).strip()
result['__backup__'] = match.text.strip()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle similar fix for junos_template as well?
Also, require separate handling for load of backup config with unicode string.


if module.params['rollback']:
if not module.check_mode:
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/plugins/action/junos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +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.utils.vars import merge_hash

PRIVATE_KEYS_RE = re.compile('__.+__')
Expand Down Expand Up @@ -74,7 +75,7 @@ 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(contents)
open(filename, 'w').write(to_native(contents, encoding='latin1'))
return filename

def _handle_template(self):
Expand Down Expand Up @@ -110,4 +111,3 @@ def _handle_template(self):
searchpath.append(os.path.dirname(source))
self._templar.environment.loader.searchpath = searchpath
self._task.args['src'] = self._templar.template(template_data)

1 change: 0 additions & 1 deletion test/sanity/pep8/legacy-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ lib/ansible/plugins/action/group_by.py
lib/ansible/plugins/action/ios_template.py
lib/ansible/plugins/action/iosxr_template.py
lib/ansible/plugins/action/junos.py
lib/ansible/plugins/action/junos_config.py
lib/ansible/plugins/action/junos_template.py
lib/ansible/plugins/action/normal.py
lib/ansible/plugins/action/nxos.py
Expand Down