Skip to content

Commit

Permalink
[ignore] Removed state from ndo_l3out_node_group_policy module attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana committed Nov 6, 2024
1 parent 9f8028f commit 9e01cdf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
15 changes: 8 additions & 7 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def generate_api_endpoint(path, **kwargs):
:param kwargs: Keyword arguments representing query parameters. -> Dict
:return: A string representing the full API endpoint with query parameters. -> Str
"""
# if not kwargs:
# return path
return path if not kwargs else "{0}?{1}".format(path, "&".join(["{0}={1}".format(key, value) for key, value in kwargs.items()]))

# query_strings = ["{0}={1}".format(key, value) for key, value in kwargs.items()]
# query_string = "&".join(query_strings)
# full_url = "{0}?{1}".format(path, query_string)

# return full_url
def check_if_all_elements_are_none(values):
"""
Checks if all the elements in the provided list are None.
return path if not kwargs else "{0}?{1}".format(path, "&".join(["{0}={1}".format(key, value) for key, value in kwargs.items()]))
:param values: List of values to check. -> List
:return: True if all elements are None, False otherwise. -> boo
"""
return all(value is None for value in values)
21 changes: 6 additions & 15 deletions plugins/modules/ndo_l3out_node_group_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@
bfd:
description:
- The Bidirectional Forwarding Detection (BFD) multi-hop configuration of the L3Out Node Group Policy.
- Providing an empty dictionary will remove the O(bfd={}) from the L3Out Node Group Policy.
type: dict
suboptions:
state:
description:
- Use C(enabled) to configure the BFD multi-hop.
- Use C(disabled) to remove the BFD multi-hop.
type: str
choices: [ enabled, disabled ]
auth:
description:
- The BFD multi-hop authentication of the L3Out Node Group Policy.
Expand Down Expand Up @@ -189,7 +184,7 @@
from ansible_collections.cisco.mso.plugins.module_utils.mso import MSOModule, mso_argument_spec
from ansible_collections.cisco.mso.plugins.module_utils.template import MSOTemplate, KVPair
from ansible_collections.cisco.mso.plugins.module_utils.constants import TARGET_DSCP_MAP
from ansible_collections.cisco.mso.plugins.module_utils.utils import generate_api_endpoint
from ansible_collections.cisco.mso.plugins.module_utils.utils import generate_api_endpoint, check_if_all_elements_are_none


def main():
Expand All @@ -203,7 +198,6 @@ def main():
bfd=dict(
type="dict",
options=dict(
state=dict(type="str", choices=["enabled", "disabled"]),
auth=dict(type="str", choices=["enabled", "disabled"], aliases=["bfd_multi_hop_authentication"]),
key_id=dict(type="int"),
key=dict(type="str", no_log=True),
Expand Down Expand Up @@ -285,10 +279,10 @@ def main():
proposed_payload["nodeRoutingPolicyRef"] = node_routing_policy

if bfd:
if bfd.get("state") == "disabled" and proposed_payload.get("bfdMultiHop"):
if check_if_all_elements_are_none(list(bfd.values())) and proposed_payload.get("bfdMultiHop"):
proposed_payload.pop("bfdMultiHop")
ops.append(dict(op="remove", path=node_group_policy_path + "/bfdMultiHop"))
else:
elif not check_if_all_elements_are_none(list(bfd.values())):
if not proposed_payload.get("bfdMultiHop"):
proposed_payload["bfdMultiHop"] = dict()
ops.append(dict(op="replace", path=node_group_policy_path + "/bfdMultiHop", value=dict()))
Expand Down Expand Up @@ -321,9 +315,7 @@ def main():
mso.sanitize(proposed_payload, collate=True)
else:
payload = dict(name=name)

if description:
payload["description"] = description
payload["description"] = description

if l3out_node_routing_policy_object:
payload["nodeRoutingPolicyRef"] = l3out_node_routing_policy_object.details.get("uuid")
Expand All @@ -343,8 +335,7 @@ def main():
if bfd_multi_hop:
payload["bfdMultiHop"] = bfd_multi_hop

if target_dscp:
payload["targetDscp"] = target_dscp
payload["targetDscp"] = target_dscp

mso.sanitize(payload)
ops.append(dict(op="add", path=node_group_policy_path, value=payload))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,7 @@
l3out: "l3out_2"
name: "node_group_policy_5"
node_routing_policy: ""
bfd:
state: disabled
bfd: {}
state: present
register: clear_ngp_5_bfd_config

Expand Down Expand Up @@ -840,18 +839,17 @@
- 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 state disabled
- name: Create ngp1 with bfd is an empty dict
cisco.mso.ndo_l3out_node_group_policy:
<<: *mso_info
template: '{{ ansible_l3out_template | default("ansible_test") }}'
l3out: "l3out_1"
name: "ngp1"
bfd:
state: disabled
bfd: {}
state: present
register: create_ngp1_bfd_disabled

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

0 comments on commit 9e01cdf

Please sign in to comment.