Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nxos_switchport #37328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 16 additions & 11 deletions lib/ansible/modules/network/nxos/_nxos_switchport.py
Expand Up @@ -269,18 +269,23 @@ def remove_switchport_config_commands(interface, existing, proposed, module):
commands.append(command)

elif mode == 'trunk':
tv_check = existing.get('trunk_vlans_list') == proposed.get('trunk_vlans_list')

if tv_check:
existing_vlans = existing.get('trunk_vlans_list')
proposed_vlans = proposed.get('trunk_vlans_list')
vlans_to_remove = set(proposed_vlans).intersection(existing_vlans)

if vlans_to_remove:
proposed_allowed_vlans = proposed.get('trunk_allowed_vlans')
remove_trunk_allowed_vlans = proposed.get('trunk_vlans', proposed_allowed_vlans)
command = 'switchport trunk allowed vlan remove {0}'.format(remove_trunk_allowed_vlans)
commands.append(command)
# Supported Remove Scenarios for trunk_vlans_list
# 1) Existing: 1,2,3 Proposed: 1,2,3 - Remove all
# 2) Existing: 1,2,3 Proposed: 1,2 - Remove 1,2 Leave 3
# 3) Existing: 1,2,3 Proposed: 2,3 - Remove 2,3 Leave 1
# 4) Existing: 1,2,3 Proposed: 4,5,6 - None removed.
# 5) Existing: None Proposed: 1,2,3 - None removed.

existing_vlans = existing.get('trunk_vlans_list')
proposed_vlans = proposed.get('trunk_vlans_list')
vlans_to_remove = set(proposed_vlans).intersection(existing_vlans)

if vlans_to_remove:
proposed_allowed_vlans = proposed.get('trunk_allowed_vlans')
remove_trunk_allowed_vlans = proposed.get('trunk_vlans', proposed_allowed_vlans)
command = 'switchport trunk allowed vlan remove {0}'.format(remove_trunk_allowed_vlans)
commands.append(command)

native_check = existing.get('native_vlan') == proposed.get('native_vlan')
if native_check and proposed.get('native_vlan'):
Expand Down
33 changes: 31 additions & 2 deletions test/integration/targets/nxos_switchport/tests/common/sanity.yaml
Expand Up @@ -88,7 +88,7 @@

- assert: *false

- name: Ensure these VLANs are not being tagged on the trunk
- name: Remove full trunk vlan range 2-50.
nxos_switchport: &no_tag
interface: "{{ intname }}"
mode: trunk
Expand All @@ -99,12 +99,41 @@

- assert: *true

- name: "no tag vlan Idempotence"
- name: Check Idempotence Remove full trunk vlan range 2-50.
nxos_switchport: *no_tag
register: result

- assert: *false

- name: Reconfigure interface trunk port and ensure 2-50 are being tagged
nxos_switchport: *tag
register: result

- assert: *true

- name: Check Idempotence Reconfigure interface trunk port and ensure 2-50 are being tagged
nxos_switchport: *tag
register: result

- assert: *false

- name: Remove partial trunk vlan range 30-4096 are removed
nxos_switchport: &partial
interface: "{{ intname }}"
mode: trunk
trunk_vlans: 30-4094
state: absent
provider: "{{ connection }}"
register: result

- assert: *true

- name: Check Idempotence Remove partial trunk vlan range 30-4096 are removed
nxos_switchport: *partial
register: result

- assert: *false

- name: put interface default state
nxos_switchport: *def_swi
register: result
Expand Down