Fix eos_l2_interface idempotency (#56531)
* Attempt to handle just mode trunk properly * Add test for trunk-only config and clean up tests * Add missing eapi tests and remove references to provider as we do not test local
This commit is contained in:
parent
18f22de67e
commit
63e33f7e71
3 changed files with 149 additions and 76 deletions
|
@ -119,9 +119,8 @@ def search_obj_in_list(name, lst):
|
|||
return None
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module):
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
want, have = updates
|
||||
|
||||
for w in want:
|
||||
name = w['name']
|
||||
|
@ -170,11 +169,10 @@ def map_obj_to_commands(updates, module):
|
|||
if mode != obj_in_have['mode']:
|
||||
if obj_in_have['mode'] == 'access':
|
||||
commands.append('no switchport access vlan {0}'.format(obj_in_have['access_vlan']))
|
||||
if native_vlan:
|
||||
commands.append('switchport mode trunk')
|
||||
if native_vlan:
|
||||
commands.append('switchport trunk native vlan {0}'.format(native_vlan))
|
||||
if trunk_allowed_vlans:
|
||||
commands.append('switchport mode trunk')
|
||||
commands.append('switchport trunk allowed vlan {0}'.format(trunk_allowed_vlans))
|
||||
else:
|
||||
if obj_in_have['native_vlan']:
|
||||
|
@ -189,7 +187,6 @@ def map_obj_to_commands(updates, module):
|
|||
if access_vlan != obj_in_have['access_vlan']:
|
||||
commands.append('switchport access vlan {0}'.format(access_vlan))
|
||||
else:
|
||||
commands.append('switchport mode {0}'.format(mode))
|
||||
if native_vlan != obj_in_have['native_vlan'] and native_vlan:
|
||||
commands.append('switchport trunk native vlan {0}'.format(native_vlan))
|
||||
if trunk_allowed_vlans != obj_in_have['trunk_allowed_vlans'] and trunk_allowed_vlans:
|
||||
|
@ -307,7 +304,7 @@ def main():
|
|||
|
||||
want = map_params_to_obj(module)
|
||||
have = map_config_to_obj(module, warnings)
|
||||
commands = map_obj_to_commands((want, have), module)
|
||||
commands = map_obj_to_commands(want, have, module)
|
||||
result['commands'] = commands
|
||||
|
||||
if commands:
|
||||
|
|
|
@ -1,140 +1,108 @@
|
|||
---
|
||||
- debug: msg="START eos_l2_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
||||
- debug:
|
||||
msg: "START eos_l2_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: Delete test interface switchports
|
||||
eos_l2_interface:
|
||||
eos_l2_interface: &clear
|
||||
name: Ethernet1
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
|
||||
- name: Set switchport mode to access on vlan 4000
|
||||
eos_l2_interface:
|
||||
eos_l2_interface: &vlan-4000
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: access
|
||||
access_vlan: 4000
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- assert: &changed
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
|
||||
- name: Set switchport mode to access on vlan 4000 again (idempotent)
|
||||
eos_l2_interface:
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: access
|
||||
access_vlan: 4000
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
eos_l2_interface: *vlan-4000
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- assert: &unchanged
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: Change access vlan to 4001
|
||||
eos_l2_interface:
|
||||
eos_l2_interface: &vlan-4001
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: access
|
||||
access_vlan: 4001
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- assert: *changed
|
||||
|
||||
- name: Change access vlan to 4001 again (idempotent)
|
||||
eos_l2_interface:
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: access
|
||||
access_vlan: 4001
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
eos_l2_interface: *vlan-4001
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Change switchport mode to trunk
|
||||
eos_l2_interface: &trunk
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *changed
|
||||
|
||||
- name: Change switchport mode to trunk (idempotent)
|
||||
eos_l2_interface: *trunk
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Change switchport mode to trunk and set native vlan to 4001
|
||||
eos_l2_interface:
|
||||
eos_l2_interface: &trunk-native
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
native_vlan: 4001
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- assert: *changed
|
||||
|
||||
- name: Change switchport mode to trunk and set native vlan to 4001 again (idempotent)
|
||||
eos_l2_interface:
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
native_vlan: 4001
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
eos_l2_interface: *trunk-native
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Set trunk allowed vlans to 20 and 4000
|
||||
eos_l2_interface:
|
||||
eos_l2_interface: &trunk-allowed
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
trunk_allowed_vlans: 20,4000
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- assert: *changed
|
||||
|
||||
- name: Set trunk allowed vlans to 20 and 4000 again (idempotent)
|
||||
eos_l2_interface:
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
trunk_allowed_vlans: 20,4000
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
eos_l2_interface: *trunk-allowed
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Tear down switchports
|
||||
eos_l2_interface:
|
||||
name: Ethernet1
|
||||
state: absent
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
eos_l2_interface: *clear
|
||||
become: yes
|
||||
|
||||
- debug: msg="END eos_l3_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
||||
- debug: msg="END eos_l2_interface cli/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
|
108
test/integration/targets/eos_l2_interface/tests/eapi/basic.yaml
Normal file
108
test/integration/targets/eos_l2_interface/tests/eapi/basic.yaml
Normal file
|
@ -0,0 +1,108 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START eos_l2_interface eapi/basic.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: Delete test interface switchports
|
||||
eos_l2_interface: &clear
|
||||
name: Ethernet1
|
||||
state: absent
|
||||
become: yes
|
||||
|
||||
- name: Set switchport mode to access on vlan 4000
|
||||
eos_l2_interface: &vlan-4000
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: access
|
||||
access_vlan: 4000
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: &changed
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
|
||||
- name: Set switchport mode to access on vlan 4000 again (idempotent)
|
||||
eos_l2_interface: *vlan-4000
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: &unchanged
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
|
||||
- name: Change access vlan to 4001
|
||||
eos_l2_interface: &vlan-4001
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: access
|
||||
access_vlan: 4001
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *changed
|
||||
|
||||
- name: Change access vlan to 4001 again (idempotent)
|
||||
eos_l2_interface: *vlan-4001
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Change switchport mode to trunk
|
||||
eos_l2_interface: &trunk
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *changed
|
||||
|
||||
- name: Change switchport mode to trunk (idempotent)
|
||||
eos_l2_interface: *trunk
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Change switchport mode to trunk and set native vlan to 4001
|
||||
eos_l2_interface: &trunk-native
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
native_vlan: 4001
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *changed
|
||||
|
||||
- name: Change switchport mode to trunk and set native vlan to 4001 again (idempotent)
|
||||
eos_l2_interface: *trunk-native
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Set trunk allowed vlans to 20 and 4000
|
||||
eos_l2_interface: &trunk-allowed
|
||||
name: Ethernet1
|
||||
state: present
|
||||
mode: trunk
|
||||
trunk_allowed_vlans: 20,4000
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *changed
|
||||
|
||||
- name: Set trunk allowed vlans to 20 and 4000 again (idempotent)
|
||||
eos_l2_interface: *trunk-allowed
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert: *unchanged
|
||||
|
||||
- name: Tear down switchports
|
||||
eos_l2_interface: *clear
|
||||
become: yes
|
||||
|
||||
- debug: msg="END eos_l2_interface eapi/basic.yaml on connection={{ ansible_connection }}"
|
Loading…
Reference in a new issue