Rather than giving up and throwing a hard to understand exception to users when the install server code can't reach the install server, retry every install_timeout / 100 seconds.
If after install_timeout / 10 we still could not reach the server, then throw an easier to understand error (Could not contact the install server). CC: Rudá Moura <[email protected]> Signed-off-by: Lucas Meneghel Rodrigues <[email protected]> --- server/hosts/remote.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/server/hosts/remote.py b/server/hosts/remote.py index 0a5f594..83b6ee6 100644 --- a/server/hosts/remote.py +++ b/server/hosts/remote.py @@ -4,12 +4,18 @@ if it is available.""" import os import logging import urllib +import socket +import time from autotest.client.shared import error from autotest.client.shared.settings import settings from autotest.server import utils from autotest.server.hosts import base_classes, install_server +class InstallServerUnavailable(Exception): + pass + + def get_install_server_info(): server_info = {} settings.parse_config_file() @@ -91,7 +97,23 @@ class RemoteHost(base_classes.Host): return num_attempts = int(server_info.get('num_attempts', 2)) ServerInterface = self.INSTALL_SERVER_MAPPING[server_info['type']] - server_interface = ServerInterface(**server_info) + end_time = time.time() + (timeout / 10) + step = int(timeout / 100) + server_interface = None + while time.time() < end_time: + try: + server_interface = ServerInterface(**server_info) + break + except socket.error: + logging.error('Install server unavailable. Trying ' + 'again in %s s...', step) + time.sleep(step) + + if server_interface is None: + raise InstallServerUnavailable("Install server unavailable. " + "Tried to communicate for " + "%s s" % (timeout/10)) + server_interface.install_host(self, profile=profile, timeout=timeout, num_attempts=num_attempts) @@ -279,7 +301,7 @@ class RemoteHost(base_classes.Host): if reboot_cmd: self.run(reboot_cmd) else: - # Try several methods of rebooting in increasing harshness. + # Try several methods of rebooting in increasing harshness. self.run('((' ' sync &' ' sleep 5; reboot &' -- 1.8.3.1 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
