From df6b0b0e9e05f16f72196c8105597289bae0d516 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Mon, 5 Nov 2018 19:21:01 +0100 Subject: [PATCH] aci_aptiplp: Support missing policy_group (#48000) * aci_aptiplp: Support missing policy_group * Adapt integration tests to fix * Add changelog fragment * Fix Co-Authored-By: dagwieers --- ...icy_leaf_profile-missing_policy_group.yaml | 2 + ...s_port_to_interface_policy_leaf_profile.py | 62 ++++++++++--------- .../tasks/main.yml | 14 ++++- 3 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 changelogs/fragments/aci_access_port_to_interface_policy_leaf_profile-missing_policy_group.yaml diff --git a/changelogs/fragments/aci_access_port_to_interface_policy_leaf_profile-missing_policy_group.yaml b/changelogs/fragments/aci_access_port_to_interface_policy_leaf_profile-missing_policy_group.yaml new file mode 100644 index 0000000000..d32a1a9a22 --- /dev/null +++ b/changelogs/fragments/aci_access_port_to_interface_policy_leaf_profile-missing_policy_group.yaml @@ -0,0 +1,2 @@ +bugfixes: +- aci_access_port_to_interface_policy_leaf_profile - Support missing policy_group diff --git a/lib/ansible/modules/network/aci/aci_access_port_to_interface_policy_leaf_profile.py b/lib/ansible/modules/network/aci/aci_access_port_to_interface_policy_leaf_profile.py index b55d61a5d1..8edc9449da 100644 --- a/lib/ansible/modules/network/aci/aci_access_port_to_interface_policy_leaf_profile.py +++ b/lib/ansible/modules/network/aci/aci_access_port_to_interface_policy_leaf_profile.py @@ -118,7 +118,7 @@ EXAMPLES = r''' access_port_selector: accessportselectorname leaf_port_blk: leafportblkname from_port: 13 - toi_port: 16 + to_port: 16 policy_group: policygroupname state: present delegate_to: localhost @@ -266,6 +266,13 @@ url: from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec from ansible.module_utils.basic import AnsibleModule +INTERFACE_TYPE_MAPPING = dict( + fex='uni/infra/funcprof/accportgrp-{0}', + port_channel='uni/infra/funcprof/accbundle-{0}', + switch_port='uni/infra/funcprof/accportgrp-{0}', + vpc='uni/infra/funcprof/accbundle-{0}', +) + def main(): argument_spec = aci_argument_spec() @@ -306,6 +313,30 @@ def main(): interface_type = module.params['interface_type'] state = module.params['state'] + # Build child_configs dyanmically + child_configs = [dict( + infraPortBlk=dict( + attributes=dict( + descr=leaf_port_blk_description, + name=leaf_port_blk, + fromPort=from_port, + toPort=to_port, + fromCard=from_card, + toCard=to_card, + ), + ), + )] + + # Add infraRsAccBaseGrp only when policy_group was defined + if policy_group is not None: + child_configs.append(dict( + infraRsAccBaseGrp=dict( + attributes=dict( + tDn=INTERFACE_TYPE_MAPPING[interface_type].format(policy_group), + ), + ), + )) + aci = ACIModule(module) aci.construct_url( root_class=dict( @@ -324,13 +355,6 @@ def main(): child_classes=['infraPortBlk', 'infraRsAccBaseGrp'], ) - INTERFACE_TYPE_MAPPING = dict( - fex='uni/infra/funcprof/accportgrp-{0}'.format(policy_group), - port_channel='uni/infra/funcprof/accbundle-{0}'.format(policy_group), - switch_port='uni/infra/funcprof/accportgrp-{0}'.format(policy_group), - vpc='uni/infra/funcprof/accbundle-{0}'.format(policy_group), - ) - aci.get_existing() if state == 'present': @@ -341,27 +365,7 @@ def main(): name=access_port_selector, # type='range', ), - child_configs=[ - dict( - infraPortBlk=dict( - attributes=dict( - descr=leaf_port_blk_description, - name=leaf_port_blk, - fromPort=from_port, - toPort=to_port, - fromCard=from_card, - toCard=to_card, - ), - ), - ), - dict( - infraRsAccBaseGrp=dict( - attributes=dict( - tDn=INTERFACE_TYPE_MAPPING[interface_type], - ), - ), - ), - ], + child_configs=child_configs, ) aci.get_diff(aci_class='infraHPortS') diff --git a/test/integration/targets/aci_access_port_to_interface_policy_leaf_profile/tasks/main.yml b/test/integration/targets/aci_access_port_to_interface_policy_leaf_profile/tasks/main.yml index 8c920a297e..c21c71282b 100644 --- a/test/integration/targets/aci_access_port_to_interface_policy_leaf_profile/tasks/main.yml +++ b/test/integration/targets/aci_access_port_to_interface_policy_leaf_profile/tasks/main.yml @@ -8,6 +8,18 @@ msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.' when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined +- name: Ensuring bindings do not already exist + aci_access_port_to_interface_policy_leaf_profile: + host: "{{ aci_hostname }}" + username: "{{ aci_username }}" + password: "{{ aci_password }}" + validate_certs: '{{ aci_validate_certs | default(false) }}' + use_ssl: '{{ aci_use_ssl | default(true) }}' + use_proxy: '{{ aci_use_proxy | default(true) }}' + leaf_interface_profile: leafintprftest + access_port_selector: anstest_accessportselector + state: absent + - name: Ensuring Interface Policy Leaf profile exists for kick off aci_interface_policy_leaf_profile: &aci_interface_policy_leaf_profile_present host: "{{ aci_hostname }}" @@ -53,7 +65,7 @@ - accessport_to_intf_check_mode_present is changed - accessport_to_intf_present is changed - accessport_to_intf_present.previous == [] - - 'accessport_to_intf_present.sent == {"infraHPortS": {"attributes": {"name": "anstest_accessportselector"}, "children": [{"infraRsAccBaseGrp": {"attributes": {"tDn": "uni/infra/funcprof/accportgrp-None"}}}]}}' + - 'accessport_to_intf_present.sent == {"infraHPortS": {"attributes": {"name": "anstest_accessportselector"}}}' - accessport_to_intf_idempotent is not changed - accessport_to_intf_idempotent.sent == {} - accessport_to_intf_update is changed