Пример #1
0
    def call_plugin_serialized_with_retry(self, plugin, fn, num_retries,
                                          callback, *args, **kwargs):
        """Allows a plugin to raise RetryableError so we can try again."""
        attempts = num_retries + 1
        sleep_time = 0.5
        for attempt in xrange(1, attempts + 1):
            LOG.info(_('%(plugin)s.%(fn)s attempt %(attempt)d/%(attempts)d'),
                     {'plugin': plugin, 'fn': fn, 'attempt': attempt,
                      'attempts': attempts})
            try:
                if attempt > 1:
                    time.sleep(sleep_time)
                    sleep_time = min(2 * sleep_time, 15)

                if callback:
                    callback(kwargs)

                return self.call_plugin_serialized(plugin, fn, *args, **kwargs)
            except self.XenAPI.Failure as exc:
                if self._is_retryable_exception(exc):
                    LOG.warn(_('%(plugin)s.%(fn)s failed. Retrying call.')
                             % {'plugin': plugin, 'fn': fn})
                else:
                    raise

        raise exception.PluginRetriesExceeded(num_retries=num_retries)
Пример #2
0
    def call_plugin_serialized_with_retry(self,
                                          plugin,
                                          fn,
                                          num_retries,
                                          callback,
                                          retry_cb=None,
                                          *args,
                                          **kwargs):
        """Allows a plugin to raise RetryableError so we can try again."""
        attempts = num_retries + 1
        sleep_time = 0.5
        for attempt in range(1, attempts + 1):
            try:
                if attempt > 1:
                    time.sleep(sleep_time)
                    sleep_time = min(2 * sleep_time, 15)

                callback_result = None
                if callback:
                    callback_result = callback(kwargs)

                msg = ('%(plugin)s.%(fn)s attempt %(attempt)d/%(attempts)d, '
                       'callback_result: %(callback_result)s')
                LOG.debug(
                    msg, {
                        'plugin': plugin,
                        'fn': fn,
                        'attempt': attempt,
                        'attempts': attempts,
                        'callback_result': callback_result
                    })
                return self.call_plugin_serialized(plugin, fn, *args, **kwargs)
            except self.XenAPI.Failure as exc:
                if self._is_retryable_exception(exc, fn):
                    LOG.warning(
                        _LW('%(plugin)s.%(fn)s failed. '
                            'Retrying call.'), {
                                'plugin': plugin,
                                'fn': fn
                            })
                    if retry_cb:
                        retry_cb(exc=exc)
                else:
                    raise
            except socket.error as exc:
                if exc.errno == errno.ECONNRESET:
                    LOG.warning(
                        _LW('Lost connection to XenAPI during call to '
                            '%(plugin)s.%(fn)s.  Retrying call.'), {
                                'plugin': plugin,
                                'fn': fn
                            })
                    if retry_cb:
                        retry_cb(exc=exc)
                else:
                    raise

        raise exception.PluginRetriesExceeded(num_retries=num_retries)