Skip to content

Commit

Permalink
eos_acls: Fix to maintain idempotent state for overridden operation (#…
Browse files Browse the repository at this point in the history
…116)

eos_acls: Fix to maintain idempotent state for overridden operation

Reviewed-by: Rohit Thakur <[email protected]>
             https://github.com/rohitthakur2590
  • Loading branch information
GomathiselviS authored Sep 28, 2020
1 parent 46326d9 commit cfaa79e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/116-acls-overridden-idempotent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Added fix to maintain the idempotency while using overridden operation.
42 changes: 35 additions & 7 deletions plugins/module_utils/network/eos/config/acls/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ def _state_overridden(self, want, have):
ace_diff = {}
h_afi_list = []
w_afi_list = []
diff = False
for h in have:
h_afi_list.append(h["afi"])
for w in want:
Expand All @@ -285,7 +284,6 @@ def _state_overridden(self, want, have):
w_ace, h_acl["aces"]
)
if ace_diff:
diff = True
h = {
"afi": h["afi"],
"acls": [
Expand All @@ -297,20 +295,48 @@ def _state_overridden(self, want, have):
}
remove_cmds = del_commands(h, have)
commands.append(remove_cmds)
w_diff = [
{
"afi": h["afi"],
"acls": [
{
"name": h_acl["name"],
"aces": [w_ace],
}
],
}
]
config_cmds = set_commands(
w_diff, have
)
config_cmds = list(
itertools.chain(*config_cmds)
)
commands.append(config_cmds)

for hname in h_names:
if hname not in w_names:
h = {"afi": h["afi"], "acls": [{"name": hname}]}
remove_cmds = del_commands(h, have)
if remove_cmds not in commands:
commands.append(remove_cmds)

if diff:
config_cmds = set_commands(want, have)
config_cmds = list(itertools.chain(*config_cmds))
commands.append(config_cmds)
if commands:
commands = list(itertools.chain(*commands))
return commands
commandset = []
for c in commands:
access_list = re.findall(r"(ip.*) access-list (.*)", c)
if access_list and "no" in c:
commandset.append(c)
continue
if access_list:
acl_index = commands.index(c)
else:
if commands[acl_index] not in commandset:
commandset.append(commands[acl_index])
commandset.append(c)

return commandset

def _state_merged(self, want, have):
""" The command generator when state is merged
Expand Down Expand Up @@ -382,6 +408,8 @@ def set_commands(want, have):

def get_updated_ace(w, h):
# gives the ace to be updated in case of merge update.
if not dict_diff(w, h):
return
w_updated = w.copy()
for hkey in h.keys():
if hkey not in w.keys():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

- assert:
that:
- result.commands|length == 8
- result.commands|length == 7
- result.changed == true
- "'ip access-list test1' in result.commands"
- "'10 permit ospf any any log' in result.commands"
Expand Down
1 change: 0 additions & 1 deletion tests/unit/modules/network/eos/test_eos_acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def test_eos_acls_overridden(self):
"ip access-list test1",
"no 35",
"no 45",
"ip access-list test1",
"10 permit ospf 30.2.0.0/8 any log",
]
self.execute_module(changed=True, commands=commands)
Expand Down

0 comments on commit cfaa79e

Please sign in to comment.