Пример #1
0
    def _heal_vnf(self, context, vnf_instance, vim_connection_info,
                  heal_vnf_request):
        inst_vnf_info = vnf_instance.instantiated_vnf_info
        try:
            self._vnf_manager.invoke(vim_connection_info.vim_type,
                                     'heal_vnf',
                                     context=context,
                                     vnf_instance=vnf_instance,
                                     vim_connection_info=vim_connection_info,
                                     heal_vnf_request=heal_vnf_request)
        except Exception as exp:
            with excutils.save_and_reraise_exception() as exc_ctxt:
                exc_ctxt.reraise = False
                LOG.error(
                    "Failed to heal vnf %(id)s in infra driver. "
                    "Error: %(error)s", {
                        "id": vnf_instance.id,
                        "error": encodeutils.exception_to_unicode(exp)
                    })
                raise exceptions.VnfHealFailed(
                    id=vnf_instance.id,
                    error=encodeutils.exception_to_unicode(exp))

        try:
            self._vnf_manager.invoke(vim_connection_info.vim_type,
                                     'heal_vnf_wait',
                                     context=context,
                                     vnf_instance=vnf_instance,
                                     vim_connection_info=vim_connection_info)
        except Exception as exp:
            LOG.error(
                "Failed to update vnf %(id)s resources for instance "
                "%(instance)s. Error: %(error)s", {
                    'id': vnf_instance.id,
                    'instance': inst_vnf_info.instance_id,
                    'error': encodeutils.exception_to_unicode(exp)
                })

        try:
            self._vnf_manager.invoke(vim_connection_info.vim_type,
                                     'post_heal_vnf',
                                     context=context,
                                     vnf_instance=vnf_instance,
                                     vim_connection_info=vim_connection_info,
                                     heal_vnf_request=heal_vnf_request)
            self._vnf_instance_update(context, vnf_instance, task_state=None)
        except Exception as exp:
            with excutils.save_and_reraise_exception() as exc_ctxt:
                exc_ctxt.reraise = False
                LOG.error(
                    "Failed to store updated resources information for "
                    "instance %(instance)s for vnf %(id)s. "
                    "Error: %(error)s", {
                        'id': vnf_instance.id,
                        'instance': inst_vnf_info.instance_id,
                        'error': encodeutils.exception_to_unicode(exp)
                    })
                raise exceptions.VnfHealFailed(
                    id=vnf_instance.id,
                    error=encodeutils.exception_to_unicode(exp))
Пример #2
0
    def _respawn_vnf(self, context, vnf_instance, vim_connection_info,
                     heal_vnf_request):
        try:
            self._delete_vnf_instance_resources(
                context,
                vnf_instance,
                vim_connection_info,
                update_instantiated_state=False)
        except Exception as exc:
            with excutils.save_and_reraise_exception() as exc_ctxt:
                exc_ctxt.reraise = False
                err_msg = ("Failed to delete vnf resources for vnf instance "
                           "%(id)s before respawning. The vnf is in "
                           "inconsistent state. Error: %(error)s")
                LOG.error(err_msg % {
                    "id": vnf_instance.id,
                    "error": six.text_type(exc)
                })
                raise exceptions.VnfHealFailed(
                    id=vnf_instance.id,
                    error=encodeutils.exception_to_unicode(exc))

        # InstantiateVnfRequest is not stored in the db as it's mapped
        # to InstantiatedVnfInfo version object. Convert InstantiatedVnfInfo
        # version object to InstantiateVnfRequest so that vnf can be
        # instantiated.

        instantiate_vnf_request = objects.InstantiateVnfRequest.\
            from_vnf_instance(vnf_instance)

        try:
            self._instantiate_vnf(context, vnf_instance, vim_connection_info,
                                  instantiate_vnf_request)
        except Exception as exc:
            with excutils.save_and_reraise_exception() as exc_ctxt:
                exc_ctxt.reraise = False
                err_msg = ("Failed to instantiate vnf instance "
                           "%(id)s after termination. The vnf is in "
                           "inconsistent state. Error: %(error)s")
                LOG.error(err_msg % {
                    "id": vnf_instance.id,
                    "error": six.text_type(exc)
                })
                raise exceptions.VnfHealFailed(
                    id=vnf_instance.id,
                    error=encodeutils.exception_to_unicode(exc))

        self._vnf_instance_update(
            context,
            vnf_instance,
            instantiation_state=fields.VnfInstanceState.INSTANTIATED,
            task_state=None)
