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 <dag@wieers.com>
pull/48303/head
Dag Wieers 6 years ago committed by John R Barker
parent d1f6ff646a
commit df6b0b0e9e

@ -0,0 +1,2 @@
bugfixes:
- aci_access_port_to_interface_policy_leaf_profile - Support missing policy_group

@ -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')

@ -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

Loading…
Cancel
Save