mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix nxos_vlan mode idempotence bug (#55144)
* fix nxos_vlan mode idempotence bug Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Fix CI failure Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
7a957ba64a
commit
57e0567310
4 changed files with 26 additions and 11 deletions
|
@ -75,6 +75,7 @@ options:
|
||||||
- Set VLAN mode to classical ethernet or fabricpath.
|
- Set VLAN mode to classical ethernet or fabricpath.
|
||||||
This is a valid option for Nexus 5000 and 7000 series.
|
This is a valid option for Nexus 5000 and 7000 series.
|
||||||
choices: ['ce','fabricpath']
|
choices: ['ce','fabricpath']
|
||||||
|
default: 'ce'
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
aggregate:
|
aggregate:
|
||||||
description: List of VLANs definitions.
|
description: List of VLANs definitions.
|
||||||
|
@ -154,6 +155,7 @@ import time
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
|
from ansible.module_utils.network.nxos.nxos import get_capabilities
|
||||||
from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands
|
from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands
|
||||||
from ansible.module_utils.network.nxos.nxos import normalize_interface, nxos_argument_spec
|
from ansible.module_utils.network.nxos.nxos import normalize_interface, nxos_argument_spec
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
@ -196,6 +198,8 @@ def map_obj_to_commands(updates, module):
|
||||||
commands = list()
|
commands = list()
|
||||||
purge = module.params['purge']
|
purge = module.params['purge']
|
||||||
want, have = updates
|
want, have = updates
|
||||||
|
info = get_capabilities(module).get('device_info')
|
||||||
|
os_platform = info.get('network_os_platform')
|
||||||
|
|
||||||
for w in want:
|
for w in want:
|
||||||
vlan_id = w['vlan_id']
|
vlan_id = w['vlan_id']
|
||||||
|
@ -208,13 +212,15 @@ def map_obj_to_commands(updates, module):
|
||||||
state = w['state']
|
state = w['state']
|
||||||
del w['state']
|
del w['state']
|
||||||
|
|
||||||
obj_in_have = search_obj_in_list(vlan_id, have)
|
obj_in_have = search_obj_in_list(vlan_id, have) or {}
|
||||||
|
if not re.match('N[567]', os_platform) or (not obj_in_have.get('mode') and mode == 'ce'):
|
||||||
|
mode = w['mode'] = None
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
if obj_in_have:
|
if obj_in_have:
|
||||||
commands.append('no vlan {0}'.format(vlan_id))
|
commands.append('no vlan {0}'.format(vlan_id))
|
||||||
|
|
||||||
elif state == 'present':
|
elif state == 'present' and not purge:
|
||||||
if not obj_in_have:
|
if not obj_in_have:
|
||||||
commands.append('vlan {0}'.format(vlan_id))
|
commands.append('vlan {0}'.format(vlan_id))
|
||||||
|
|
||||||
|
@ -627,7 +633,7 @@ def main():
|
||||||
delay=dict(default=10, type='int'),
|
delay=dict(default=10, type='int'),
|
||||||
state=dict(choices=['present', 'absent'], default='present', required=False),
|
state=dict(choices=['present', 'absent'], default='present', required=False),
|
||||||
admin_state=dict(choices=['up', 'down'], required=False, default='up'),
|
admin_state=dict(choices=['up', 'down'], required=False, default='up'),
|
||||||
mode=dict(choices=['ce', 'fabricpath'], required=False),
|
mode=dict(default='ce', choices=['ce', 'fabricpath']),
|
||||||
)
|
)
|
||||||
|
|
||||||
aggregate_spec = deepcopy(element_spec)
|
aggregate_spec = deepcopy(element_spec)
|
||||||
|
|
|
@ -138,7 +138,7 @@ class HttpApi(HttpApiBase):
|
||||||
device_info['network_os_image'] = match_file_name.group(1)
|
device_info['network_os_image'] = match_file_name.group(1)
|
||||||
break
|
break
|
||||||
|
|
||||||
match_os_platform = re.search(r'NAME: "Chassis",\s*DESCR:.*\nPID:\s*(\S+)', platform_reply, re.M)
|
match_os_platform = re.search(r'NAME: (?:"Chassis"| Chassis ),\s*DESCR:.*\nPID:\s*(\S+)', platform_reply, re.M)
|
||||||
if match_os_platform:
|
if match_os_platform:
|
||||||
device_info['network_os_platform'] = match_os_platform.group(1)
|
device_info['network_os_platform'] = match_os_platform.group(1)
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,20 @@
|
||||||
when: platform is search('N5K|N7K')
|
when: platform is search('N5K|N7K')
|
||||||
|
|
||||||
- name: "Enable feature vn segment"
|
- name: "Enable feature vn segment"
|
||||||
nxos_config:
|
nxos_config:
|
||||||
commands:
|
commands:
|
||||||
- feature vn-segment-vlan-based
|
- feature vn-segment-vlan-based
|
||||||
match: none
|
match: none
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
when: platform is search('N9K')
|
when: platform is search('N9K')
|
||||||
|
|
||||||
|
- name: vlan teardown
|
||||||
|
nxos_vlan: &vlan_teardown
|
||||||
|
vlan_range: "2-200"
|
||||||
|
provider: "{{ connection }}"
|
||||||
|
state: absent
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: Ensure a range of VLANs are present on the switch
|
- name: Ensure a range of VLANs are present on the switch
|
||||||
nxos_vlan: &conf_vlan
|
nxos_vlan: &conf_vlan
|
||||||
vlan_range: "2-10,20,50,55-60,100-150"
|
vlan_range: "2-10,20,50,55-60,100-150"
|
||||||
|
@ -219,15 +226,12 @@
|
||||||
nxos_vlan: *remint
|
nxos_vlan: *remint
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: remove vlans
|
- name: vlan teardown final
|
||||||
nxos_vlan:
|
nxos_vlan: *vlan_teardown
|
||||||
vlan_range: "2-10,20,50,55-60,100-150"
|
|
||||||
provider: "{{ connection }}"
|
|
||||||
state: absent
|
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: "Disable feature vn segement"
|
- name: "Disable feature vn segement"
|
||||||
nxos_feature:
|
nxos_feature:
|
||||||
feature: vn-segment-vlan-based
|
feature: vn-segment-vlan-based
|
||||||
provider: "{{ connection }}"
|
provider: "{{ connection }}"
|
||||||
state: disabled
|
state: disabled
|
||||||
|
|
|
@ -42,11 +42,16 @@ class TestNxosVlanModule(TestNxosModule):
|
||||||
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_vlan.get_config')
|
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_vlan.get_config')
|
||||||
self.get_config = self.mock_get_config.start()
|
self.get_config = self.mock_get_config.start()
|
||||||
|
|
||||||
|
self.mock_get_capabilities = patch('ansible.modules.network.nxos.nxos_vlan.get_capabilities')
|
||||||
|
self.get_capabilities = self.mock_get_capabilities.start()
|
||||||
|
self.get_capabilities.return_value = {'device_info': {'network_os_platform': 'N9K-9000v'}, 'network_api': 'cliconf'}
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestNxosVlanModule, self).tearDown()
|
super(TestNxosVlanModule, self).tearDown()
|
||||||
self.mock_run_commands.stop()
|
self.mock_run_commands.stop()
|
||||||
self.mock_load_config.stop()
|
self.mock_load_config.stop()
|
||||||
self.mock_get_config.stop()
|
self.mock_get_config.stop()
|
||||||
|
self.mock_get_capabilities.stop()
|
||||||
|
|
||||||
def load_fixtures(self, commands=None, device=''):
|
def load_fixtures(self, commands=None, device=''):
|
||||||
def load_from_file(*args, **kwargs):
|
def load_from_file(*args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue