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

Fix in confirmed_commit capability in netconf_config modules #46964

Merged
merged 3 commits into from
Oct 15, 2018
Merged
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
18 changes: 12 additions & 6 deletions lib/ansible/modules/network/netconf/netconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
commit:
description:
- This boolean flag controls if the configuration changes should be committed or not after editing the
candidate datastore. This oprion is supported only if remote Netconf server supports :candidate
candidate datastore. This option is supported only if remote Netconf server supports :candidate
capability. If the value is set to I(False) commit won't be issued after edit-config operation
and user needs to handle commit or discard-changes explicitly.
type: bool
Expand Down Expand Up @@ -305,8 +305,8 @@ def main():
if confirm_commit and not operations.get('supports_confirm_commit', False):
module.fail_json(msg='confirm commit is not supported by Netconf server')

if confirm_commit or (confirm > 0) and not operations.get('supports_confirm_commit', False):
module.fail_json(msg='confirm commit is not supported by this netconf server')
if (confirm > 0) and not operations.get('supports_confirm_commit', False):
module.fail_json(msg='confirm commit is not supported by this netconf server, given confirm timeout: %d' % confirm)

if validate and not operations.get('supports_validate', False):
module.fail_json(msg='validate is not supported by this netconf server')
Expand All @@ -323,6 +323,7 @@ def main():

result = {'changed': False, 'server_capabilities': capabilities.get('server_capabilities', [])}
before = None
after = None
locked = False
try:
if module.params['backup']:
Expand Down Expand Up @@ -362,15 +363,20 @@ def main():
'error_option': module.params['error_option'],
'format': module.params['format'],
}

conn.edit_config(**kwargs)

if supports_commit and module.params['commit']:
after = to_text(conn.get_config(source='candidate'), errors='surrogate_then_replace').strip()
if not module.check_mode:
timeout = confirm if confirm > 0 else None
conn.commit(confirmed=confirm_commit, timeout=timeout)
confirm_timeout = confirm if confirm > 0 else None
confirmed_commit = True if confirm_timeout else False
conn.commit(confirmed=confirmed_commit, timeout=confirm_timeout)
else:
conn.discard_changes()

after = to_text(conn.get_config(source='running'), errors='surrogate_then_replace').strip()
if after is None:
after = to_text(conn.get_config(source='running'), errors='surrogate_then_replace').strip()

sanitized_before = sanitize_xml(before)
sanitized_after = sanitize_xml(after)
Expand Down