From 591b074e43358582b1cdaee1bc644b52a99dc3a7 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Mon, 5 Nov 2018 19:02:06 +0100 Subject: [PATCH] aci_switch_leaf_selector: Support missing policy_group (#47992) * aci_switch_leaf_selector: Support empty policy_group * Reorganize code * Adapt integration tests to fix --- ...f_selector-support_empty_policy_group.yaml | 2 + .../network/aci/aci_switch_leaf_selector.py | 44 +++++++++++-------- .../aci_switch_leaf_selector/tasks/main.yml | 2 +- 3 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 changelogs/fragments/47668-aci_switch_leaf_selector-support_empty_policy_group.yaml diff --git a/changelogs/fragments/47668-aci_switch_leaf_selector-support_empty_policy_group.yaml b/changelogs/fragments/47668-aci_switch_leaf_selector-support_empty_policy_group.yaml new file mode 100644 index 00000000000..b9ff26f81b2 --- /dev/null +++ b/changelogs/fragments/47668-aci_switch_leaf_selector-support_empty_policy_group.yaml @@ -0,0 +1,2 @@ +bugfixes: +- aci_switch_leaf_selector - Support empty policy_group diff --git a/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py b/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py index 358ec63a8fa..6ad7017db89 100644 --- a/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py +++ b/lib/ansible/modules/network/aci/aci_switch_leaf_selector.py @@ -260,6 +260,30 @@ def main(): policy_group = module.params['policy_group'] state = module.params['state'] + # Build child_configs dynamically + child_configs = [ + dict( + infraNodeBlk=dict( + attributes=dict( + descr=leaf_node_blk_description, + name=leaf_node_blk, + from_=from_, + to_=to_, + ), + ), + ), + ] + + # Add infraRsAccNodePGrp only when policy_group was defined + if policy_group is not None: + child_configs.append(dict( + infraRsAccNodePGrp=dict( + attributes=dict( + tDn='uni/infra/funcprof/accnodepgrp-{0}'.format(policy_group), + ), + ), + )) + aci = ACIModule(module) aci.construct_url( root_class=dict( @@ -289,25 +313,7 @@ def main(): descr=description, name=leaf, ), - child_configs=[ - dict( - infraNodeBlk=dict( - attributes=dict( - descr=leaf_node_blk_description, - name=leaf_node_blk, - from_=from_, - to_=to_, - ), - ), - ), - dict( - infraRsAccNodePGrp=dict( - attributes=dict( - tDn='uni/infra/funcprof/accnodepgrp-{0}'.format(policy_group), - ), - ), - ), - ], + child_configs=child_configs, ) aci.get_diff(aci_class='infraLeafS') diff --git a/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml b/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml index 95e81d27124..fccc77c9839 100644 --- a/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml +++ b/test/integration/targets/aci_switch_leaf_selector/tasks/main.yml @@ -68,7 +68,7 @@ - sw_leaf_selec_check_mode_present is changed - sw_leaf_selec_present is changed - sw_leaf_selec_present.previous == [] - - 'sw_leaf_selec_present.sent == {"infraLeafS": {"attributes": {"name": "leaf_selector_name"}, "children": [{"infraNodeBlk": {"attributes": {"from_": "1011", "name": "node_blk_name", "to_": "1011"}}},{"infraRsAccNodePGrp": {"attributes": {"tDn": "uni/infra/funcprof/accnodepgrp-None"}}}]}}' + - 'sw_leaf_selec_present.sent == {"infraLeafS": {"attributes": {"name": "leaf_selector_name"}, "children": [{"infraNodeBlk": {"attributes": {"from_": "1011", "name": "node_blk_name", "to_": "1011"}}}]}}' - sw_leaf_selec_idempotent is not changed - sw_leaf_selec_idempotent.sent == {} - sw_leaf_selec_update is changed