Skip to content

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Girish5tri committed Nov 21, 2024
1 parent a71f345 commit 1d36773
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
6 changes: 6 additions & 0 deletions plugins/module_utils/network/ios/config/ospfv2/ospfv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def generate_commands(self):
if self.want:
for entry in self.want.get("processes", []):
entry = self._handle_deprecated(entry)
# remove set_interface from passive_intf if it already exists
passive_intf = entry.get("passive_interfaces", {}).get("interface", {})
if passive_intf and any(h["process_id"] == entry["process_id"] and
h.get("passive_interfaces", {}).get("interface", {}).get("name") == passive_intf.get("name")
for h in self.have.get("processes", [])):
passive_intf.pop("set_interface", None)
wantd.update({(entry["process_id"], entry.get("vrf")): entry})

if self.have:
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/targets/ios_ospfv2/tests/cli/merged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
router_lsa: true
on_startup:
time: 110
passive_interfaces:
interface:
set_interface: true
name:
- GigabitEthernet1
areas:
- area_id: "5"
capability: true
Expand Down Expand Up @@ -73,7 +78,7 @@
- name: Assert that after dict is correctly generated
ansible.builtin.assert:
that:
- "{{ merged['after']['processes'] | symmetric_difference(result['after']['processes']) | length == 0 }}"
- "{{ merged['after']['processes'] | map('combine', {'passive_interfaces': none}) | symmetric_difference(result['after']['processes'] | map('combine', {'passive_interfaces': none})) | length == 0 }}"

- name: Merge provided configuration with device configuration (idempotent)
register: result
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/targets/ios_ospfv2/tests/cli/rendered.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
router_lsa: true
on_startup:
time: 110
passive_interfaces:
interface:
set_interface: true
name:
- GigabitEthernet1
areas:
- area_id: "5"
capability: true
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/ios_ospfv2/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ merged:
- area 10 filter-list prefix test_prefix_out out
- area 10 filter-list prefix test_prefix_in in
- area 5 capability default-exclusion

- passive-interface GigabitEthernet1
after:
processes:
- areas:
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/modules/network/ios/test_ios_ospfv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,3 +1206,49 @@ def test_ios_ospfv2_overridden_idempotent(self):
),
)
self.execute_module(changed=False, commands=[])

def test_ios_ospfv2_set_interface_idempotent(self):
self.execute_show_command.return_value = dedent(
"""\
router ospf 1
router-id 1.1.1.1
passive-interface GigabitEthernet1
network 10.140.2.0 0.0.0.255 area 0
network 10.140.5.0 0.0.0.255 area 0
""",
)
set_module_args(
dict(
config=dict(
processes=[
dict(
process_id="1",
router_id="1.1.1.1",
network=[
dict(
address="10.140.2.0",
wildcard_bits="0.0.0.255",
area="0",
),
dict(
address="10.140.5.0",
wildcard_bits="0.0.0.255",
area="0",
),
],
passive_interfaces=dict(
interface=dict(
set_interface=True,
name=["GigabitEthernet1"],
),
),
vrf=None,
),
],
),
state="merged",
),
)

self.execute_module(changed=False, commands=[])

0 comments on commit 1d36773

Please sign in to comment.