Esempio n. 1
0
 def execute(self, driver_factory):
     resource = self._resource
     driver = driver_factory.get(resource['type'])
     try:
         driver.stop(resource)
     except Exception:
         with excutils.save_and_reraise_exception() as exc_reraiser:
             LOG.exception(_('Failed to delete resource'))
             exc_reraiser.reraise = not self._force
     return resource
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 __iter__(self):
     """Return a result until we get a reply with an 'ending' flag."""
     if self._done:
         raise StopIteration
     while True:
         try:
             data = self._dataqueue.get(timeout=self._timeout)
             result = self._process_data(data)
         except queue.Empty:
             self.done()
             raise rpc_common.Timeout()
         except Exception:
             with excutils.save_and_reraise_exception():
                 self.done()
         if self._got_ending:
             self.done()
             raise StopIteration
         if isinstance(result, Exception):
             self.done()
             raise result
         yield result