diff --git a/src/execo_g5k/kadeploy.py b/src/execo_g5k/kadeploy.py index 32beb4999f6e6216ca71dfbe2107734c43743a8d..43c2994d3549b14be4084d5cecbc6a09fa5b5f32 100644 --- a/src/execo_g5k/kadeploy.py +++ b/src/execo_g5k/kadeploy.py @@ -507,18 +507,34 @@ def deploy(deployment, class KaconsoleProcessLifecycleHandler(ProcessLifecycleHandler): def start(self, p): - p.expect('Connection to console .* opened', - timeout=max(0, p.start_date + p.console_connection_timeout - time.time()) if p.console_connection_timeout else None, - expect_output_handler=p.console_connection_expect_output_handler) + timeout = max(0, p.start_date + p.console_connection_timeout - time.time()) if p.console_connection_timeout else None + logger.debug("waiting console connection to %s, timeout=%s" % (p.kaconsole_host.address, timeout)) + expect_result = p.expect('Connection to console .* opened', + timeout=timeout) + if expect_result == (None, None): + logger.info("wait for console connection to %s failed with timeout=%s" % (p.kaconsole_host.address, timeout)) + return + logger.debug("sending login disconnect sequence to console on %s" % (p.kaconsole_host.address, )) p.write("\x04\n\x04\n") # to make sure we disconnect if a console was previously opened, and to get the login prompt - p.expect('login: ', - timeout=max(0, p.start_date + p.console_connection_timeout - time.time()) if p.console_connection_timeout else None, - expect_output_handler=p.console_connection_expect_output_handler) + timeout = max(0, p.start_date + p.console_connection_timeout - time.time()) if p.console_connection_timeout else None + logger.debug("waiting login prompt on %s, timeout=%s" % (p.kaconsole_host.address, timeout)) + expect_result = p.expect('login: ', + timeout=timeout) + if expect_result == (None, None): + logger.info("wait login prompt on %s failed with timeout=%s" % (p.kaconsole_host.address, timeout)) + return + logger.debug("sending login %s to console on %s" % (p.console_connection_params['user'], p.kaconsole_host.address)) p.write(p.console_connection_params['user'] + "\n") - p.expect('Password: ', - timeout=max(0, p.start_date + p.console_connection_timeout - time.time()) if p.console_connection_timeout else None, - expect_output_handler=p.console_connection_expect_output_handler) + timeout = max(0, p.start_date + p.console_connection_timeout - time.time()) if p.console_connection_timeout else None + logger.debug("waiting password prompt on %s, timeout=%s" % (p.kaconsole_host.address, timeout)) + expect_result = p.expect('Password: ', + timeout=timeout) + if expect_result == (None, None): + logger.info("wait password prompt on %s failed with timeout=%s" % (p.kaconsole_host.address, timeout)) + return + logger.debug("sending password to console on %s" % (p.kaconsole_host.address, )) p.write(p.console_connection_params['password'] + "\n") + logger.debug("connected to console on %s" %(p.kaconsole_host.address,)) p.console_connected.set() class KaconsoleProcess(SshProcess): @@ -532,18 +548,18 @@ class KaconsoleProcess(SshProcess): """ def __init__(self, host, frontend_connection_params=None, connection_timeout=20, prompt='root@[^#]*#', **kwargs): - host = Host(host) + self.kaconsole_host = Host(host) self.console_connection_timeout = connection_timeout self.console_connection_params = make_connection_params(kwargs.get("connection_params"), {'user': 'root', 'password': 'grid5000'}) if 'connection_params' in kwargs: del kwargs['connection_params'] - super().__init__("kaconsole3 " + host.address, - host = get_frontend_host(_get_host_frontend(host)), + super().__init__("kaconsole3 " + self.kaconsole_host.address, + host = get_frontend_host(_get_host_frontend(self.kaconsole_host)), connection_params = make_connection_params(frontend_connection_params, default_frontend_connection_params), **kwargs) self.pty = True self.prompt = prompt self.console_connected = threading.Event() - self.console_connection_expect_output_handler = ExpectOutputHandler() + #self.console_connection_expect_output_handler = ExpectOutputHandler() self.lifecycle_handlers.append(KaconsoleProcessLifecycleHandler()) def wait_connected(self, timeout=None): @@ -558,8 +574,8 @@ class KaconsoleProcess(SshProcess): if not self.wait_connected(timeout=timeout): return None, None return self.expect(self.prompt, - timeout=max(0, wait_start + timeout - time.time()) if timeout else None, - expect_output_handler=self.console_connection_expect_output_handler) + timeout=max(0, wait_start + timeout - time.time()) if timeout else None) + #expect_output_handler=self.console_connection_expect_output_handler) def close(self): self.write('&.')