fixes issue where config sessions where left behind (#17673)

When using the Cli transport, if the session hung on a command and the
socket timed out, the config session would be left behind.  This change
will allow the shell to try to get control back and remove the config
session, assuming the channel is still open.

fixes ansible/ansible-modules-core#4945
This commit is contained in:
Peter Sprygada 2016-09-20 16:30:09 -04:00 committed by GitHub
parent f0c9cc909b
commit 765a76885b

View file

@ -29,7 +29,7 @@
import re import re
import time import time
from ansible.module_utils.basic import json from ansible.module_utils.basic import json, get_exception
from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule
from ansible.module_utils.network import add_argument, register_transport, to_list from ansible.module_utils.network import add_argument, register_transport, to_list
from ansible.module_utils.netcli import Command from ansible.module_utils.netcli import Command
@ -81,6 +81,11 @@ class EosConfigMixin(object):
else: else:
self.execute(['no configure session %s' % session]) self.execute(['no configure session %s' % session])
except NetworkError: except NetworkError:
exc = get_exception()
if 'timeout trying to send command' in exc.message:
# try to get control back and get out of config mode
if isinstance(self, Cli):
self.execute(['\x03', 'end'])
self.abort_config(session) self.abort_config(session)
diff = None diff = None
raise raise