* [stable-2.8] eos_l2_interface handle "Interface does not exist" (#56787)
* Quick and dirty attempt to handle eapi error
* Well this should probably change
* Hopefully this works correctly?
* Fix check_rc handling with httpapi
* Add tests that should hopefully cover the error
* Fix warnings
* Improve tests.
(cherry picked from commit cebb363fcc
)
Co-authored-by: Nathaniel Case <ncase@redhat.com>
* Add changelog
* Remove backport overreach
* Fix debug statements in new tests while I'm here
This commit is contained in:
parent
0a3410f5c6
commit
5a1985cb06
5 changed files with 86 additions and 8 deletions
2
changelogs/fragments/56787-interface-not-found.yaml
Normal file
2
changelogs/fragments/56787-interface-not-found.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- Fix "Interface not found" errors when using eos_l2_interface with nonexistant interfaces configured
|
|
@ -449,10 +449,10 @@ class HttpApi:
|
|||
def run_queue(queue, output):
|
||||
try:
|
||||
response = to_list(self._connection.send_request(queue, output=output))
|
||||
except Exception as exc:
|
||||
except ConnectionError as exc:
|
||||
if check_rc:
|
||||
raise
|
||||
return to_text(exc)
|
||||
return to_list(to_text(exc))
|
||||
|
||||
if output == 'json':
|
||||
response = [json.loads(item) for item in response]
|
||||
|
|
|
@ -200,7 +200,7 @@ def map_obj_to_commands(updates, module):
|
|||
return commands
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
def map_config_to_obj(module, warnings):
|
||||
config = get_config(module, flags=['| section interface'])
|
||||
configobj = NetworkConfig(indent=3, contents=config)
|
||||
|
||||
|
@ -213,7 +213,12 @@ def map_config_to_obj(module):
|
|||
for item in set(match):
|
||||
command = {'command': 'show interfaces {0} switchport | include Switchport'.format(item),
|
||||
'output': 'text'}
|
||||
switchport_cfg = run_commands(module, command)[0].split(':')[1].strip()
|
||||
command_result = run_commands(module, command, check_rc=False)
|
||||
if "Interface does not exist" in command_result[0]:
|
||||
warnings.append("Could not gather switchport information for {0}: {1}".format(item, command_result[0]))
|
||||
continue
|
||||
|
||||
switchport_cfg = command_result[0].split(':')[1].strip()
|
||||
if switchport_cfg == 'Enabled':
|
||||
state = 'present'
|
||||
else:
|
||||
|
@ -294,12 +299,10 @@ def main():
|
|||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
result = {'changed': False}
|
||||
if warnings:
|
||||
result['warnings'] = warnings
|
||||
result = {'changed': False, 'warnings': warnings}
|
||||
|
||||
want = map_params_to_obj(module)
|
||||
have = map_config_to_obj(module)
|
||||
have = map_config_to_obj(module, warnings)
|
||||
commands = map_obj_to_commands((want, have), module)
|
||||
result['commands'] = commands
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START eos_l2_interface/cli/no_interface.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: Create fake interface
|
||||
eos_interface:
|
||||
name: Management0
|
||||
become: yes
|
||||
|
||||
- block:
|
||||
- name: eos_l2_interface shouldn't fail
|
||||
eos_l2_interface: &no_switchport
|
||||
name: Ethernet1
|
||||
state: absent
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that: "'Interface does not exist' in result.warnings[0]"
|
||||
|
||||
always:
|
||||
- name: Cleanup fake interface
|
||||
cli_config:
|
||||
config: no interface Management0
|
||||
become: yes
|
||||
|
||||
- name: eos_l2_interface should still not fail
|
||||
eos_l2_interface: *no_switchport
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that: "result.warnings is not defined"
|
||||
|
||||
- debug:
|
||||
msg: "END eos_l2_interface/cli/no_interface.yaml on connection={{ ansible_connection }}"
|
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START eos_l2_interface/eapi/no_interface.yaml on connection={{ ansible_connection }}"
|
||||
|
||||
- name: Create fake interface
|
||||
eos_interface:
|
||||
name: Management0
|
||||
become: yes
|
||||
|
||||
- block:
|
||||
- name: eos_l2_interface shouldn't fail
|
||||
eos_l2_interface: &no_switchport
|
||||
name: Ethernet1
|
||||
state: absent
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that: "'Interface does not exist' in result.warnings[0]"
|
||||
|
||||
always:
|
||||
- name: Cleanup fake interface
|
||||
eos_config:
|
||||
lines:
|
||||
- no interface Management0
|
||||
become: yes
|
||||
|
||||
- name: eos_l2_interface should still not fail
|
||||
eos_l2_interface: *no_switchport
|
||||
become: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that: "result.warnings is not defined"
|
||||
|
||||
- debug:
|
||||
msg: "END eos_l2_interface/eapi/no_interface.yaml on connection={{ ansible_connection }}"
|
Loading…
Reference in a new issue