Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
Signed-off-by: rohitthakur2590 <[email protected]>
  • Loading branch information
rohitthakur2590 committed Jan 4, 2024
1 parent 1420644 commit c68972e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
52 changes: 52 additions & 0 deletions docs/arista.eos.eos_config_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,58 @@ Parameters
<div>The ordered set of commands to push on to the command stack if a change needs to be made. This allows the playbook designer the opportunity to perform configuration commands prior to pushing any changes without affecting how the set of commands are matched against the system.</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>context_diff</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">dictionary</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify the off-box diff options</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>context_lines</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>Specify The number of context lines, by default it includes all lines.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>enable</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>
<ul style="margin: 0; padding: 0"><b>Choices:</b>
<li>no</li>
<li>yes</li>
</ul>
</td>
<td>
<div>Enable off box diff</div>
</td>
</tr>

<tr>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
1 change: 0 additions & 1 deletion plugins/cliconf/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def edit_config(

resp = {}
session = None

if self.supports_sessions():
session = session_name()
resp.update({"session": session})
Expand Down
7 changes: 5 additions & 2 deletions plugins/module_utils/network/eos/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def numerical_sort(string_int_list):
as_int_list.sort()
return list(set(as_int_list))

def unified_diff(content1, content2):
unified_diff = difflib.unified_diff(content1, content2, n=70, lineterm='\n')
def unified_diff(content1, content2, count):
"""
Provide the unified diff in context to number of lines specified with count
"""
unified_diff = difflib.unified_diff(content1, content2, n=count, lineterm='\n')
return "\n".join(unified_diff)
16 changes: 10 additions & 6 deletions plugins/modules/eos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
false, the command is issued without the all keyword
type: bool
default: false
off_box_diff:
description: Specify the off-box diff parameters
context_diff:
description: Specify the off-box diff options
type: dict
suboptions:
enable:
Expand Down Expand Up @@ -386,7 +386,7 @@ def main():
parents=dict(type="list", elements="str"),
before=dict(type="list", elements="str"),
after=dict(type="list", elements="str"),
off_box_diff=dict(type="dict", options=dict(
context_diff=dict(type="dict", options=dict(
enable=dict(type="bool"), context_lines=dict(type="int")
)),
match=dict(
Expand Down Expand Up @@ -501,11 +501,15 @@ def main():
commit=commit,
)
result["changed"] = True

if module.params["diff_against"] == "session":
if "diff" in response:
if module.params.get("off_box_diff"):
result["off_box_diff"] = unified_diff(candidate.split("\n"), running.split("\n"))
context_diff = module.params.get("context_diff")
if context_diff and context_diff.get("enable"):
if context_diff.get("context_lines"):
count = context_diff.get("context_lines")
else:
count = max(len(candidate), len(running))
result["context_diff"] = unified_diff(candidate.split("\n"), running.split("\n"), count)
else:
result["diff"] = {"prepared": response["diff"]}
else:
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/targets/eos_config/tests/cli/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@
that:
- result.changed == true

- name: take configuration backup in custom filename
become: true
register: result
arista.eos.eos_config:
src: ./fixtures/candidate.cfg
backup: true
context_diff:
enable: true
context_lines: 10
enable: true
backup_options:
filename: backup.cfg

- ansible.builtin.assert:
that:
- result.context_diff is defined

- name: check if the backup file-2 exist
ansible.builtin.find:
paths: "{{ role_path }}/backup/backup.cfg"
Expand Down

0 comments on commit c68972e

Please sign in to comment.