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 testspull/4420/head
parent
5005c353ef
commit
cebb363fcc
|
@ -449,10 +449,10 @@ class HttpApi:
|
||||||
def run_queue(queue, output):
|
def run_queue(queue, output):
|
||||||
try:
|
try:
|
||||||
response = to_list(self._connection.send_request(queue, output=output))
|
response = to_list(self._connection.send_request(queue, output=output))
|
||||||
except Exception as exc:
|
except ConnectionError as exc:
|
||||||
if check_rc:
|
if check_rc:
|
||||||
raise
|
raise
|
||||||
return to_text(exc)
|
return to_list(to_text(exc))
|
||||||
|
|
||||||
if output == 'json':
|
if output == 'json':
|
||||||
response = [json.loads(item) for item in response]
|
response = [json.loads(item) for item in response]
|
||||||
|
|
|
@ -211,8 +211,8 @@ def map_config_to_obj(module, warnings):
|
||||||
for item in set(match):
|
for item in set(match):
|
||||||
command = {'command': 'show interfaces {0} switchport | include Switchport'.format(item),
|
command = {'command': 'show interfaces {0} switchport | include Switchport'.format(item),
|
||||||
'output': 'text'}
|
'output': 'text'}
|
||||||
command_result = run_commands(module, command)
|
command_result = run_commands(module, command, check_rc=False)
|
||||||
if command_result[0] == "% Interface does not exist":
|
if "Interface does not exist" in command_result[0]:
|
||||||
warnings.append("Could not gather switchport information for {0}: {1}".format(item, command_result[0]))
|
warnings.append("Could not gather switchport information for {0}: {1}".format(item, command_result[0]))
|
||||||
continue
|
continue
|
||||||
elif command_result[0] != "":
|
elif command_result[0] != "":
|
||||||
|
@ -298,9 +298,7 @@ def main():
|
||||||
supports_check_mode=True)
|
supports_check_mode=True)
|
||||||
|
|
||||||
warnings = list()
|
warnings = list()
|
||||||
result = {'changed': False}
|
result = {'changed': False, 'warnings': warnings}
|
||||||
if warnings:
|
|
||||||
result['warnings'] = warnings
|
|
||||||
|
|
||||||
want = map_params_to_obj(module)
|
want = map_params_to_obj(module)
|
||||||
have = map_config_to_obj(module, warnings)
|
have = map_config_to_obj(module, warnings)
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
---
|
||||||
|
- debug:
|
||||||
|
msg: "START eos_l3_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_l3_interface/cli/no_interface.yaml on connection={{ ansible_connection }}"
|
|
@ -0,0 +1,37 @@
|
||||||
|
---
|
||||||
|
- debug:
|
||||||
|
msg: "START eos_l3_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_l3_interface/eapi/no_interface.yaml on connection={{ ansible_connection }}"
|
Loading…
Reference in New Issue