Skip to content

Commit 5f9357d

Browse files
bewingroverflowRuchip16KB-perByte
authored
Correct indentation in ACL comparator (#564)
* Add unit test for #512 * Correct indentation of ACL comparator Only check for missing wanted ACLs after processing all had ACLs, not just the first one. Addresses #512 * Add changelog entry for replaced acls idempotency * Correct ACL replaced idempotency check An idempotency check should ensure that there is NO change and NO commands. --------- Co-authored-by: Vinay M <[email protected]> Co-authored-by: Ruchi Pakhle <[email protected]> Co-authored-by: Sagar Paul <[email protected]>
1 parent 37793d2 commit 5f9357d

File tree

5 files changed

+89
-19
lines changed

5 files changed

+89
-19
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
bugfixes:
3+
- Fixed idempotency when using `replaced` state on host with multiple ACLs present.

plugins/module_utils/network/eos/config/acls/acls.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,23 @@ def _state_replaced(self, want, have):
278278
config_cmds.append(
279279
list(itertools.chain(*cmds)),
280280
)
281-
if name not in ace_names:
282-
for w_ace in want_ace:
283-
w = [
284-
{
285-
"afi": afi,
286-
"acls": [
287-
{
288-
"name": name,
289-
"aces": [w_ace],
290-
},
291-
],
292-
},
293-
]
294-
cmds = set_commands(w, have)
295-
config_cmds.append(
296-
list(itertools.chain(*cmds)),
297-
)
281+
if name not in ace_names:
282+
for w_ace in want_ace:
283+
w = [
284+
{
285+
"afi": afi,
286+
"acls": [
287+
{
288+
"name": name,
289+
"aces": [w_ace],
290+
},
291+
],
292+
},
293+
]
294+
cmds = set_commands(w, have)
295+
config_cmds.append(
296+
list(itertools.chain(*cmds)),
297+
)
298298

299299
if remove_cmds:
300300
remove_cmds = list(itertools.chain(*remove_cmds))

tests/integration/targets/eos_acls/tests/common/replaced.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@
113113

114114
- ansible.builtin.assert:
115115
that:
116-
- result.changed == true
117-
- result.commands|length == 2
116+
- result.changed == false
117+
- result.commands|length == 0
118118
- ansible_facts.network_resources.acls|symmetric_difference(result.before)
119119
== []
120120
always:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ip access-list TEST-LIST-1
2+
10 remark test
3+
20 permit tcp 192.0.2.0/24 any eq https log
4+
!
5+
ip access-list TEST-LIST-2
6+
10 remark test
7+
20 permit tcp 192.0.2.0/24 any eq https log
8+
!
9+
ip access-list TEST-LIST-3
10+
10 remark test
11+
20 permit tcp 192.0.2.0/24 any eq https log
12+
!

tests/unit/modules/network/eos/test_eos_acls.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,61 @@ def test_eos_acls_deletedafis(self):
397397
commands = ["no ip access-list test1"]
398398
self.execute_module(changed=True, commands=commands)
399399

400+
def test_eos_two_acls_idempotent(self):
401+
set_module_args(
402+
dict(
403+
config=[
404+
dict(
405+
afi="ipv4",
406+
acls=[
407+
dict(
408+
name="TEST-LIST-1",
409+
aces=[
410+
dict(
411+
sequence="10",
412+
remark="test",
413+
),
414+
dict(
415+
sequence="20",
416+
grant="permit",
417+
source=dict(subnet_address="192.0.2.0/24"),
418+
destination=dict(
419+
any="true",
420+
port_protocol=dict(eq="https"),
421+
),
422+
protocol="tcp",
423+
log="true",
424+
),
425+
],
426+
),
427+
dict(
428+
name="TEST-LIST-2",
429+
aces=[
430+
dict(
431+
sequence="10",
432+
remark="test",
433+
),
434+
dict(
435+
sequence="20",
436+
grant="permit",
437+
log="true",
438+
destination=dict(
439+
any="true",
440+
port_protocol=dict(eq="https"),
441+
),
442+
protocol="tcp",
443+
source=dict(subnet_address="192.0.2.0/24"),
444+
),
445+
],
446+
),
447+
],
448+
),
449+
],
450+
state="replaced",
451+
),
452+
)
453+
self.execute_module(changed=False, commands=[], filename="eos_acls_idempotent.cfg")
454+
400455
def test_eos_acls_gathered(self):
401456
set_module_args(dict(config=[], state="gathered"))
402457
result = self.execute_module(

0 commit comments

Comments
 (0)