Esempio n. 1
0
 def make_cleanup(self):
     self.deployment.update_status(consts.DeployStatus.CLEANUP_STARTED)
     try:
         self.cleanup()
     except Exception:
         with excutils.save_and_reraise_exception():
             self.deployment.update_status(
                 consts.DeployStatus.CLEANUP_FAILED)
     else:
         self.deployment.update_status(consts.DeployStatus.CLEANUP_FINISHED)
Esempio n. 2
0
def remove_path_on_error(path):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.

    :param path: File to work with
    """
    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            delete_if_exists(path)
Esempio n. 3
0
 def make_deploy(self):
     self.deployment.update_status(consts.DeployStatus.DEPLOY_STARTED)
     try:
         endpoint = self.deploy()
     except Exception:
         with excutils.save_and_reraise_exception():
             self.deployment.update_status(
                 consts.DeployStatus.DEPLOY_FAILED)
     else:
         self.deployment.update_status(consts.DeployStatus.DEPLOY_FINISHED)
         return endpoint
Esempio n. 4
0
def remove_path_on_error(path, remove=delete_if_exists):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.

    :param path: File to work with
    :param remove: Optional function to remove passed path
    """

    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            remove(path)