Skip to content

Commit

Permalink
[bugfix] Fixed the useg_subnet logic in the mso_schema_template_anp_e…
Browse files Browse the repository at this point in the history
…pg_useg_attribute.py module
  • Loading branch information
sajagana authored and lhercot committed Jan 17, 2024
1 parent 6e2e818 commit b68e063
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 6 additions & 4 deletions plugins/modules/mso_schema_template_anp_epg_useg_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
description:
- The uSeg Subnet can only be used when the I(attribute_type) is IP.
- Use C(false) to set the custom uSeg Subnet IP address to the uSeg Attribute.
- Use C(true) to set the uSeg Subnet IP address to 0.0.0.0.
- Use C(true) to set the default uSeg Subnet IP address 0.0.0.0.
type: bool
state:
description:
Expand Down Expand Up @@ -229,11 +229,13 @@ def main():
payload = dict(name=name, displayName=name, description=description, type=EPG_U_SEG_ATTR_TYPE_MAP[attribute_type], value=value)

if attribute_type == "ip":
if useg_subnet is False:
if useg_subnet:
if value != "" and value != "0.0.0.0" and value is not None:
mso.fail_json(msg="The value should be empty string or 0.0.0.0, when the useg_subnet is true.")
payload["fvSubnet"] = True
else:
payload["fvSubnet"] = False
payload["value"] = "0.0.0.0"
else:
payload["fvSubnet"] = useg_subnet

mso.sanitize(payload, collate=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@
ignore_errors: true
register: ans_test_uSeg_1_nt

- name: Invalid test - ans_test_uSeg_1 present - attribute_type - ip, useg_subnet - true, with value
cisco.mso.mso_schema_template_anp_epg_useg_attribute:
<<: *useg_attribute_present
name: ans_test_uSeg_2
attribute_type: ip
useg_subnet: true
value: "1.2.3.4"
ignore_errors: true
register: ans_test_uSeg_1_nt1

- name: Assertions check for invalid tests - ans_test_uSeg_1
ansible.builtin.assert:
that:
- ans_test_uSeg_1_nt is not changed
- ans_test_uSeg_1_nt.msg == "state is present but all of the following are missing{{':'}} name, type"
- ans_test_uSeg_1_nt1 is not changed
- ans_test_uSeg_1_nt1.msg == "The value should be empty string or 0.0.0.0, when the useg_subnet is true."

- name: ans_test_uSeg_1 present - attribute_type - ip, useg_subnet - true, without value
cisco.mso.mso_schema_template_anp_epg_useg_attribute:
<<: *mso_info
Expand Down Expand Up @@ -124,11 +142,13 @@
- name: ans_test_uSeg_2 present - attribute_type - ip, useg_subnet - false, with value - normal mode
cisco.mso.mso_schema_template_anp_epg_useg_attribute: &ans_test_uSeg_2_nm_present
<<: *ans_test_uSeg_2_cm_present
output_level: debug
register: ans_test_uSeg_2_nm_present

- name: ans_test_uSeg_2 present - attribute_type - ip, useg_subnet - false, with value - normal mode again
cisco.mso.mso_schema_template_anp_epg_useg_attribute:
<<: *ans_test_uSeg_2_nm_present
output_level: debug
register: ans_test_uSeg_2_nm_present_again

- name: Assertions check for add ans_test_uSeg_1 and ans_test_uSeg_2 object
Expand All @@ -139,7 +159,7 @@
- ans_test_uSeg_1.current.name == "ans_test_uSeg_1"
- ans_test_uSeg_1.current.type == "ip"
- ans_test_uSeg_1.current.value == "0.0.0.0"
- ans_test_uSeg_1.current.fvSubnet == false
- ans_test_uSeg_1.current.fvSubnet == true
- ans_test_uSeg_1.current.description == "ans_test_uSeg_1"
- ans_test_uSeg_2_nt is not changed
- ans_test_uSeg_2_nt.msg == "useg_subnet is False but all of the following are missing{{':'}} value"
Expand All @@ -149,28 +169,26 @@
- ans_test_uSeg_2_cm_present.current.name == "ans_test_uSeg_2"
- ans_test_uSeg_2_cm_present.current.type == "ip"
- ans_test_uSeg_2_cm_present.current.value == "11.22.33.44/24"
- ans_test_uSeg_2_cm_present.current.fvSubnet == true
- ans_test_uSeg_2_cm_present.current.description == "uSeg Attr object created using Ansible"
- ans_test_uSeg_2_nm_present is changed
- ans_test_uSeg_2_nm_present.current != {}
- ans_test_uSeg_2_nm_present.previous == {}
- ans_test_uSeg_2_nm_present.current.name == "ans_test_uSeg_2"
- ans_test_uSeg_2_nm_present.current.type == "ip"
- ans_test_uSeg_2_nm_present.current.value == "11.22.33.44/24"
- ans_test_uSeg_2_nm_present.current.fvSubnet == true
- ans_test_uSeg_2_nm_present.sent.fvSubnet == false
- ans_test_uSeg_2_nm_present.current.description == "uSeg Attr object created using Ansible"
- ans_test_uSeg_2_nm_present_again is not changed
- ans_test_uSeg_2_nm_present_again.current != {}
- ans_test_uSeg_2_nm_present_again.previous != {}
- ans_test_uSeg_2_nm_present_again.current.name == "ans_test_uSeg_2"
- ans_test_uSeg_2_nm_present_again.current.type == "ip"
- ans_test_uSeg_2_nm_present_again.current.value == "11.22.33.44/24"
- ans_test_uSeg_2_nm_present_again.current.fvSubnet == true
- ans_test_uSeg_2_nm_present_again.sent.fvSubnet == false
- ans_test_uSeg_2_nm_present_again.current.description == "uSeg Attr object created using Ansible"
- ans_test_uSeg_2_nm_present_again.previous.name == "ans_test_uSeg_2"
- ans_test_uSeg_2_nm_present_again.previous.type == "ip"
- ans_test_uSeg_2_nm_present_again.previous.value == "11.22.33.44/24"
- ans_test_uSeg_2_nm_present_again.previous.fvSubnet == true
- ans_test_uSeg_2_nm_present_again.previous.description == "uSeg Attr object created using Ansible"

- name: Invalid test - ans_test_uSeg_3 present - attribute_type - mac and without value
Expand Down

0 comments on commit b68e063

Please sign in to comment.