Пример #3
0
    def post_heal_vnf(self, context, vnf_instance, vim_connection_info,
                      heal_vnf_request):
        """Update resource_id for each vnfc resources

        :param context: A RequestContext
        :param vnf_instance: tacker.objects.VnfInstance to be healed
        :vim_info: Credentials to initialize Vim connection
        :heal_vnf_request: tacker.objects.HealVnfRequest object containing
                           parameters passed in the heal request
        """
        access_info = vim_connection_info.access_info
        region_name = access_info.get('region')

        heatclient = hc.HeatClient(access_info, region_name)
        inst_vnf_info = vnf_instance.instantiated_vnf_info
        stack_resources = self._get_stack_resources(inst_vnf_info.instance_id,
                                                    heatclient)

        vnfc_resources = self._get_vnfc_resources_from_heal_request(
            inst_vnf_info, heal_vnf_request)
        for vnfc_res_info in vnfc_resources:
            stack_id = vnfc_res_info.metadata.get("stack_id")
            resources = stack_resources.get(stack_id)
            if not resources:
                # NOTE(tpatil): This could happen when heat child stacks
                # and the stack_id stored in metadata of vnfc_res_info are
                # not in sync. There is no point in syncing inconsistent
                # resources information so exit with an error,
                error = "Failed to find stack_id %s" % stack_id
                raise exceptions.VnfHealFailed(id=vnf_instance.id, error=error)

            self._update_vnfc_resource_info(vnf_instance,
                                            vnfc_res_info,
                                            {stack_id: resources},
                                            update_network_resource=False)
Пример #4
0
        def _resource_mark_unhealthy():
            vnfc_resources = self._get_vnfc_resources_from_heal_request(
                inst_vnf_info, heal_vnf_request)

            vdu_resources = _get_vdu_resources(vnfc_resources)
            stack_resources = self._get_stack_resources(
                inst_vnf_info.instance_id, heatclient)

            cause = heal_vnf_request.cause or "Healing"
            for stack_uuid, resource_name in \
                    _prepare_stack_resources_for_updation(
                        vdu_resources, stack_resources):
                try:
                    LOG.info("Marking resource %(resource)s as unhealthy for "
                             "stack %(stack)s for vnf instance %(id)s",
                             {"resource": resource_name,
                              "stack": stack_uuid,
                              "id": vnf_instance.id})

                    heatclient.resource_mark_unhealthy(
                        stack_id=stack_uuid,
                        resource_name=resource_name, mark_unhealthy=True,
                        resource_status_reason=cause)
                except Exception as exp:
                    msg = ("Failed to mark stack '%(stack_id)s' resource as "
                           "unhealthy for resource '%(resource)s', "
                           "Error: %(error)s")
                    raise exceptions.VnfHealFailed(id=vnf_instance.id,
                        error=msg % {"stack_id": inst_vnf_info.instance_id,
                                     "resource": resource_name,
                                     "error": str(exp)})
Пример #5
0
 def _get_stack_status():
     stack_statuses = ["CREATE_COMPLETE", "UPDATE_COMPLETE"]
     stack = heatclient.get(inst_vnf_info.instance_id)
     if stack.stack_status not in stack_statuses:
         error = ("Healing of vnf instance %(id)s is possible only "
                  "when stack %(stack_id)s status is %(statuses)s, "
                  "current stack status is %(status)s")
         raise exceptions.VnfHealFailed(id=vnf_instance.id,
             error=error % {"id": vnf_instance.id,
             "stack_id": inst_vnf_info.instance_id,
             "statuses": ",".join(stack_statuses),
             "status": stack.stack_status})