Skip to content

Commit

Permalink
Fix commit timeout failure issue for netconf modules
Browse files Browse the repository at this point in the history
Fixes ansible-collections/cisco.iosxr#74

*  ncclient API expects commit timeout value in either unicode
   or bytes format, hence convert the timeout value explicitly
   to string type.
  • Loading branch information
ganeshrn committed Aug 15, 2020
1 parent ea8c219 commit cc79480
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/iosxr_netconf_config_commit_fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Confirmed commit fails with TypeError in IOS XR netconf plugin (https://github.com/ansible-collections/cisco.iosxr/issues/74)
3 changes: 2 additions & 1 deletion lib/ansible/plugins/netconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from ansible.errors import AnsibleError
from ansible.plugins import AnsiblePlugin
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.basic import missing_required_lib

try:
Expand Down Expand Up @@ -269,6 +269,7 @@ def commit(self, confirmed=False, timeout=None, persist=None):
and set a token on the ongoing confirmed commit
:return: Returns xml string containing the RPC response received from remote host
"""
timeout = to_text(timeout, errors='surrogate_or_strict')
resp = self.m.commit(confirmed=confirmed, timeout=timeout, persist=persist)
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml

Expand Down
4 changes: 3 additions & 1 deletion lib/ansible/plugins/netconf/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import re
import collections

from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.network.common.netconf import remove_namespaces
from ansible.module_utils.network.iosxr.iosxr import build_xml, etree_find
from ansible.errors import AnsibleConnectionFailure
Expand Down Expand Up @@ -181,6 +181,8 @@ def edit_config(self, config=None, format='xml', target='candidate', default_ope
raise Exception(to_xml(exc.xml))

def commit(self, confirmed=False, timeout=None, persist=None, remove_ns=False):
timeout = to_text(timeout, errors='surrogate_or_strict')

try:
resp = self.m.commit(confirmed=confirmed, timeout=timeout, persist=persist)
if remove_ns:
Expand Down
20 changes: 20 additions & 0 deletions test/integration/targets/netconf_config/tests/iosxr/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,24 @@
that:
- "'backup_path' in result"

- name: test confirm commit
netconf_config:
target: "candidate"
error_option: "rollback-on-error"
commit: yes
confirm: 10
default_operation: "merge"
content: |
<nc:config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<cdp xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-cdp-cfg">
<enable>true</enable>
</cdp>
</nc:config>
register: result
ignore_errors: True

- assert:
that:
- "'failed' not in result"

- debug: msg="END netconf_config iosxr/basic.yaml on connection={{ ansible_connection }}"

0 comments on commit cc79480

Please sign in to comment.