Skip to content

Commit

Permalink
[ignore] Fixed based on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samiib authored and lhercot committed Dec 13, 2024
1 parent cdf42ec commit d994bfd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
32 changes: 16 additions & 16 deletions plugins/modules/ndo_mcp_global_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
type: str
per_vlan:
description:
- Enable or disable MCP packets being sent to each End Point Group (EPG).
- When enabled MCP will send packets on a per End Point Group (EPG) basis.
- If disabled, the packets will only be sent on untagged EPGs which allows detecting loops in the native VLAN only.
- Defaults to C(disabled) when unset during creation.
type: str
choices: [ enabled, disabled ]
Expand All @@ -65,7 +66,7 @@
description:
- The amount of MCP packets that will be received before port disable loop protection action takes place.
- Defaults to 3 when unset during creation.
- The value must be between 0 and 255.
- The value must be between 1 and 255.
type: int
aliases: [ loop_factor, loop_detection_mult_factor ]
port_disable:
Expand Down Expand Up @@ -121,18 +122,17 @@
username: admin
password: SomeSecretPassword
template: fabric_template
name: mcp_global_policy_1
key: cisco
name: example_mcp_global_policy
state: present
register: mcp_global_policy_1
register: mcp_global_policy_new
- name: Create the MCP Global Policy object with all attributes
cisco.mso.ndo_mcp_global_policy:
host: mso_host
username: admin
password: SomeSecretPassword
template: fabric_template
name: mcp_global_policy_1
name: example_mcp_global_policy
description: A Global MCP Policy
key: cisco
admin_state: enabled
Expand All @@ -143,7 +143,7 @@
transmission_frequency_sec: 2
transmission_frequency_msec: 10
state: present
register: mcp_global_policy_1
register: mcp_global_policy_all
- name: Update the MCP Global Policy object with UUID
cisco.mso.ndo_mcp_global_policy:
Expand All @@ -152,7 +152,7 @@
password: SomeSecretPassword
template: fabric_template
name: mcp_global_policy_update
uuid: "{{ mcp_global_policy_1.current.uuid }}"
uuid: "{{ mcp_global_policy_all.current.uuid }}"
state: present
- name: Query the MCP Global Policy object with name
Expand All @@ -161,7 +161,7 @@
username: admin
password: SomeSecretPassword
template: fabric_template
name: mcp_global_policy_1
name: example_mcp_global_policy
state: query
register: query_name
Expand All @@ -171,7 +171,7 @@
username: admin
password: SomeSecretPassword
template: fabric_template
uuid: "{{ mcp_global_policy_1.current.uuid }}"
uuid: "{{ mcp_global_policy_all.current.uuid }}"
state: query
register: query_uuid
Expand All @@ -190,7 +190,7 @@
username: admin
password: SomeSecretPassword
template: fabric_template
name: mcp_global_policy_1
name: example_mcp_global_policy
state: absent
- name: Delete the MCP Global Policy object with UUID
Expand All @@ -199,7 +199,7 @@
username: admin
password: SomeSecretPassword
template: fabric_template
uuid: "{{ mcp_global_policy_1.current.uuid }}"
uuid: "{{ mcp_global_policy_all.current.uuid }}"
state: absent
"""

Expand Down Expand Up @@ -263,9 +263,9 @@ def main():
"description": module.params.get("description"),
"adminState": module.params.get("admin_state"),
"key": module.params.get("key"),
"enablePduPerVlan": ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP[per_vlan] if per_vlan else None,
"enablePduPerVlan": ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(per_vlan),
"loopDetectMultFactor": module.params.get("loop_detection_factor"),
"protectPortDisable": ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP[port_disable] if port_disable else None,
"protectPortDisable": ENABLED_OR_DISABLED_TO_BOOL_STRING_MAP.get(port_disable),
"initialDelayTime": module.params.get("initial_delay_time"),
"txFreq": module.params.get("transmission_frequency_sec"),
"txFreqMsec": module.params.get("transmission_frequency_msec"),
Expand Down Expand Up @@ -308,8 +308,8 @@ def main():

mso.sanitize(proposed_payload, collate=True)
else:
if not name:
mso.fail_json(msg="{0} name cannot be empty".format(object_description))
if uuid:
mso.fail_json(msg="{0} cannot be created with a UUID".format(object_description))
payload = dict()
for mso_name, mso_value in mso_values.items():
if mso_value:
Expand Down
50 changes: 35 additions & 15 deletions tests/integration/targets/ndo_mcp_global_policy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
- query_all_mcp_policy.current | length == 1 # Can only be one

# DELETE
- name: Delete a MCP Global Policy with name (check mode)
- name: Delete MCP Global Policy with name (check mode)
cisco.mso.ndo_mcp_global_policy: &delete_mcp_global_policy
<<: *mso_info
template: ansible_fabric_policy_template
Expand All @@ -213,7 +213,7 @@
check_mode: true
register: cm_delete_mcp_global_policy

- name: Delete a MCP Global Policy with name
- name: Delete MCP Global Policy with name
cisco.mso.ndo_mcp_global_policy:
<<: *delete_mcp_global_policy
register: nm_delete_mcp_global_policy
Expand Down Expand Up @@ -243,15 +243,6 @@
description: An MCP Global policy to delete with UUID
register: new_mcp_global_policy

- name: Delete the MCP Global Policy with incorrect UUID
cisco.mso.ndo_mcp_global_policy:
<<: *mso_info
template: ansible_fabric_policy_template
uuid: does-not-exist
state: absent
ignore_errors: true
register: no_uuid_delete_mcp_global_policy

- name: Delete the MCP Global Policy with UUID
cisco.mso.ndo_mcp_global_policy:
<<: *mso_info
Expand All @@ -275,7 +266,20 @@
<<: *query_mcp_global_policy
register: query_none

- name: Create an MCP Global Policy without a name
- name: Create the MCP Global Policy with a UUID
cisco.mso.ndo_mcp_global_policy:
<<: *mso_info
template: ansible_fabric_policy_template
uuid: not-possible
state: present
ignore_errors: true
register: create_with_uuid

- name: Create the MCP Global Policy
cisco.mso.ndo_mcp_global_policy:
<<: *add_mcp_global_policy

- name: Update the MCP Global Policy with incorrect UUID
cisco.mso.ndo_mcp_global_policy:
<<: *mso_info
template: ansible_fabric_policy_template
Expand All @@ -284,15 +288,31 @@
ignore_errors: true
register: update_non_existing_uuid

- name: Delete the MCP Global Policy with incorrect UUID
cisco.mso.ndo_mcp_global_policy:
<<: *mso_info
template: ansible_fabric_policy_template
uuid: does-not-exist
state: absent
ignore_errors: true
register: delete_non_existing_uuid

- name: Delete the MCP Global Policy
cisco.mso.ndo_mcp_global_policy:
<<: *add_mcp_global_policy
state: absent

- name: Assert errors and no MCP Global Policy found
ansible.builtin.assert:
that:
- query_none is not changed
- query_none.current == {}
- no_uuid_delete_mcp_global_policy is failed
- no_uuid_delete_mcp_global_policy.msg == "MCP Global Policy with the UUID{{":"}} 'does-not-exist' not found"
- update_non_existing_uuid is failed
- update_non_existing_uuid.msg == "MCP Global Policy name cannot be empty"
- update_non_existing_uuid.msg == "MCP Global Policy with the UUID{{":"}} 'non-existing-uuid' not found"
- delete_non_existing_uuid is failed
- delete_non_existing_uuid.msg == "MCP Global Policy with the UUID{{":"}} 'does-not-exist' not found"
- create_with_uuid is failed
- create_with_uuid.msg == "MCP Global Policy cannot be created with a UUID"

# CLEANUP TEMPLATE
- name: Ensure fabric resource policy template do not exist
Expand Down

0 comments on commit d994bfd

Please sign in to comment.