nxos_vlan: fix broken purge behavior (issue #57101) (#57229)

* nxos_vlan: fix broken purge behavior (issue #57101)

Symptoms/Analysis:
- `nxos_vlan` `purge: true` would fail when `purge` was trying to delete all unspecified vlans, including vlan 1.
- `nxos` devices do not allow removing vlan 1 and raise a cli exception error
- Previous fix #55144 caused a side effect when `purge` was used: vlan changes specified by `aggregate` were ignored; e.g.
 - vlan 4 is not present; playbook specifies `aggregate: { vlan: 4 }, purge: true`
 - results in proper purging but vlan 4 is not created

Solutions:
- ignore vlan 1 when purging
- remove the `not purge` check from state present logic

Added additional unit tests and integration tests.
Tested against all regression platforms.

* PEP fixes

* Add agg_show_vlan_brief.txt fixture

* Add warning for removing vlan 1

* change method name check
This commit is contained in:
Chris Van Heuveln
2019-06-03 23:44:09 -04:00
committed by Trishna Guha
parent 333f54ec3b
commit 6bb13bbb84
5 changed files with 139 additions and 4 deletions

View File

@@ -84,6 +84,7 @@ options:
description:
- Purge VLANs not defined in the I(aggregate) parameter.
This parameter can be used without aggregate as well.
- Removal of Vlan 1 is not allowed and will be ignored by purge.
type: bool
default: 'no'
delay:
@@ -220,7 +221,7 @@ def map_obj_to_commands(updates, module):
if obj_in_have:
commands.append('no vlan {0}'.format(vlan_id))
elif state == 'present' and not purge:
elif state == 'present':
if not obj_in_have:
commands.append('vlan {0}'.format(vlan_id))
@@ -318,6 +319,9 @@ def map_obj_to_commands(updates, module):
if purge:
for h in have:
if h['vlan_id'] == '1':
module.warn("Deletion of vlan 1 is not allowed; purge will ignore vlan 1")
continue
obj_in_want = search_obj_in_list(h['vlan_id'], want)
if not obj_in_want:
commands.append('no vlan {0}'.format(h['vlan_id']))