示例#1
0
    def decorated_function(self, context, *args, **kwargs):
        try:
            return function(self, context, *args, **kwargs)
        except Exception as exp:
            with excutils.save_and_reraise_exception():
                wrapped_func = safe_utils.get_wrapped_function(function)
                keyed_args = inspect.getcallargs(wrapped_func, self, context,
                                                 *args, **kwargs)
                context = keyed_args['context']
                vnf_package = keyed_args['vnf_package']
                if not (isinstance(exp, exceptions.UploadFailedToGlanceStore)
                        or isinstance(exp, exceptions.VNFPackageURLInvalid)):
                    # Delete the csar file from the glance store.
                    glance_store.delete_csar(context, vnf_package.id,
                                             vnf_package.location_glance_store)

                    csar_utils.delete_csar_data(vnf_package.id)

                # Delete the vnf_deployment_flavour if created.
                if vnf_package.vnf_deployment_flavours:
                    for flavour in vnf_package.vnf_deployment_flavours:
                        flavour.destroy(context)

                # Set the vnf package onboarding status to created,
                # so that user can retry uploading vnf package
                # after correcting the csar zip file.
                vnf_package.onboarding_state = (
                    fields.PackageOnboardingStateType.CREATED)

                vnf_package.save()
示例#2
0
 def decorated_function(self, context, *args, **kwargs):
     try:
         return function(self, context, *args, **kwargs)
     except Exception:
         with excutils.save_and_reraise_exception():
             wrapped_func = safe_utils.get_wrapped_function(function)
             keyed_args = inspect.getcallargs(wrapped_func, self, context,
                                              *args, **kwargs)
             vnf_instance = keyed_args['vnf_instance']
             previous_task_state = vnf_instance.task_state
             try:
                 self._vnf_instance_update(
                     context,
                     vnf_instance,
                     task_state=fields.VnfInstanceTaskState.ERROR)
                 LOG.info(
                     "Successfully reverted task state from "
                     "%(state)s to %(error)s on failure for vnf "
                     "instance %(id)s.", {
                         "state": previous_task_state,
                         "id": vnf_instance.id,
                         "error": fields.VnfInstanceTaskState.ERROR
                     })
             except Exception as e:
                 LOG.warning(
                     "Failed to revert task state for vnf "
                     "instance %(id)s. Error: %(error)s", {
                         "id": vnf_instance.id,
                         "error": e
                     })
 def _decorator(f):
     base_f = safe_utils.get_wrapped_function(f)
     argspec = getargspec(base_f)
     if argspec[1] or argspec[2] or set(args) <= set(argspec[0]):
         # NOTE (nirajsingh): We can't really tell if correct stuff will
         # be passed if it's a function with *args or **kwargs so
         # we still carry on and hope for the best
         return dec(f)
     else:
         raise TypeError("Decorated function %(f_name)s does not "
                         "have the arguments expected by the "
                         "decorator %(d_name)s" %
                         {'f_name': base_f.__name__,
                          'd_name': dec.__name__})
示例#4
0
    def decorated_function(self, context, *args, **kwargs):
        try:
            return function(self, context, *args, **kwargs)
        except Exception as exp:
            with excutils.save_and_reraise_exception():
                wrapped_func = safe_utils.get_wrapped_function(function)
                keyed_args = inspect.getcallargs(wrapped_func, self, context,
                                                 *args, **kwargs)
                vnf_instance = keyed_args['vnf_instance']
                LOG.error("Failed to instantiate vnf %(id)s. Error: %(error)s",
                          {"id": vnf_instance.id,
                           "error": six.text_type(exp)})

                _rollback_vnf(self, context, vnf_instance)