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

Implement Commit Confirm Support For Resource Modules #440

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelogs/fragments/add_commit_confirm_to_rm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
minor_changes:
rohitthakur2590 marked this conversation as resolved.
Show resolved Hide resolved
- check out the full motivation behind this enhancement(https://github.com/ansible-collections/junipernetworks.junos/issues/384).
rohitthakur2590 marked this conversation as resolved.
Show resolved Hide resolved
- ability to revert changes if the playbook executes multiple Junos modules in a row and results are undesired.
rohitthakur2590 marked this conversation as resolved.
Show resolved Hide resolved
- with task level var `ansible_junos_commit_confirmed` leverage upon confirm commit feature supported by junos.
rohitthakur2590 marked this conversation as resolved.
Show resolved Hide resolved
timer can be set with var `commit_confirmed_timeout`
- it can also help to reduce large CPU utilization when using single commit for mulitple tasks.
rohitthakur2590 marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions docs/junipernetworks.junos.junos_netconf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,45 @@ Parameters
<th>Configuration</th>
<th width="100%">Comments</th>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>commit_confirmed</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">boolean</span>
</div>
</td>
<td>
<b>Default:</b><br/><div style="color: blue">"no"</div>
</td>
<td>
<div>env:ANSIBLE_JUNOS_COMMIT_CONFIRMED</div>
<div>var: ansible_junos_commit_confirmed</div>
</td>
<td>
<div>enable or disable commit confirmed mode</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>commit_confirmed_timeout</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">integer</span>
</div>
</td>
<td>
</td>
<td>
<div>env:ANSIBLE_JUNOS_COMMIT_CONFIRMED_TIMEOUT</div>
<div>var: ansible_junos_commit_confirmed_timeout</div>
</td>
<td>
<div>Commits the configuration on a trial basis for the time specified in minutes.</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
27 changes: 25 additions & 2 deletions plugins/netconf/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@
netconf commands from Juniper JUNOS network devices.
version_added: 1.0.0
options:
commit_confirmed:
type: boolean
default: false
description:
- enable or disable commit confirmed mode
env:
- name: ANSIBLE_JUNOS_COMMIT_CONFIRMED
vars:
- name: ansible_junos_commit_confirmed
commit_confirmed_timeout:
type: int
description:
- Commits the configuration on a trial basis for the time specified in minutes.
env:
- name: ANSIBLE_JUNOS_COMMIT_CONFIRMED_TIMEOUT
vars:
- name: ansible_junos_commit_confirmed_timeout
ncclient_device_handler:
type: str
default: junos
Expand Down Expand Up @@ -267,6 +284,8 @@ def commit(
obj = new_ele("commit-configuration")
if confirmed:
sub_ele(obj, "confirmed")
elif self.get_option("commit_confirmed"):
sub_ele(obj, "confirmed")
if check:
sub_ele(obj, "check")
if synchronize:
Expand All @@ -277,7 +296,11 @@ def commit(
if comment:
subele = sub_ele(obj, "log")
subele.text = str(comment)
if timeout:
if self.get_option("commit_confirmed_timeout"):
subele = sub_ele(obj, "confirm-timeout")
subele.text = str(timeout)
subele.text = str(self.get_option("commit_confirmed_timeout"))
else:
if timeout:
subele = sub_ele(obj, "confirm-timeout")
subele.text = str(timeout)
return self.rpc(obj)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
- ansible.builtin.debug:
msg: START ios_cliconf integration tests on connection={{ ansible_connection }}

- name: Reset
junipernetworks.junos.junos_hostname:
state: deleted

- name: Verify hostname changed immediately
register: get_hostname
junipernetworks.junos.junos_hostname:
state: gathered

- name: Change hostname with commit_confirm_immediate true and timer 2 minutes
vars:
ansible_junos_commit_confirmed: true
ansible_junos_commit_confirmed_timeout: 2
junipernetworks.junos.junos_hostname:
state: merged
config:
hostname: testConfirmCommitAppliance

- name: Gather hostname
register: get_hostname
junipernetworks.junos.junos_hostname:
state: gathered

- name: Assert that the hostname is correctly set
ansible.builtin.assert:
that:
- "'testConfirmCommitAppliance' == get_hostname.gathered.hostname"

- name: Sleep for 300 seconds and continue with play
ansible.builtin.wait_for:
timeout: 150
delegate_to: localhost

- name: Verify hostname change is persistent even after timeout
register: get_hostname
junipernetworks.junos.junos_hostname:
state: gathered

- name: Assert that the hostname is correctly set
ansible.builtin.assert:
that:
- "{} == get_hostname.gathered"

- name: Clenup
junipernetworks.junos.junos_hostname:
state: deleted
Loading