Don't always delete temporary directories

In debug mode it is useful to have temporary directory available on each host.
This patch implements skipping the cleanup during debug.

Change-Id: I6e95366c0e421e48b0f7ac19f44a25d5159c31f6
This commit is contained in:
Martin Mágr
2015-01-06 12:26:04 +01:00
parent 38bcdb2491
commit 3f74acf7b1

View File

@@ -627,17 +627,24 @@ def _main(options, configFile=None, logFile=None):
print output_messages.INFO_INSTALL_SUCCESS print output_messages.INFO_INSTALL_SUCCESS
def remove_remote_var_dirs(): def remove_remote_var_dirs(options, config, messages):
""" """
Removes the temp directories on remote hosts, Removes the temp directories on remote hosts,
doesn't remove data on localhost doesn't remove data on localhost
""" """
for host in gethostlist(controller.CONF): for host in gethostlist(config):
try: try:
host_dir = controller.CONF['HOST_DETAILS'][host]['tmpdir'] host_dir = config['HOST_DETAILS'][host]['tmpdir']
except KeyError: except KeyError:
# Nothing was added to this host yet, so we have nothing to delete # Nothing was added to this host yet, so we have nothing to delete
continue continue
if options.debug:
# we keep temporary directories on hosts in debug mode
messages.append(
'Note temporary directory {host_dir} on host {host} was '
'not deleted for debugging purposes.'.format(**locals())
)
continue
logging.debug(output_messages.INFO_REMOVE_REMOTE_VAR % (host_dir, host)) logging.debug(output_messages.INFO_REMOVE_REMOTE_VAR % (host_dir, host))
server = utils.ScriptRunner(host) server = utils.ScriptRunner(host)
server.append('rm -rf %s' % host_dir) server.append('rm -rf %s' % host_dir)
@@ -647,7 +654,7 @@ def remove_remote_var_dirs():
msg = output_messages.ERR_REMOVE_REMOTE_VAR % (host_dir, host) msg = output_messages.ERR_REMOVE_REMOTE_VAR % (host_dir, host)
logging.error(msg) logging.error(msg)
logging.exception(e) logging.exception(e)
controller.MESSAGES.append(utils.color_text(msg, 'red')) messages.append(utils.color_text(msg, 'red'))
def remove_temp_files(): def remove_temp_files():
""" """
@@ -971,7 +978,7 @@ def main():
sys.exit(1) sys.exit(1)
finally: finally:
remove_remote_var_dirs() remove_remote_var_dirs(options, controller.CONF, controller.MESSAGES)
remove_temp_files() remove_temp_files()
# Always print user params to log # Always print user params to log