Skip to content

Commit

Permalink
[bugfix] Fix to avoid making updates to attributes that are not provi…
Browse files Browse the repository at this point in the history
…ded which could lead to removal of configuration in mso_schema_template_bd
  • Loading branch information
akinross authored and lhercot committed Jul 3, 2024
1 parent 3adc47f commit cf0d51c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
43 changes: 42 additions & 1 deletion plugins/modules/mso_schema_template_bd.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,51 @@ def main():
payload.update(mcastRtMapFilter=route_map_filter)

mso.sanitize(payload, collate=True, required=["dhcpLabel", "dhcpLabels"])

if mso.existing:
ops.append(dict(op="replace", path=bd_path, value=mso.sent))
# When updating an existing BD, replace operation for each attribute to avoid existing configuration being replaced
# This case is specifically important for subnet and dhcp policy which can be configured as a child module
if display_name is not None and mso.existing.get("displayName") != display_name:
ops.append(dict(op="replace", path=bd_path + "/displayName", value=payload.get("displayName")))
if subnets is not None and mso.existing.get("subnets") != subnets:
ops.append(dict(op="replace", path=bd_path + "/subnets", value=payload.get("subnets")))
if vrf_ref != mso.existing.get("vrfRef"):
ops.append(dict(op="replace", path=bd_path + "/vrfRef", value=payload.get("vrfRef")))
if intersite_bum_traffic is not None and mso.existing.get("intersiteBumTrafficAllow") != intersite_bum_traffic:
ops.append(dict(op="replace", path=bd_path + "/intersiteBumTrafficAllow", value=payload.get("intersiteBumTrafficAllow")))
if optimize_wan_bandwidth is not None and mso.existing.get("optimizeWanBandwidth") != optimize_wan_bandwidth:
ops.append(dict(op="replace", path=bd_path + "/optimizeWanBandwidth", value=payload.get("optimizeWanBandwidth")))
if layer2_stretch is not None and mso.existing.get("l2Stretch") != layer2_stretch:
ops.append(dict(op="replace", path=bd_path + "/l2Stretch", value=payload.get("l2Stretch")))
if layer2_unknown_unicast is not None and mso.existing.get("l2UnknownUnicast") != layer2_unknown_unicast:
ops.append(dict(op="replace", path=bd_path + "/l2UnknownUnicast", value=payload.get("l2UnknownUnicast")))
if layer3_multicast is not None and mso.existing.get("l3MCast") != layer3_multicast:
ops.append(dict(op="replace", path=bd_path + "/l3MCast", value=payload.get("l3MCast")))
if dhcp_label is not None and mso.existing.get("dhcpLabel") != dhcp_label:
ops.append(dict(op="replace", path=bd_path + "/dhcpLabel", value=payload.get("dhcpLabel")))
if dhcp_labels is not None and mso.existing.get("dhcpLabels") != dhcp_labels:
ops.append(dict(op="replace", path=bd_path + "/dhcpLabels", value=payload.get("dhcpLabels")))
if unknown_multicast_flooding is not None and mso.existing.get("unkMcastAct") != unknown_multicast_flooding:
ops.append(dict(op="replace", path=bd_path + "/unkMcastAct", value=payload.get("unkMcastAct")))
if multi_destination_flooding is not None and mso.existing.get("multiDstPktAct") != multi_destination_flooding:
ops.append(dict(op="replace", path=bd_path + "/multiDstPktAct", value=payload.get("multiDstPktAct")))
if ipv6_unknown_multicast_flooding is not None and mso.existing.get("v6unkMcastAct") != ipv6_unknown_multicast_flooding:
ops.append(dict(op="replace", path=bd_path + "/v6unkMcastAct", value=payload.get("v6unkMcastAct")))
if arp_flooding is not None and mso.existing.get("arpFlood") != arp_flooding:
ops.append(dict(op="replace", path=bd_path + "/arpFlood", value=payload.get("arpFlood")))
if virtual_mac_address is not None and mso.existing.get("vmac") != virtual_mac_address:
ops.append(dict(op="replace", path=bd_path + "/vmac", value=payload.get("vmac")))
if unicast_routing is not None and mso.existing.get("unicastRouting") != unicast_routing:
ops.append(dict(op="replace", path=bd_path + "/unicastRouting", value=payload.get("unicastRouting")))
if description is not None and mso.existing.get("description") != description:
ops.append(dict(op="replace", path=bd_path + "/description", value=payload.get("description")))
if multicast_route_map_source_filter or multicast_route_map_destination_filter:
if mso.existing.get("mcastRtMapFilter") != payload.get("mcastRtMapFilter"):
ops.append(dict(op="replace", path=bd_path + "/mcastRtMapFilter", value=payload.get("mcastRtMapFilter")))

else:
ops.append(dict(op="add", path=bds_path + "/-", value=mso.sent))

mso.existing = mso.proposed

if "bdRef" in mso.previous:
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/targets/mso_schema_template_bd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,15 @@
<<: *bd_multicast_route_map
register: nm_create_bd_multicast_route_map_again

# Add a subnet to BD with multicast route-map filters to ensure that changes made after to the BD do not remove the existing subnet
- name: Add a subnet to BD with multicast route-map filters
cisco.mso.mso_schema_template_bd_subnet:
<<: *mso_info
schema: '{{ mso_schema | default("ansible_test") }}'
template: Template1
bd: ansible_test_multicast_route_map
subnet: 10.1.1.1/24

- name: Update BD with a destination multicast route-map filter from different template
cisco.mso.mso_schema_template_bd:
<<: *bd_multicast_route_map
Expand Down Expand Up @@ -1872,6 +1881,8 @@
- nm_update_bd_multicast_route_map is changed
- nm_update_bd_multicast_route_map.current.displayName == "ansible_test_multicast_route_map"
- nm_update_bd_multicast_route_map.current.mcastRtMapFilter.mcastRtMapDestRef != nm_update_bd_multicast_route_map.previous.mcastRtMapFilter.mcastRtMapDestRef
- nm_update_bd_multicast_route_map.previous.subnets[0].ip == "10.1.1.1/24"
- nm_update_bd_multicast_route_map.current.subnets[0].ip == "10.1.1.1/24"
- nm_update_bd_multicast_route_map_source_only is changed
- nm_update_bd_multicast_route_map_source_only.current.displayName == "ansible_test_multicast_route_map"
- nm_update_bd_multicast_route_map_source_only.current.mcastRtMapFilter.mcastRtMapDestRef is not defined
Expand Down

0 comments on commit cf0d51c

Please sign in to comment.