From 865f2c5990554e51e412f8c3748ff0e6fc29f59c Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Wed, 16 May 2018 18:14:23 +0530 Subject: [PATCH] Fix junos_config confirm timeout issue (#40238) * Fix junos_config confirm timeout issue * Fix unit test --- lib/ansible/modules/network/junos/junos_config.py | 7 ++++--- test/units/modules/network/junos/test_junos_config.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/network/junos/junos_config.py b/lib/ansible/modules/network/junos/junos_config.py index 894d849875b..c04ac5c6ee1 100644 --- a/lib/ansible/modules/network/junos/junos_config.py +++ b/lib/ansible/modules/network/junos/junos_config.py @@ -184,7 +184,7 @@ from ansible.module_utils.network.junos.junos import get_diff, load_config, get_ from ansible.module_utils.network.junos.junos import commit_configuration, discard_changes, locked_config from ansible.module_utils.network.junos.junos import junos_argument_spec, load_configuration, get_connection, tostring from ansible.module_utils.six import string_types -from ansible.module_utils._text import to_native +from ansible.module_utils._text import to_native, to_text try: from lxml.etree import Element, fromstring @@ -362,10 +362,11 @@ def main(): 'comment': module.params['comment'] } - if module.params['confirm'] > 0: + confirm = module.params['confirm'] + if confirm > 0: kwargs.update({ 'confirm': True, - 'confirm_timeout': module.params['confirm'] + 'confirm_timeout': to_text(confirm, errors='surrogate_then_replace') }) commit_configuration(module, **kwargs) else: diff --git a/test/units/modules/network/junos/test_junos_config.py b/test/units/modules/network/junos/test_junos_config.py index 7d1a751d8fb..d42dcacccea 100644 --- a/test/units/modules/network/junos/test_junos_config.py +++ b/test/units/modules/network/junos/test_junos_config.py @@ -23,6 +23,7 @@ __metaclass__ = type from ansible.compat.tests.mock import patch from ansible.modules.network.junos import junos_config from units.modules.utils import set_module_args +from ansible.module_utils._text import to_text from .junos_module import TestJunosModule, load_fixture @@ -118,7 +119,7 @@ class TestJunosConfigModule(TestJunosModule): set_module_args(dict(src=src, confirm=40)) self.execute_module(changed=True) args, kwargs = self.commit_configuration.call_args - self.assertEqual(kwargs['confirm_timeout'], 40) + self.assertEqual(kwargs['confirm_timeout'], to_text(40)) def test_junos_config_rollback(self): rollback = 10