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 list.copy() and idempotent issues (replaced and overridden) #142

Merged
merged 14 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 11 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
4 changes: 4 additions & 0 deletions changelogs/fragments/acls_idempotent_issue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- replace list.copy() with list[:] to support python 2.7 and fix idempotent issue with
replaced and overridden (https://github.com/ansible-collections/arista.eos/pull/142).
48 changes: 30 additions & 18 deletions plugins/module_utils/network/eos/config/acls/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _state_replaced(self, want, have):
to the desired configuration
"""
commands = []
have_commands = []
config_cmds = []
remove_cmds = []
diff = {}
present = False
Expand All @@ -233,18 +233,26 @@ def _state_replaced(self, want, have):
"acls": [{"name": name, "aces": [h_ace]}],
}
remove_cmds.append(del_commands(h, have))
if diff_present or not present:
config_cmds = set_commands(want, have)
config_cmds = list(itertools.chain(*config_cmds))
for cmd in have:
have_configs = add_commands(cmd)
have_commands.append(have_configs)
have_commands = list(itertools.chain(*have_commands))
if remove_cmds:
remove_cmds = list(itertools.chain(*remove_cmds))
commands.append(remove_cmds)
for w_ace in want_ace:
w_diff = get_ace_diff(w_ace, h_acl["aces"])
if w_diff:
w = [{
"afi": afi,
"acls": [{"name": name, "aces": [w_ace]}],
}]
config_cmds = set_commands(w, have)
config_cmds = list(itertools.chain(*config_cmds))

#for cmd in have:
# have_configs = add_commands(cmd)
# have_commands.append(have_configs)
#have_commands = list(itertools.chain(*have_commands))
if remove_cmds:
remove_cmds = list(itertools.chain(*remove_cmds))
commands.append(remove_cmds)
if config_cmds:
commands.append(config_cmds)
commands = list(itertools.chain(*commands))
commands = list(itertools.chain(*commands))
commandset = []
[commandset.append(cmd) for cmd in commands if cmd not in commandset]
return commandset
Expand Down Expand Up @@ -279,28 +287,33 @@ def _state_overridden(self, want, have):
for h_acl in h["acls"]:
h_names.append(h_acl["name"])
if h_acl["name"] == w_acl["name"]:
for w_ace in w_acl["aces"]:
for h_ace in h_acl["aces"]:
ace_diff = get_ace_diff(
w_ace, h_acl["aces"]
h_ace, w_acl["aces"]
)
if ace_diff:
h = {
"afi": h["afi"],
"acls": [
{
"name": h_acl["name"],
"aces": h_acl["aces"],
"aces": [h_ace],
}
],
}
remove_cmds = del_commands(h, have)
commands.append(remove_cmds)
for w_ace in w_acl["aces"]:
w_ace_diff = get_ace_diff(
w_ace, h_acl["aces"]
)
if w_ace_diff:
w_diff = [
{
"afi": h["afi"],
"afi": w["afi"],
"acls": [
{
"name": h_acl["name"],
"name": w_acl["name"],
"aces": [w_ace],
}
],
Expand All @@ -313,7 +326,6 @@ def _state_overridden(self, want, have):
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}]}
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/network/eos/facts/acls/acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def render_config(self, spec, conf):
dev_config_remainder
and dev_config_remainder[0] in flags
):
flaglist = dev_config_remainder.copy()
flaglist = dev_config_remainder[:]
for config_remainder in flaglist:
if config_remainder not in flags:
break
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/modules/network/eos/test_eos_acls.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ def test_eos_acls_merged(self):
dict(
sequence="10",
grant="permit",
protocol="ospf",
protocol="tcp",
protocol_options=dict(
tcp=dict(
flags=dict(established="yes")
)
),
source=dict(
subnet_address="30.2.0.0/8"
),
Expand All @@ -109,7 +114,7 @@ def test_eos_acls_merged(self):
)
commands = [
"ipv6 access-list standard test2",
"10 permit ospf 30.2.0.0/8 any log",
"10 permit tcp 30.2.0.0/8 any established log",
]
self.execute_module(changed=True, commands=commands)

Expand Down