mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix issue with vNIC redundancy templates (#36608)
* Fix bug with redundancy templates and add integration tests for redundancy templates. * vlan_list absent state support and fix for vlans as strings in vlan_list
This commit is contained in:
parent
f28cf6e8e9
commit
f8f22f77ed
2 changed files with 172 additions and 25 deletions
|
@ -93,6 +93,11 @@ options:
|
||||||
- " Designates the VLAN as a native VLAN. Only one VLAN in the list can be a native VLAN."
|
- " Designates the VLAN as a native VLAN. Only one VLAN in the list can be a native VLAN."
|
||||||
- " [choices: 'no', 'yes']"
|
- " [choices: 'no', 'yes']"
|
||||||
- " [Default: 'no']"
|
- " [Default: 'no']"
|
||||||
|
- "- state"
|
||||||
|
- " If present, will verify VLAN is present on template."
|
||||||
|
- " If absent, will verify VLAN is absent on template."
|
||||||
|
- " choices: [present, absent]"
|
||||||
|
- " default: present"
|
||||||
cdn_source:
|
cdn_source:
|
||||||
description:
|
description:
|
||||||
- CDN Source field.
|
- CDN Source field.
|
||||||
|
@ -161,7 +166,7 @@ EXAMPLES = r'''
|
||||||
vlans_list:
|
vlans_list:
|
||||||
- name: default
|
- name: default
|
||||||
native: 'yes'
|
native: 'yes'
|
||||||
- name: finance
|
state: present
|
||||||
|
|
||||||
- name: Remove vNIC template
|
- name: Remove vNIC template
|
||||||
ucs_vnic_template:
|
ucs_vnic_template:
|
||||||
|
@ -178,6 +183,18 @@ EXAMPLES = r'''
|
||||||
password: password
|
password: password
|
||||||
name: vNIC-A-B
|
name: vNIC-A-B
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Remove VLAN from template
|
||||||
|
ucs_vnic_template:
|
||||||
|
hostname: 172.16.143.150
|
||||||
|
username: admin
|
||||||
|
password: password
|
||||||
|
name: vNIC-A-B
|
||||||
|
fabric: A-B
|
||||||
|
vlans_list:
|
||||||
|
- name: default
|
||||||
|
native: 'yes'
|
||||||
|
state: absent
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r'''
|
||||||
|
@ -250,6 +267,8 @@ def main():
|
||||||
for vlan in module.params['vlans_list']:
|
for vlan in module.params['vlans_list']:
|
||||||
if not vlan.get('native'):
|
if not vlan.get('native'):
|
||||||
vlan['native'] = 'no'
|
vlan['native'] = 'no'
|
||||||
|
if not vlan.get('state'):
|
||||||
|
vlan['state'] = 'present'
|
||||||
# for target 'adapter', change to internal UCS Manager spelling 'adaptor'
|
# for target 'adapter', change to internal UCS Manager spelling 'adaptor'
|
||||||
if module.params['target'] == 'adapter':
|
if module.params['target'] == 'adapter':
|
||||||
module.params['target'] = 'adaptor'
|
module.params['target'] = 'adaptor'
|
||||||
|
@ -271,19 +290,27 @@ def main():
|
||||||
kwargs['nw_ctrl_policy_name'] = module.params['network_control_policy']
|
kwargs['nw_ctrl_policy_name'] = module.params['network_control_policy']
|
||||||
kwargs['pin_to_group_name'] = module.params['pin_group']
|
kwargs['pin_to_group_name'] = module.params['pin_group']
|
||||||
kwargs['stats_policy_name'] = module.params['stats_policy']
|
kwargs['stats_policy_name'] = module.params['stats_policy']
|
||||||
if (mo.check_prop_match(**kwargs)):
|
if mo.check_prop_match(**kwargs):
|
||||||
# top-level props match, check next level mo/props
|
# top-level props match, check next level mo/props
|
||||||
if not module.params.get('vlans_list'):
|
if not module.params.get('vlans_list'):
|
||||||
props_match = True
|
props_match = True
|
||||||
else:
|
else:
|
||||||
# check vlan props
|
# check vlan props
|
||||||
for vlan in module.params['vlans_list']:
|
for vlan in module.params['vlans_list']:
|
||||||
child_dn = dn + '/if-' + vlan['name']
|
child_dn = dn + '/if-' + str(vlan['name'])
|
||||||
mo_1 = ucs.login_handle.query_dn(child_dn)
|
mo_1 = ucs.login_handle.query_dn(child_dn)
|
||||||
|
if vlan['state'] == 'absent':
|
||||||
|
if mo_1:
|
||||||
|
props_match = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
if mo_1:
|
if mo_1:
|
||||||
kwargs = dict(default_net=vlan['native'])
|
kwargs = dict(default_net=vlan['native'])
|
||||||
if (mo_1.check_prop_match(**kwargs)):
|
if mo_1.check_prop_match(**kwargs):
|
||||||
props_match = True
|
props_match = True
|
||||||
|
else:
|
||||||
|
props_match = False
|
||||||
|
break
|
||||||
|
|
||||||
if not props_match:
|
if not props_match:
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
|
@ -306,7 +333,7 @@ def main():
|
||||||
descr=module.params['description'],
|
descr=module.params['description'],
|
||||||
switch_id=module.params['fabric'],
|
switch_id=module.params['fabric'],
|
||||||
redundancy_pair_type=module.params['redundancy_type'],
|
redundancy_pair_type=module.params['redundancy_type'],
|
||||||
peer_redundancy_templ_name=module.params['peer_redundancy_templ'],
|
peer_redundancy_templ_name=module.params['peer_redundancy_template'],
|
||||||
target=module.params['target'],
|
target=module.params['target'],
|
||||||
templ_type=module.params['template_type'],
|
templ_type=module.params['template_type'],
|
||||||
cdn_source=module.params['cdn_source'],
|
cdn_source=module.params['cdn_source'],
|
||||||
|
@ -321,9 +348,14 @@ def main():
|
||||||
|
|
||||||
if module.params.get('vlans_list'):
|
if module.params.get('vlans_list'):
|
||||||
for vlan in module.params['vlans_list']:
|
for vlan in module.params['vlans_list']:
|
||||||
|
if vlan['state'] == 'absent':
|
||||||
|
child_dn = dn + '/if-' + str(vlan['name'])
|
||||||
|
mo_1 = ucs.login_handle.query_dn(child_dn)
|
||||||
|
ucs.login_handle.remove_mo(mo_1)
|
||||||
|
else:
|
||||||
mo_1 = VnicEtherIf(
|
mo_1 = VnicEtherIf(
|
||||||
parent_mo_or_dn=mo,
|
parent_mo_or_dn=mo,
|
||||||
name=vlan['name'],
|
name=str(vlan['name']),
|
||||||
default_net=vlan['native'],
|
default_net=vlan['native'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,18 @@
|
||||||
name: vNIC-A-B
|
name: vNIC-A-B
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: vNIC primary template absent
|
||||||
|
ucs_vnic_template: &vnic_primary_templates_absent
|
||||||
|
<<: *login_info
|
||||||
|
name: vNIC-A
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: vNIC secondary template absent
|
||||||
|
ucs_vnic_template: &vnic_secondary_templates_absent
|
||||||
|
<<: *login_info
|
||||||
|
name: vNIC-B
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
|
||||||
# Test present (check_mode)
|
# Test present (check_mode)
|
||||||
- name: vNIC template present (check_mode)
|
- name: vNIC template present (check_mode)
|
||||||
|
@ -29,16 +41,53 @@
|
||||||
vlans_list:
|
vlans_list:
|
||||||
- name: default
|
- name: default
|
||||||
native: 'yes'
|
native: 'yes'
|
||||||
- name: finance
|
- name: 10
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: cm_vnic_templates_present
|
register: cm_vnic_templates_present
|
||||||
|
|
||||||
|
- name: vNIC primary template present (check_mode)
|
||||||
|
ucs_vnic_template: &vnic_primary_templates_present
|
||||||
|
<<: *login_info
|
||||||
|
name: vNIC-A
|
||||||
|
fabric: A
|
||||||
|
redundancy_type: primary
|
||||||
|
peer_redundancy_templ: vNIC-B
|
||||||
|
template_type: updating-template
|
||||||
|
mtu: '9000'
|
||||||
|
mac_pool: MAC-Pool-A
|
||||||
|
network_control_policy: Enable-CDP-LLDP
|
||||||
|
vlans_list:
|
||||||
|
- name: default
|
||||||
|
native: 'yes'
|
||||||
|
- name: finance
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_primary_templates_present
|
||||||
|
|
||||||
|
- name: vNIC secondary template present (check_mode)
|
||||||
|
ucs_vnic_template: &vnic_secondary_templates_present
|
||||||
|
<<: *login_info
|
||||||
|
name: vNIC-B
|
||||||
|
fabric: B
|
||||||
|
redundancy_type: secondary
|
||||||
|
peer_redundancy_templ: vNIC-A
|
||||||
|
mac_pool: MAC-Pool-B
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_secondary_templates_present
|
||||||
|
|
||||||
|
|
||||||
# Present (normal mode)
|
# Present (normal mode)
|
||||||
- name: vNIC template present (normal mode)
|
- name: vNIC template present (normal mode)
|
||||||
ucs_vnic_template: *vnic_templates_present
|
ucs_vnic_template: *vnic_templates_present
|
||||||
register: nm_vnic_templates_present
|
register: nm_vnic_templates_present
|
||||||
|
|
||||||
|
- name: vNIC primary template present (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_primary_templates_present
|
||||||
|
register: nm_vnic_primary_templates_present
|
||||||
|
|
||||||
|
- name: vNIC secondary template present (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_secondary_templates_present
|
||||||
|
register: nm_vnic_secondary_templates_present
|
||||||
|
|
||||||
|
|
||||||
# Test present again (idempotent)
|
# Test present again (idempotent)
|
||||||
- name: vNIC template present again (check_mode)
|
- name: vNIC template present again (check_mode)
|
||||||
|
@ -46,12 +95,30 @@
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: cm_vnic_templates_present_again
|
register: cm_vnic_templates_present_again
|
||||||
|
|
||||||
|
- name: vNIC primary template present again (check_mode)
|
||||||
|
ucs_vnic_template: *vnic_primary_templates_present
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_primary_templates_present_again
|
||||||
|
|
||||||
|
- name: vNIC secondary template present again (check_mode)
|
||||||
|
ucs_vnic_template: *vnic_secondary_templates_present
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_secondary_templates_present_again
|
||||||
|
|
||||||
|
|
||||||
# Present again (normal mode)
|
# Present again (normal mode)
|
||||||
- name: vNIC template present again (normal mode)
|
- name: vNIC template present again (normal mode)
|
||||||
ucs_vnic_template: *vnic_templates_present
|
ucs_vnic_template: *vnic_templates_present
|
||||||
register: nm_vnic_templates_present_again
|
register: nm_vnic_templates_present_again
|
||||||
|
|
||||||
|
- name: vNIC primary template present again (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_primary_templates_present
|
||||||
|
register: nm_vnic_primary_templates_present_again
|
||||||
|
|
||||||
|
- name: vNIC secondary template present again (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_secondary_templates_present
|
||||||
|
register: nm_vnic_secondary_templates_present_again
|
||||||
|
|
||||||
|
|
||||||
# Verfiy present
|
# Verfiy present
|
||||||
- name: Verify vNIC template present results
|
- name: Verify vNIC template present results
|
||||||
|
@ -59,42 +126,50 @@
|
||||||
that:
|
that:
|
||||||
- cm_vnic_templates_present.changed == nm_vnic_templates_present.changed == true
|
- cm_vnic_templates_present.changed == nm_vnic_templates_present.changed == true
|
||||||
- cm_vnic_templates_present_again.changed == nm_vnic_templates_present_again.changed == false
|
- cm_vnic_templates_present_again.changed == nm_vnic_templates_present_again.changed == false
|
||||||
|
- cm_vnic_primary_templates_present.changed == nm_vnic_primary_templates_present.changed == true
|
||||||
|
- cm_vnic_primary_templates_present_again.changed == nm_vnic_primary_templates_present_again.changed == false
|
||||||
|
- cm_vnic_secondary_templates_present.changed == nm_vnic_secondary_templates_present.changed == true
|
||||||
|
- cm_vnic_secondary_templates_present_again.changed == nm_vnic_secondary_templates_present_again.changed == false
|
||||||
|
|
||||||
|
|
||||||
# Test change (check_mode)
|
# Test change (check_mode)
|
||||||
- name: vNIC template description change (check_mode)
|
- name: vNIC template change (check_mode)
|
||||||
ucs_vnic_template: &vnic_templates_change
|
ucs_vnic_template: &vnic_templates_change
|
||||||
<<: *vnic_templates_present
|
<<: *vnic_templates_present
|
||||||
descr: Testing Ansible
|
vlans_list:
|
||||||
|
- name: default
|
||||||
|
native: 'yes'
|
||||||
|
- name: 10
|
||||||
|
state: absent
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: cm_vnic_templates_descr_change
|
register: cm_vnic_templates_change
|
||||||
|
|
||||||
|
|
||||||
# Change (normal mode)
|
# Change (normal mode)
|
||||||
- name: vNIC template description change (normal mode)
|
- name: vNIC template change (normal mode)
|
||||||
ucs_vnic_template: *vnic_templates_change
|
ucs_vnic_template: *vnic_templates_change
|
||||||
register: nm_vnic_templates_descr_change
|
register: nm_vnic_templates_change
|
||||||
|
|
||||||
|
|
||||||
# Test change again (idempotent)
|
# Test change again (idempotent)
|
||||||
- name: vNIC template description again (check_mode)
|
- name: vNIC template change again (check_mode)
|
||||||
ucs_vnic_template: *vnic_templates_change
|
ucs_vnic_template: *vnic_templates_change
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: cm_vnic_templates_descr_change_again
|
register: cm_vnic_templates_change_again
|
||||||
|
|
||||||
|
|
||||||
# Change again (normal mode)
|
# Change again (normal mode)
|
||||||
- name: vNIC template description change again (normal mode)
|
- name: vNIC template change again (normal mode)
|
||||||
ucs_vnic_template: *vnic_templates_change
|
ucs_vnic_template: *vnic_templates_change
|
||||||
register: nm_vnic_templates_descr_change_again
|
register: nm_vnic_templates_change_again
|
||||||
|
|
||||||
|
|
||||||
# Verfiy change
|
# Verfiy change
|
||||||
- name: Verify vNIC template change results
|
- name: Verify vNIC template change results
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- cm_vnic_templates_descr_change.changed == nm_vnic_templates_descr_change.changed == true
|
- cm_vnic_templates_change.changed == nm_vnic_templates_change.changed == true
|
||||||
- cm_vnic_templates_descr_change_again.changed == nm_vnic_templates_descr_change_again.changed == false
|
- cm_vnic_templates_change_again.changed == nm_vnic_templates_change_again.changed == false
|
||||||
|
|
||||||
|
|
||||||
# Teardown (clean environment)
|
# Teardown (clean environment)
|
||||||
|
@ -103,12 +178,30 @@
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: cm_vnic_templates_absent
|
register: cm_vnic_templates_absent
|
||||||
|
|
||||||
|
- name: vNIC primary template absent (check_mode)
|
||||||
|
ucs_vnic_template: *vnic_primary_templates_absent
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_primary_templates_absent
|
||||||
|
|
||||||
|
- name: vNIC secondary template absent (check_mode)
|
||||||
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_secondary_templates_absent
|
||||||
|
|
||||||
|
|
||||||
# Absent (normal mode)
|
# Absent (normal mode)
|
||||||
- name: vNIC template absent (normal mode)
|
- name: vNIC template absent (normal mode)
|
||||||
ucs_vnic_template: *vnic_templates_absent
|
ucs_vnic_template: *vnic_templates_absent
|
||||||
register: nm_vnic_templates_absent
|
register: nm_vnic_templates_absent
|
||||||
|
|
||||||
|
- name: vNIC primary template absent (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_primary_templates_absent
|
||||||
|
register: nm_vnic_primary_templates_absent
|
||||||
|
|
||||||
|
- name: vNIC secondary template absent (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
||||||
|
register: nm_vnic_secondary_templates_absent
|
||||||
|
|
||||||
|
|
||||||
# Test absent again (idempotent)
|
# Test absent again (idempotent)
|
||||||
- name: vNIC template absent again (check_mode)
|
- name: vNIC template absent again (check_mode)
|
||||||
|
@ -116,12 +209,30 @@
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
register: cm_vnic_templates_absent_again
|
register: cm_vnic_templates_absent_again
|
||||||
|
|
||||||
|
- name: vNIC primary template absent again (check_mode)
|
||||||
|
ucs_vnic_template: *vnic_primary_templates_absent
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_primary_templates_absent_again
|
||||||
|
|
||||||
|
- name: vNIC secondary template absent again (check_mode)
|
||||||
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
||||||
|
check_mode: yes
|
||||||
|
register: cm_vnic_secondary_templates_absent_again
|
||||||
|
|
||||||
|
|
||||||
# Absent again (normal mode)
|
# Absent again (normal mode)
|
||||||
- name: vNIC template absent again (normal mode)
|
- name: vNIC template absent again (normal mode)
|
||||||
ucs_vnic_template: *vnic_templates_absent
|
ucs_vnic_template: *vnic_templates_absent
|
||||||
register: nm_vnic_templates_absent_again
|
register: nm_vnic_templates_absent_again
|
||||||
|
|
||||||
|
- name: vNIC primary template absent again (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_primary_templates_absent
|
||||||
|
register: nm_vnic_primary_templates_absent_again
|
||||||
|
|
||||||
|
- name: vNIC secondary template absent again (normal mode)
|
||||||
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
||||||
|
register: nm_vnic_secondary_templates_absent_again
|
||||||
|
|
||||||
|
|
||||||
# Verfiy absent
|
# Verfiy absent
|
||||||
- name: Verify vNIC template absent results
|
- name: Verify vNIC template absent results
|
||||||
|
@ -129,3 +240,7 @@
|
||||||
that:
|
that:
|
||||||
- cm_vnic_templates_absent.changed == nm_vnic_templates_absent.changed == true
|
- cm_vnic_templates_absent.changed == nm_vnic_templates_absent.changed == true
|
||||||
- cm_vnic_templates_absent_again.changed == nm_vnic_templates_absent_again.changed == false
|
- cm_vnic_templates_absent_again.changed == nm_vnic_templates_absent_again.changed == false
|
||||||
|
- cm_vnic_primary_templates_absent.changed == nm_vnic_primary_templates_absent.changed == true
|
||||||
|
- cm_vnic_primary_templates_absent_again.changed == nm_vnic_primary_templates_absent_again.changed == false
|
||||||
|
- cm_vnic_secondary_templates_absent.changed == nm_vnic_secondary_templates_absent.changed == true
|
||||||
|
- cm_vnic_secondary_templates_absent_again.changed == nm_vnic_secondary_templates_absent_again.changed == false
|
||||||
|
|
Loading…
Reference in a new issue