Commit 8647a52c authored by Iustin Pop's avatar Iustin Pop

setup-ssh: fix the logging error message

This took a bit of interesting debugging, but the issue seems to be that
on older python/logging/paramiko (I'm not sure which is at fault here),
the other threads are finishing later than the main thread, so the
logging module closes the logging file (but doesn't unregister it)
before the paramiko thread(s) get a change to finish their logging.

Tested on both old versions (Dapper) and new versions (Lucid) of these
three pieces of the puzzle.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent a4978169
......@@ -201,12 +201,13 @@ def SetupLogging(options):
else:
stderr_handler.setLevel(logging.ERROR)
# This is the paramiko logger instance
paramiko_logger = logging.getLogger("paramiko")
root_logger = logging.getLogger("")
root_logger.setLevel(logging.NOTSET)
root_logger.addHandler(stderr_handler)
root_logger.addHandler(file_handler)
# This is the paramiko logger instance
paramiko_logger = logging.getLogger("paramiko")
paramiko_logger.addHandler(file_handler)
......@@ -220,18 +221,39 @@ def main():
passwd = getpass.getpass(prompt="%s password:" % constants.GANETI_RUNAS)
# Below, we need to join() the transport objects, as otherwise the
# following happens:
# - the main thread finishes
# - the atexit functions run (in the main thread), and cause the
# logging file to be closed
# - a tiny bit later, the transport thread is finally ending, and
# wants to log one more message, which fails as the file is closed
# now
for host in args:
transport = paramiko.Transport((host, netutils.GetDaemonPort("ssh")))
transport.connect(username=constants.GANETI_RUNAS, password=passwd)
try:
transport.connect(username=constants.GANETI_RUNAS, password=passwd)
except Exception, err:
logging.error("Connection or authentication failed to host %s: %s",
host, err)
transport.close()
# this is needed for compatibility with older Paramiko or Python
# versions
transport.join()
continue
try:
try:
SetupSSH(transport)
SetupNodeDaemon(transport)
except errors.GenericError, err:
logging.fatal("While doing setup on host %s an error occured: %s", host,
err)
logging.error("While doing setup on host %s an error occured: %s",
host, err)
finally:
transport.close()
# this is needed for compatibility with older Paramiko or Python
# versions
transport.join()
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment