reboot - Fix connection timeout reset (#51000)

* only reset if we could retrieve the conn timeout

(cherry picked from commit 9fa46e7f94)
This commit is contained in:
Jordan Borean 2019-01-18 01:45:41 +10:00 committed by Toshio Kuratomi
parent 4a89749dd5
commit 970669b70e
2 changed files with 19 additions and 11 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- reboot - Fix bug where the connection timeout was not reset in the same task after rebooting

View file

@ -302,7 +302,6 @@ class ActionModule(ActionBase):
try:
# keep on checking system boot_time with short connection responses
reboot_timeout = int(self._task.args.get('reboot_timeout', self._task.args.get('reboot_timeout_sec', self.DEFAULT_REBOOT_TIMEOUT)))
connect_timeout = self._task.args.get('connect_timeout', self._task.args.get('connect_timeout_sec', self.DEFAULT_CONNECT_TIMEOUT))
self.do_until_success_or_timeout(
action=self.check_boot_time,
@ -311,16 +310,23 @@ class ActionModule(ActionBase):
distribution=distribution,
action_kwargs=action_kwargs)
if connect_timeout and original_connection_timeout:
try:
display.debug("{action}: setting connect_timeout back to original value of {value}".format(
action=self._task.action,
value=original_connection_timeout))
self._connection.set_option("connection_timeout", original_connection_timeout)
self._connection.reset()
except (AnsibleError, AttributeError) as e:
# reset the connection to clear the custom connection timeout
display.debug("{action}: failed to reset connection_timeout back to default: {error}".format(action=self._task.action, error=to_text(e)))
# Get the connect_timeout set on the connection to compare to the original
try:
connect_timeout = self._connection.get_option('connection_timeout')
except AnsibleError:
pass
else:
if original_connection_timeout != connect_timeout:
try:
display.debug("{action}: setting connect_timeout back to original value of {value}".format(
action=self._task.action,
value=original_connection_timeout))
self._connection.set_option("connection_timeout", original_connection_timeout)
self._connection.reset()
except (AnsibleError, AttributeError) as e:
# reset the connection to clear the custom connection timeout
display.debug("{action}: failed to reset connection_timeout back to default: {error}".format(action=self._task.action,
error=to_text(e)))
# finally run test command to ensure everything is working
# FUTURE: add a stability check (system must remain up for N seconds) to deal with self-multi-reboot updates