Skip to content

Commit

Permalink
[ignore] Modify aci_tenant_action_rule_profile module and test case t…
Browse files Browse the repository at this point in the history
…o deal with non-exsiting child classes for APIC version prior to 5.0
  • Loading branch information
gmicol committed Nov 3, 2023
1 parent c0680b7 commit 96d3877
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 23 deletions.
26 changes: 15 additions & 11 deletions plugins/modules/aci_tenant_action_rule_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def main():
rtctrlSetWeight=dict(attribute_input=module.params.get("set_weight"), attribute_name="weight"),
)

# This condition deal with child classes which do not exist in APIC version 4.2 and prior.
for class_name in ["rtctrlSetNhUnchanged", "rtctrlSetRedistMultipath"]:
if child_classes[class_name].get("attribute_input") is None:
child_classes.pop(class_name)

aci.construct_url(
root_class=dict(
aci_class="fvTenant",
Expand Down Expand Up @@ -421,17 +426,16 @@ def main():
if isinstance(attribute_input, dict):
only_none = all(value is None for value in attribute_input.values())
# This condition checks if the child object needs to be deleted depending on the type of the corresponding attribute input (bool, str, dict).
if attribute_input == "" or attribute_input is False or only_none:
if isinstance(aci.existing, list) and len(aci.existing) > 0:
for child in aci.existing[0].get("rtctrlAttrP", {}).get("children", {}):
if child.get(class_name):
child_configs.append(
{
class_name: dict(
attributes=dict(status="deleted"),
),
}
)
if (attribute_input == "" or attribute_input is False or only_none) and isinstance(aci.existing, list) and len(aci.existing) > 0:
for child in aci.existing[0].get("rtctrlAttrP", {}).get("children", {}):
if child.get(class_name):
child_configs.append(
{
class_name: dict(
attributes=dict(status="deleted"),
),
}
)
# This condition checks if the child object needs to be modified or created depending on the type of the corresponding attribute input.
elif attribute_input != "" or attribute_input is True or attribute_input != {}:
if class_name == "rtctrlSetComm" and isinstance(attribute_input, dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@
max_suppress_time: 100
state: absent

- name: Ensure second action rule profile does not exist
aci_tenant_action_rule_profile: &aci_tenant_action_rule_profile_2_absent
- name: Ensure second action rule profile does not exist - APIC version >= 5.0
when: version.current.0.topSystem.attributes.version is version('5', '>=')
aci_tenant_action_rule_profile: &aci_tenant_action_rule_profile_2_5_absent
<<: *aci_tenant_present
name: anstest_2
set_next_hop: 1.1.1.2
next_hop_propagation: true
multipath: true
state: absent

- name: Ensure second action rule profile does not exist - APIC version < 5.0
when: version.current.0.topSystem.attributes.version is version('5', '<')
aci_tenant_action_rule_profile: &aci_tenant_action_rule_profile_2_absent
<<: *aci_tenant_present
name: anstest_2
set_next_hop: 1.1.1.2
state: absent

- name: Create first action rule profile (check_mode)
aci_tenant_action_rule_profile: &aci_tenant_action_rule_profile_present
Expand All @@ -81,13 +90,21 @@
<<: *aci_tenant_action_rule_profile_present
register: idempotency_add_tenant_action_rule_profile_1

- name: Create second action rule profile
- name: Create second action rule profile - APIC version >= 5.0
when: version.current.0.topSystem.attributes.version is version('5', '>=')
aci_tenant_action_rule_profile: &aci_tenant_action_rule_profile_2_5_present
<<: *aci_tenant_action_rule_profile_2_5_absent
state: present
register: nm_add_tenant_action_rule_profile_2_5

- name: Create second action rule profile - APIC version < 5.0
when: version.current.0.topSystem.attributes.version is version('5', '<')
aci_tenant_action_rule_profile: &aci_tenant_action_rule_profile_2_present
<<: *aci_tenant_action_rule_profile_2_absent
state: present
register: nm_add_tenant_action_rule_profile_2

- name: Asserts for creation tasks
- name: Asserts for creation tasks for action rule profile 1
assert:
that:
- cm_add_tenant_action_rule_profile_1 is changed
Expand All @@ -108,11 +125,24 @@
- nm_add_tenant_action_rule_profile_1.current.0.rtctrlAttrP.children.6.rtctrlSetComm.attributes.setCriteria == "replace"
- nm_add_tenant_action_rule_profile_1.current.0.rtctrlAttrP.children.7.rtctrlSetTag.attributes.tag == "100"
- idempotency_add_tenant_action_rule_profile_1 is not changed

- name: Asserts for creation tasks for action rule profile 2 - APIC version >= 5.0
when: version.current.0.topSystem.attributes.version is version('5', '>=')
assert:
that:
- nm_add_tenant_action_rule_profile_2_5 is changed
- nm_add_tenant_action_rule_profile_2_5.current.0.rtctrlAttrP.attributes.name == "anstest_2"
- nm_add_tenant_action_rule_profile_2_5.current.0.rtctrlAttrP.children.0.rtctrlSetRedistMultipath.attributes.descr == ""
- nm_add_tenant_action_rule_profile_2_5.current.0.rtctrlAttrP.children.1.rtctrlSetNhUnchanged.attributes.descr == ""
- nm_add_tenant_action_rule_profile_2_5.current.0.rtctrlAttrP.children.2.rtctrlSetNh.attributes.addr == "1.1.1.2"

- name: Asserts for creation tasks for action rule profile 2 - APIC version < 5.0
when: version.current.0.topSystem.attributes.version is version('5', '<')
assert:
that:
- nm_add_tenant_action_rule_profile_2 is changed
- nm_add_tenant_action_rule_profile_2.current.0.rtctrlAttrP.attributes.name == "anstest_2"
- nm_add_tenant_action_rule_profile_2.current.0.rtctrlAttrP.children.0.rtctrlSetRedistMultipath.attributes.descr == ""
- nm_add_tenant_action_rule_profile_2.current.0.rtctrlAttrP.children.1.rtctrlSetNhUnchanged.attributes.descr == ""
- nm_add_tenant_action_rule_profile_2.current.0.rtctrlAttrP.children.2.rtctrlSetNh.attributes.addr == "1.1.1.2"
- nm_add_tenant_action_rule_profile_2.current.0.rtctrlAttrP.children.0.rtctrlSetNh.attributes.addr == "1.1.1.2"

- name: Query all action rule profiles
aci_tenant_action_rule_profile:
Expand Down Expand Up @@ -171,22 +201,42 @@
<<: *aci_tenant_action_rule_profile_children_deleted
register: idempotency_delete_children_tenant_action_rule_profile_1

- name: Delete children for second action rule profile (normal_mode)
- name: Delete children for second action rule profile - APIC version >= 5.0
when: version.current.0.topSystem.attributes.version is version('5', '>=')
aci_tenant_action_rule_profile:
<<: *aci_tenant_action_rule_profile_2_present
<<: *aci_tenant_action_rule_profile_2_5_present
set_next_hop: ""
next_hop_propagation: false
multipath: false
register: nm_delete_children_tenant_action_rule_profile_2_5

- name: Delete children for second action rule profile - APIC version < 5.0
when: version.current.0.topSystem.attributes.version is version('5', '<')
aci_tenant_action_rule_profile:
<<: *aci_tenant_action_rule_profile_2_present
set_next_hop: ""
register: nm_delete_children_tenant_action_rule_profile_2

- name: Asserts for deletion tasks
- name: Asserts for deletion tasks for action rule profile 1
assert:
that:
- cm_delete_children_tenant_action_rule_profile_1 is changed
- cm_delete_children_tenant_action_rule_profile_1.current == cm_delete_children_tenant_action_rule_profile_1.previous
- nm_delete_children_tenant_action_rule_profile_1 is changed
- nm_delete_children_tenant_action_rule_profile_1.current.0.rtctrlAttrP | length == 1
- idempotency_delete_children_tenant_action_rule_profile_1 is not changed

- name: Asserts for deletion tasks for action rule profile 2 - APIC version >= 5.0
when: version.current.0.topSystem.attributes.version is version('5', '>=')
assert:
that:
- nm_delete_children_tenant_action_rule_profile_2_5 is changed
- nm_delete_children_tenant_action_rule_profile_2_5.current.0.rtctrlAttrP | length == 1

- name: Asserts for deletion tasks for action rule profile 2 - APIC version < 5.0
when: version.current.0.topSystem.attributes.version is version('5', '<')
assert:
that:
- nm_delete_children_tenant_action_rule_profile_2 is changed
- nm_delete_children_tenant_action_rule_profile_2.current.0.rtctrlAttrP | length == 1

Expand All @@ -209,13 +259,21 @@
state: absent
register: idempotency_delete_tenant_action_rule_profile_1

- name: Delete second action rule profile (normal_mode)
- name: Delete second action rule profile - APIC version >= 5.0
when: version.current.0.topSystem.attributes.version is version('5', '>=')
aci_tenant_action_rule_profile:
<<: *aci_tenant_action_rule_profile_2_5_present
state: absent
register: nm_delete_tenant_action_rule_profile_2_5

- name: Delete second action rule profile - APIC version < 5.0
when: version.current.0.topSystem.attributes.version is version('5', '<')
aci_tenant_action_rule_profile:
<<: *aci_tenant_action_rule_profile_2_present
state: absent
register: nm_delete_tenant_action_rule_profile_2

- name: Asserts for deletion tasks
- name: Asserts for deletion tasks for action rule profile 1
assert:
that:
- cm_delete_tenant_action_rule_profile_1 is changed
Expand All @@ -225,6 +283,19 @@
- nm_delete_tenant_action_rule_profile_1.current == []
- idempotency_delete_tenant_action_rule_profile_1 is not changed
- idempotency_delete_tenant_action_rule_profile_1.previous == []

- name: Asserts for deletion tasks for action rule profile 2 - APIC version >= 5.0
when: version.current.0.topSystem.attributes.version is version('5', '>=')
assert:
that:
- nm_delete_tenant_action_rule_profile_2_5 is changed
- nm_delete_tenant_action_rule_profile_2_5.previous != []
- nm_delete_tenant_action_rule_profile_2_5.current == []

- name: Asserts for deletion tasks for action rule profile 2 - APIC version < 5.0
when: version.current.0.topSystem.attributes.version is version('5', '<')
assert:
that:
- nm_delete_tenant_action_rule_profile_2 is changed
- nm_delete_tenant_action_rule_profile_2.previous != []
- nm_delete_tenant_action_rule_profile_2.current == []
Expand Down

0 comments on commit 96d3877

Please sign in to comment.