Beispiel #1
0
    def execute(self, image_id):
        """Finishing the task flow

        :param image_id: Glance Image ID
        """
        task = script_utils.get_task(self.task_repo, self.task_id)
        if task is None:
            return
        try:
            task.succeed({'image_id': image_id})
        except Exception as e:
            # Note: The message string contains Error in it to indicate
            # in the task.message that it's a error message for the user.

            # TODO(nikhil): need to bring back save_and_reraise_exception when
            # necessary
            err_msg = ("Error: " + six.text_type(type(e)) + ': ' +
                       encodeutils.exception_to_unicode(e))
            log_msg = err_msg + _LE("Task ID %s") % task.task_id
            LOG.exception(log_msg)

            task.fail(err_msg)
        finally:
            self.task_repo.save(task)

        LOG.info(_LI("%(task_id)s of %(task_type)s completed"), {
            'task_id': self.task_id,
            'task_type': self.task_type
        })
    def _finish_task(self, task):
        try:
            task.succeed({'image_id': self.action_wrapper.image_id})
        except Exception as e:
            # Note: The message string contains Error in it to indicate
            # in the task.message that it's a error message for the user.

            # TODO(nikhil): need to bring back save_and_reraise_exception when
            # necessary
            log_msg = _LE("Task ID %(task_id)s failed. Error: %(exc_type)s: "
                          "%(e)s")
            LOG.exception(
                log_msg, {
                    'exc_type': six.text_type(type(e)),
                    'e': encodeutils.exception_to_unicode(e),
                    'task_id': task.task_id
                })

            err_msg = _("Error: %(exc_type)s: %(e)s")
            task.fail(
                err_msg % {
                    'exc_type': six.text_type(type(e)),
                    'e': encodeutils.exception_to_unicode(e)
                })
        finally:
            self.task_repo.save(task)
Beispiel #3
0
    def execute(self, image_id):
        """Finishing the task flow

        :param image_id: Glance Image ID
        """
        task = script_utils.get_task(self.task_repo, self.task_id)
        if task is None:
            return
        try:
            task.succeed({'image_id': image_id})
        except Exception as e:
            # Note: The message string contains Error in it to indicate
            # in the task.message that it's a error message for the user.

            # TODO(nikhil): need to bring back save_and_reraise_exception when
            # necessary
            log_msg = _LE("Task ID %(task_id)s failed. Error: %(exc_type)s: "
                          "%(e)s")
            LOG.exception(log_msg, {'exc_type': six.text_type(type(e)),
                                    'e': encodeutils.exception_to_unicode(e),
                                    'task_id': task.task_id})

            err_msg = _("Error: %(exc_type)s: %(e)s")
            task.fail(err_msg % {'exc_type': six.text_type(type(e)),
                                 'e': encodeutils.exception_to_unicode(e)})
        finally:
            self.task_repo.save(task)

        LOG.info(_LI("%(task_id)s of %(task_type)s completed"),
                 {'task_id': self.task_id, 'task_type': self.task_type})
Beispiel #4
0
def assert_quota(context, task_repo, task_id, stores,
                 action_wrapper, enforce_quota_fn,
                 **enforce_kwargs):
    try:
        enforce_quota_fn(context, context.owner, **enforce_kwargs)
    except exception.LimitExceeded as e:
        with excutils.save_and_reraise_exception():
            with action_wrapper as action:
                action.remove_importing_stores(stores)
                if action.image_status == 'importing':
                    action.set_image_attribute(status='queued')
            action_wrapper.drop_lock_for_task()
            task = script_utils.get_task(task_repo, task_id)
            if task is None:
                LOG.error(_LE('Failed to find task %r to update after '
                              'quota failure'), task_id)
            else:
                task.fail(str(e))
                task_repo.save(task)