eos_l2_interface: Handle Interface does not exist (#56140)

* Fail on switchport error

* Handle `Interface does not exist` when gathering switchport.
This commit is contained in:
Nathaniel Case 2019-05-10 03:44:30 -04:00 committed by Nilashish Chakraborty
parent 776ec08ad5
commit 1097632039

View file

@ -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)
@ -214,7 +214,10 @@ def map_config_to_obj(module):
command = {'command': 'show interfaces {0} switchport | include Switchport'.format(item),
'output': 'text'}
command_result = run_commands(module, command)
if command_result[0] != "":
if command_result[0] == "% Interface does not exist":
warnings.append("Could not gather switchport information for {0}: {1}".format(item, command_result[0]))
continue
elif command_result[0] != "":
switchport_cfg = command_result[0].split(':')[1].strip()
if switchport_cfg == 'Enabled':
@ -302,7 +305,7 @@ def main():
result['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