Skip to content

Commit

Permalink
[ignore] Changed the current value output logic for the ndo_l3out_tem…
Browse files Browse the repository at this point in the history
…plate module
  • Loading branch information
sajagana authored and lhercot committed Oct 3, 2024
1 parent 528f4b2 commit 0c4d236
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
31 changes: 12 additions & 19 deletions plugins/modules/ndo_l3out_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,22 +505,16 @@ def main():
tenant_name = l3out_template_object.template_summary.get("tenantName")

l3outs = l3out_template_object.template.get("l3outTemplate", {}).get("l3outs", [])
object_description = "L3Out"

if state in ["query", "absent"] and l3outs == []:
mso.exit_json()
elif state == "query" and not (name or uuid):
mso.existing = l3outs
elif l3outs and (name or uuid):
object_description = "L3Out"

if uuid:
match = l3out_template_object.get_object_by_uuid(object_description, l3outs, uuid)
else:
match = l3out_template_object.get_object_by_key_value_pairs(object_description, l3outs, [KVPair("name", name)])

match = l3out_template_object.get_object_by_key_value_pairs(object_description, l3outs, [KVPair("uuid", uuid) if uuid else KVPair("name", name)])
if match:
mso.existing = copy.deepcopy(match.details)
mso.previous = copy.deepcopy(match.details)
mso.existing = mso.previous = copy.deepcopy(match.details)

ops = []

Expand Down Expand Up @@ -875,9 +869,7 @@ def main():

if originate_default_route is not None and originate_default_route == "" and mso.existing.get("defaultRouteLeak"):
ops.append(dict(op="remove", path=l3out_attrs_path + "/defaultRouteLeak"))

proposed_payload.pop("defaultRouteLeak", None)
mso.existing.pop("defaultRouteLeak", None)

elif (originate_default_route is not None and originate_default_route != "") or (originate_default_route_always is not None):
if not mso.existing.get("defaultRouteLeak"):
Expand Down Expand Up @@ -938,27 +930,28 @@ def main():

elif ospf_state == "disabled":
ops.append(dict(op="remove", path=l3out_attrs_path + "/ospfAreaConfig"))

proposed_payload.pop("ospfAreaConfig", None)
mso.existing.pop("ospfAreaConfig", None)

ops.append(dict(op="remove", path=l3out_attrs_path + "/defaultRouteLeak"))

proposed_payload.pop("defaultRouteLeak", None)
mso.existing.pop("defaultRouteLeak", None)

mso.sanitize(proposed_payload, collate=True)

mso.existing = mso.proposed

elif state == "absent":
if mso.existing:
ops.append(dict(op="remove", path="/l3outTemplate/l3outs/{0}".format(match.index)))
mso.existing = {}

if not module.check_mode and ops:
l3out_template_path = "{0}/{1}".format(l3out_template_object.templates_path, l3out_template_object.template_id)
mso.request(l3out_template_path, method="PATCH", data=ops)
response_object = mso.request(l3out_template_path, method="PATCH", data=ops)
l3outs = response_object.get("l3outTemplate", {}).get("l3outs", [])
match = l3out_template_object.get_object_by_key_value_pairs(object_description, l3outs, [KVPair("uuid", uuid) if uuid else KVPair("name", name)])
if match:
mso.existing = match.details # When the state is present
else:
mso.existing = {} # When the state is absent
elif module.check_mode and state != "query": # When the state is present/absent with check mode
mso.existing = mso.proposed if state == "present" else {}

mso.exit_json()

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/targets/ndo_l3out_template/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,15 @@
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.attachedHostRouteRedistRef != ""
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.connectedRouteRedistRef != ""
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.interleakRef != ""
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.routeDampeningV4Ref == ""
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.routeDampeningV6Ref == ""
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.routeDampeningV4Ref is not defined
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.routeDampeningV6Ref is not defined
- l3out_1_update_empty_bgp.current.advancedRouteMapRefs.staticRouteRedistRef != ""
- l3out_1_update_empty_bgp.current.defaultRouteLeak.always == false
- l3out_1_update_empty_bgp.current.defaultRouteLeak.originateDefaultRoute == "only"
- l3out_1_update_empty_bgp.current.description == "add_log"
- l3out_1_update_empty_bgp.current.exportRouteMapRef == ""
- l3out_1_update_empty_bgp.current.exportRouteMapRef is not defined
- l3out_1_update_empty_bgp.current.importRouteControl == false
- l3out_1_update_empty_bgp.current.importRouteMapRef == ""
- l3out_1_update_empty_bgp.current.importRouteMapRef is not defined
- l3out_1_update_empty_bgp.current.l3domain == "ans_l3_domain"
- l3out_1_update_empty_bgp.current.name == "l3out_1_updated"
- l3out_1_update_empty_bgp.current.ospfAreaConfig.areaType == "regular"
Expand Down

0 comments on commit 0c4d236

Please sign in to comment.