1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix eos_vrf and eos_vlan interfaces param idempotent issue (#34921)

Fixes # 34917

*  Remove spaces from in between interface name
*  Convert interface name to lower case as interface name
   is case insensitive wrt configuring on remote device.
This commit is contained in:
Ganesh Nalawade 2018-01-16 17:46:14 +05:30 committed by GitHub
parent 6fe0215c8f
commit c386ae9498
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 17 deletions

View file

@ -27,7 +27,8 @@ notes:
options: options:
name: name:
description: description:
- Name of the Interface to be configured on remote device. - Name of the Interface to be configured on remote device. The name of interface
should be in expanded format and not abbreviated.
required: true required: true
description: description:
description: description:

View file

@ -45,7 +45,8 @@ options:
required: true required: true
interfaces: interfaces:
description: description:
- List of interfaces that should be associated to the VLAN. - List of interfaces that should be associated to the VLAN. The name of interface
should be in expanded format and not abbreviated.
delay: delay:
description: description:
- Delay the play should wait to check for declarative intent params values. - Delay the play should wait to check for declarative intent params values.
@ -214,7 +215,7 @@ def map_config_to_obj(module):
if len(splitted_line) > 3: if len(splitted_line) > 3:
for i in splitted_line[3].split(','): for i in splitted_line[3].split(','):
obj['interfaces'].append(i.strip().replace('Et', 'Ethernet')) obj['interfaces'].append(i.strip().replace('Et', 'ethernet'))
objs.append(obj) objs.append(obj)
@ -230,6 +231,9 @@ def map_params_to_obj(module):
if item.get(key) is None: if item.get(key) is None:
item[key] = module.params[key] item[key] = module.params[key]
if item.get('interfaces'):
item['interfaces'] = [intf.replace(" ", "").lower() for intf in item.get('interfaces') if intf]
d = item.copy() d = item.copy()
d['vlan_id'] = str(d['vlan_id']) d['vlan_id'] = str(d['vlan_id'])
@ -239,7 +243,7 @@ def map_params_to_obj(module):
'vlan_id': str(module.params['vlan_id']), 'vlan_id': str(module.params['vlan_id']),
'name': module.params['name'], 'name': module.params['name'],
'state': module.params['state'], 'state': module.params['state'],
'interfaces': module.params['interfaces'] 'interfaces': [intf.replace(" ", "").lower() for intf in module.params['interfaces']] if module.params['interfaces'] else []
}) })
return obj return obj
@ -318,5 +322,6 @@ def main():
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -45,8 +45,10 @@ options:
- Route distinguisher of the VRF - Route distinguisher of the VRF
interfaces: interfaces:
description: description:
- List of interfaces to check the VRF has been - Identifies the set of interfaces that
configured correctly. should be configured in the VRF. Interfaces must be routed
interfaces in order to be placed into a VRF. The name of interface
should be in expanded format and not abbreviated.
aggregate: aggregate:
description: List of VRFs definitions description: List of VRFs definitions
purge: purge:
@ -195,13 +197,13 @@ def map_config_to_obj(module):
obj = {} obj = {}
obj['name'] = splitted_line[0] obj['name'] = splitted_line[0]
obj['rd'] = splitted_line[1] obj['rd'] = splitted_line[1]
obj['interfaces'] = None obj['interfaces'] = []
if len(splitted_line) > 4: if len(splitted_line) > 4:
obj['interfaces'] = [] obj['interfaces'] = []
for i in splitted_line[4].split(','): for i in splitted_line[4].split(','):
obj['interfaces'].append(i.strip()) obj['interfaces'].append(i.strip().lower())
objs.append(obj) objs.append(obj)
@ -216,13 +218,17 @@ def map_params_to_obj(module):
for key in item: for key in item:
if item.get(key) is None: if item.get(key) is None:
item[key] = module.params[key] item[key] = module.params[key]
if item.get('interfaces'):
item['interfaces'] = [intf.replace(" ", "").lower() for intf in item.get('interfaces') if intf]
obj.append(item.copy()) obj.append(item.copy())
else: else:
obj.append({ obj.append({
'name': module.params['name'], 'name': module.params['name'],
'state': module.params['state'], 'state': module.params['state'],
'rd': module.params['rd'], 'rd': module.params['rd'],
'interfaces': module.params['interfaces'] 'interfaces': [intf.replace(" ", "").lower() for intf in module.params['interfaces']] if module.params['interfaces'] else []
}) })
return obj return obj

View file

@ -134,9 +134,9 @@
that: that:
- "result.changed == true" - "result.changed == true"
- "'vlan 4000' in result.commands" - "'vlan 4000' in result.commands"
- "'interface Ethernet1' in result.commands" - "'interface ethernet1' in result.commands"
- "'switchport access vlan 4000' in result.commands" - "'switchport access vlan 4000' in result.commands"
- "'interface Ethernet2' in result.commands" - "'interface ethernet2' in result.commands"
- "'switchport access vlan 4000' in result.commands" - "'switchport access vlan 4000' in result.commands"
# Ensure sessions contains epoc. Will fail after 18th May 2033 # Ensure sessions contains epoc. Will fail after 18th May 2033
- "'ansible_1' in result.session_name" - "'ansible_1' in result.session_name"
@ -146,8 +146,8 @@
vlan_id: 4000 vlan_id: 4000
state: present state: present
interfaces: interfaces:
- Ethernet1 - ethernet 1 # interface name modified to test case insensitive and space scenario
- Ethernet2 - ethernet 2 # interface name modified to test case insensitive and space scenario
authorize: yes authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
@ -175,7 +175,7 @@
that: that:
- "result.changed == true" - "result.changed == true"
- "'vlan 4000' in result.commands" - "'vlan 4000' in result.commands"
- "'interface Ethernet2' in result.commands" - "'interface ethernet2' in result.commands"
- "'no switchport access vlan 4000' in result.commands" - "'no switchport access vlan 4000' in result.commands"
# Ensure sessions contains epoc. Will fail after 18th May 2033 # Ensure sessions contains epoc. Will fail after 18th May 2033
- "'ansible_1' in result.session_name" - "'ansible_1' in result.session_name"
@ -185,7 +185,7 @@
vlan_id: 4000 vlan_id: 4000
state: present state: present
interfaces: interfaces:
- Ethernet1 - ethernet 1 # interface name modified to handle case insensitive and space scenario
authorize: yes authorize: yes
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes

View file

@ -109,7 +109,7 @@
- assert: - assert:
that: that:
- "result.changed == true" - "result.changed == true"
- "'interface Ethernet2' in result.commands" - "'interface ethernet2' in result.commands"
- "'vrf forwarding test' in result.commands" - "'vrf forwarding test' in result.commands"
# Ensure sessions contains epoc. Will fail after 18th May 2033 # Ensure sessions contains epoc. Will fail after 18th May 2033
- "'ansible_1' in result.session_name" - "'ansible_1' in result.session_name"
@ -121,7 +121,7 @@
state: present state: present
authorize: yes authorize: yes
interfaces: interfaces:
- Ethernet2 - ethernet 2 # interface name modified to test case insensitive and space scenario
provider: "{{ cli }}" provider: "{{ cli }}"
become: yes become: yes
register: result register: result