-
Notifications
You must be signed in to change notification settings - Fork 119
fix(netconf_config.py): type conversion issue for confirm_timeout #689
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
base: main
Are you sure you want to change the base?
Conversation
Voici un message de commit clair et concis pour ton pull request : Ensure confirm_timeout is correctly converted to a string using `to_text()` to prevent type mismatches. This resolves errors like `Argument must be bytes or unicode, got 'int'` when using commit confirmation. Change applied in line 669: - `confirmed=confirmed_commit, timeout=confirm_timeout` + `confirmed=confirmed_commit, timeout=to_text(confirm_timeout, errors='surrogate_or_strict')`
for more information, see https://pre-commit.ci
|
Hi, Problems observed with the current PR implementation1.
|
Correction regarding
|
|
Hello, After a thorough review of the issue, I'd like to provide some context and clarification regarding the behavior of the Background: IOS-XE and NETCONF commit supportTo the best of my knowledge, Cisco IOS-XE does not support the standard NETCONF Analysis of ncclient ImplementationDespite this limitation, Here is the relevant part of the class Commit(RPC):
DEPENDS = [':candidate']
def request(self, confirmed=False, timeout=None, persist=None, persist_id=None):
node = new_ele("commit")
if confirmed:
self._assert(":confirmed-commit")
sub_ele(node, "confirmed")
if timeout is not None:
sub_ele(node, "confirm-timeout").text = timeout
# ... other fields
return self._request(node)This generates a well-formed, RFC-compliant XML payload such as: <commit>
<confirmed />
<confirm-timeout>120</confirm-timeout>
</commit>The XML structure itself is correct - the issue does not lie in Root cause of the current bugThe actual problem occurs in Ansible’s Since TypeError: cannot serialize 120 (type int)This causes the task to fail before the RPC is even sent - regardless of whether the device supports the operation. Solution and testingThe fix proposed by @jclaerhout addresses this by explicitly converting I have tested this change on a device that does support candidate configurations and confirmed commit (e.g., SROS), and it works as expected - the correct XML is generated and the operation succeeds. ConclusionWhile IOS-XE may not support confirmed commits due to lack of Therefore, I recommend merging the proposed change, as it:
Without this fix, users are unable to use the Could we please move forward with this merge request? Thank you! |
SUMMARY
This pull request fixes a type conversion issue in the
netconf_configmodule of theansible.netcommoncollection.When using the
confirmparameter, Ansible throws an error due to a type mismatch:This occurs because
confirm_timeout, which is expected to be an integer, is not properly converted before being passed to the NETCONF commit operation.The fix ensures
confirm_timeoutis explicitly converted to a string usingto_text()witherrors='surrogate_or_strict'before passing it to the commit operation.Fixes #551
ISSUE TYPE
COMPONENT NAME
ansible.netcommon.netconf_configADDITIONAL INFORMATION
The issue occurs when attempting to use
confirminansible.netcommon.netconf_config, leading to a failure due to incorrect type handling.Code Change (Line 669 of
netconf_config.py):This fix ensures proper type handling and allows users to correctly perform confirmed commits with rollback timers.
References:
Let me know if any further modifications are required! 🚀