Skip to content

Commit

Permalink
[ignore] Changed the BFD Multi Hop create and update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana committed Dec 13, 2024
1 parent 47c2ef7 commit 3ef826a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
39 changes: 21 additions & 18 deletions plugins/modules/ndo_l3out_node_group_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@
from ansible_collections.cisco.mso.plugins.module_utils.utils import generate_api_endpoint, check_if_all_elements_are_none, append_update_ops_data


def bfd_multi_hop_mso_values(bfd):
return dict(
authEnabled=ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(bfd.get("auth")),
keyID=bfd.get("key_id"),
key=dict(
value=bfd.get("key"),
),
)


def main():
argument_spec = mso_argument_spec()
argument_spec.update(
Expand Down Expand Up @@ -245,6 +255,10 @@ def main():
ops = []

if state == "present":
if bfd:
# True if all elements are None, False otherwise.
bfd_is_empty = check_if_all_elements_are_none(list(bfd.values()))

l3out_node_routing_policy_object = None
if node_routing_policy:
l3out_node_routing_policy_objects = mso.query_objs(
Expand Down Expand Up @@ -275,12 +289,13 @@ def main():
mso_values["nodeRoutingPolicyRef"] = l3out_node_routing_policy_object.details.get("uuid") if l3out_node_routing_policy_object else None

if bfd:
if check_if_all_elements_are_none(list(bfd.values())) and proposed_payload.get("bfdMultiHop"):
if bfd_is_empty and proposed_payload.get("bfdMultiHop"):
mso_values_remove.append("bfdMultiHop")
elif not check_if_all_elements_are_none(list(bfd.values())):
if not proposed_payload.get("bfdMultiHop"):
mso_values["bfdMultiHop"] = dict()

elif not bfd_is_empty and not proposed_payload.get("bfdMultiHop"):
mso_values["bfdMultiHop"] = bfd_multi_hop_mso_values(bfd)

elif not bfd_is_empty and proposed_payload.get("bfdMultiHop"):
mso_values[("bfdMultiHop", "authEnabled")] = ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(bfd.get("auth"))
mso_values[("bfdMultiHop", "keyID")] = bfd.get("key_id")

Expand All @@ -298,20 +313,8 @@ def main():
if l3out_node_routing_policy_object:
mso_values["nodeRoutingPolicyRef"] = l3out_node_routing_policy_object.details.get("uuid")

if bfd:
bfd_multi_hop = dict()

if bfd.get("auth"):
bfd_multi_hop["authEnabled"] = ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(bfd.get("auth"))

if bfd.get("key_id"):
bfd_multi_hop["keyID"] = bfd.get("key_id")

if bfd.get("key"):
bfd_multi_hop["key"] = dict(value=bfd.get("key"))

if bfd_multi_hop:
mso_values["bfdMultiHop"] = bfd_multi_hop
if bfd and not bfd_is_empty:
mso_values["bfdMultiHop"] = bfd_multi_hop_mso_values(bfd)

mso_values["targetDscp"] = target_dscp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@
- node_group_policy_nt_with_l3out_1 is changed
- node_group_policy_nt_with_l3out_1.msg == "MSO Error 400{{':'}} Invalid configuration in L3Out 'l3out_1'{{':'}} node group 'node_group_policy_nt'{{':'}} BFD Multihop is not supported with non-BGP routing protocols. Current protocol{{':'}} none"

- name: Create ngp1 with bfd is an empty dict
- name: Create ngp1 with an empty bfd configuration
cisco.mso.ndo_l3out_node_group_policy:
<<: *mso_info
template: '{{ mso_l3out_template | default("ansible_test") }}'
Expand All @@ -851,7 +851,7 @@
state: present
register: create_ngp1_bfd_disabled

- name: Assertion check for create ngp1 with bfd is an empty dict
- name: Assertion check for create ngp1 with an empty bfd configuration
ansible.builtin.assert:
that:
- create_ngp1_bfd_disabled is changed
Expand Down

0 comments on commit 3ef826a

Please sign in to comment.