[fix] Copy app remove script in a tmp file at restoration failure

This commit is contained in:
Jérôme Lebleu 2016-05-14 00:03:04 +02:00
parent 3cc8f52bc8
commit 420e5aed2c

View file

@ -501,7 +501,7 @@ def backup_restore(auth, name, hooks=[], ignore_hooks=False,
filesystem.chmod(app_setting_path, 0555, 0444, True)
filesystem.chmod(app_setting_path + '/settings.yml', 0400)
# Execute app restore script
# Copy restore script in a tmp file
subprocess.call(['install', '-Dm555', app_script, tmp_script])
# Prepare env. var. to pass to script
@ -511,11 +511,18 @@ def backup_restore(auth, name, hooks=[], ignore_hooks=False,
env_dict["YNH_APP_INSTANCE_NUMBER"] = str(app_instance_nb)
env_dict["YNH_APP_BACKUP_DIR"] = tmp_app_bkp_dir
# Execute app restore script
hook_exec(tmp_script, args=[tmp_app_bkp_dir, app_instance_name],
raise_on_error=True, chdir=tmp_app_bkp_dir, env=env_dict)
except:
logger.exception(m18n.n('restore_app_failed', app=app_instance_name))
# Copy remove script in a tmp file
filesystem.rm(tmp_script, force=True)
app_script = tmp_app_dir + '/settings/scripts/remove'
tmp_script = '/tmp/remove_' + app_instance_name
subprocess.call(['install', '-Dm555', app_script, tmp_script])
# Setup environment for remove script
env_dict_remove = {}
env_dict_remove["YNH_APP_ID"] = app_id
@ -523,10 +530,9 @@ def backup_restore(auth, name, hooks=[], ignore_hooks=False,
env_dict_remove["YNH_APP_INSTANCE_NUMBER"] = str(app_instance_nb)
# Execute remove script
remove_retcode = hook_exec(
os.path.join(tmp_app_dir, 'settings/scripts/remove'),
args=[app_instance_name], env=env_dict_remove)
if remove_retcode != 0:
# TODO: call app_remove instead
if hook_exec(tmp_script, args=[app_instance_name],
env=env_dict_remove) != 0:
logger.warning(m18n.n('app_not_properly_removed',
app=app_instance_name))