def scale_wait(self, context, plugin, auth_attr, policy, region_name,
                   last_event_id):
        """Scale wait function

        Scale wait function will marked VNF is ACTIVE when all status state
        from Pod objects is RUNNING.
        """
        # initialize Kubernetes APIs
        auth_cred, file_descriptor = self._get_auth_creds(auth_attr)
        try:
            core_v1_api_client = self.kubernetes.get_core_v1_api_client(
                auth=auth_cred)
            deployment_info = policy['instance_id'].split(",")

            pods_information = self._get_pods_information(
                core_v1_api_client=core_v1_api_client,
                deployment_info=deployment_info)
            status = self._get_pod_status(pods_information)

            stack_retries = self.STACK_RETRIES
            error_reason = None
            while status == 'Pending' and stack_retries > 0:
                time.sleep(self.STACK_RETRY_WAIT)

                pods_information = self._get_pods_information(
                    core_v1_api_client=core_v1_api_client,
                    deployment_info=deployment_info)
                status = self._get_pod_status(pods_information)

                # LOG.debug('status: %s', status)
                stack_retries = stack_retries - 1

            LOG.debug('VNF initializing status: %(service_name)s %(status)s', {
                'service_name': str(deployment_info),
                'status': status
            })

            if stack_retries == 0 and status != 'Running':
                error_reason = _("Resource creation is not completed within"
                                 " {wait} seconds as creation of stack {stack}"
                                 " is not completed").format(
                                     wait=(self.STACK_RETRIES *
                                           self.STACK_RETRY_WAIT),
                                     stack=policy['instance_id'])
                LOG.error("VNF Creation failed: %(reason)s",
                          {'reason': error_reason})
                raise vnfm.VNFCreateWaitFailed(reason=error_reason)

            elif stack_retries != 0 and status != 'Running':
                raise vnfm.VNFCreateWaitFailed(reason=error_reason)
        except Exception as e:
            LOG.error('Scaling wait VNF got an error due to %s', e)
            raise
        finally:
            self.clean_authenticate_vim(auth_cred, file_descriptor)
Exemple #2
0
 def test_create_vnf_create_wait_failed_exception(self):
     self._insert_dummy_vnf_template()
     vnf_obj = utils.get_dummy_vnf_obj()
     self.create_wait.side_effect = vnfm.VNFCreateWaitFailed(
         reason="failed")
     vnf_dict = self.vnfm_plugin.create_vnf(self.context, vnf_obj)
     self.assertEqual(constants.ERROR, vnf_dict['status'])
Exemple #3
0
    def delete_wait(self,
                    plugin,
                    context,
                    vnf_id,
                    auth_attr,
                    region_name=None):
        heatclient_ = HeatClient(auth_attr, region_name)

        stack = heatclient_.get(vnf_id)
        status = stack.stack_status
        error_reason = None
        stack_retries = self.STACK_RETRIES
        while (status == 'DELETE_IN_PROGRESS' and stack_retries > 0):
            time.sleep(self.STACK_RETRY_WAIT)
            try:
                stack = heatclient_.get(vnf_id)
            except heatException.HTTPNotFound:
                return
            except Exception:
                LOG.exception(
                    _("VNF Instance cleanup may not have "
                      "happened because Heat API request failed "
                      "while waiting for the stack %(stack)s to be "
                      "deleted"), {'stack': vnf_id})
                break
            status = stack.stack_status
            stack_retries = stack_retries - 1

        if stack_retries == 0 and status != 'DELETE_COMPLETE':
            error_reason = _("Resource cleanup for vnf is"
                             " not completed within {wait} seconds as "
                             "deletion of Stack {stack} is "
                             "not completed").format(
                                 stack=vnf_id,
                                 wait=(self.STACK_RETRIES *
                                       self.STACK_RETRY_WAIT))
            LOG.warning(error_reason)
            raise vnfm.VNFCreateWaitFailed(vnf_id=vnf_id, reason=error_reason)

        if stack_retries != 0 and status != 'DELETE_COMPLETE':
            error_reason = _("vnf {vnf_id} deletion is not completed. "
                             "{stack_status}").format(vnf_id=vnf_id,
                                                      stack_status=status)
            LOG.warning(error_reason)
            raise vnfm.VNFCreateWaitFailed(vnf_id=vnf_id, eason=error_reason)
    def create_wait(self, plugin, context, vnf_dict, vnf_id, auth_attr):
        region_name = vnf_dict.get('placement_attr',
                                   {}).get('region_name', None)
        heatclient = hc.HeatClient(auth_attr, region_name)

        stack, status, stack_retries = self._wait_until_stack_ready(
            vnf_id,
            auth_attr,
            infra_cnst.STACK_CREATE_IN_PROGRESS,
            region_name=region_name)

        if stack_retries == 0 and status != infra_cnst.STACK_CREATE_COMPLETE:
            error_reason = _("Resource creation is not completed within"
                             " {wait} seconds as creation of stack {stack}"
                             " is not completed").format(
                                 wait=(self.STACK_RETRIES *
                                       self.STACK_RETRY_WAIT),
                                 stack=vnf_id)
            LOG.warning("VNF Creation failed: %(reason)s",
                        {'reason': error_reason})
            raise vnfm.VNFCreateWaitFailed(reason=error_reason)

        elif stack_retries != 0 and status != infra_cnst.STACK_CREATE_COMPLETE:
            error_reason = stack.stack_status_reason
            raise vnfm.VNFCreateWaitFailed(reason=error_reason)

        # scaling enabled
        if vnf_dict['attributes'].get('scaling_group_names'):
            group_names = jsonutils.loads(
                vnf_dict['attributes'].get('scaling_group_names')).values()
            mgmt_ips = self._find_mgmt_ips_from_groups(heatclient, vnf_id,
                                                       group_names)
        else:
            mgmt_ips = self._find_mgmt_ips(stack.outputs)

        if mgmt_ips:
            vnf_dict['mgmt_ip_address'] = jsonutils.dump_as_bytes(mgmt_ips)
Exemple #5
0
    def create_wait(self, plugin, context, vnf_dict, vnf_id, auth_attr):
        region_name = vnf_dict.get('placement_attr',
                                   {}).get('region_name', None)
        heatclient = hc.HeatClient(auth_attr, region_name)

        stack = heatclient.get(vnf_id)
        status = stack.stack_status
        stack_retries = self.STACK_RETRIES
        error_reason = None
        while status == 'CREATE_IN_PROGRESS' and stack_retries > 0:
            time.sleep(self.STACK_RETRY_WAIT)
            try:
                stack = heatclient.get(vnf_id)
            except Exception:
                LOG.warning(
                    "VNF Instance setup may not have "
                    "happened because Heat API request failed "
                    "while waiting for the stack %(stack)s to be "
                    "created", {'stack': vnf_id})
                # continue to avoid temporary connection error to target
                # VIM
            status = stack.stack_status
            LOG.debug('status: %s', status)
            stack_retries = stack_retries - 1

        LOG.debug('stack status: %(stack)s %(status)s', {
            'stack': str(stack),
            'status': status
        })
        if stack_retries == 0 and status != 'CREATE_COMPLETE':
            error_reason = _("Resource creation is not completed within"
                             " {wait} seconds as creation of stack {stack}"
                             " is not completed").format(
                                 wait=(self.STACK_RETRIES *
                                       self.STACK_RETRY_WAIT),
                                 stack=vnf_id)
            LOG.warning("VNF Creation failed: %(reason)s",
                        {'reason': error_reason})
            raise vnfm.VNFCreateWaitFailed(reason=error_reason)

        elif stack_retries != 0 and status != 'CREATE_COMPLETE':
            error_reason = stack.stack_status_reason
            raise vnfm.VNFCreateWaitFailed(reason=error_reason)

        def _find_mgmt_ips(outputs):
            LOG.debug('outputs %s', outputs)
            mgmt_ips = dict(
                (output['output_key'][len(OUTPUT_PREFIX):],
                 output['output_value']) for output in outputs
                if output.get('output_key', '').startswith(OUTPUT_PREFIX))
            return mgmt_ips

        # scaling enabled
        if vnf_dict['attributes'].get('scaling_group_names'):
            group_names = jsonutils.loads(
                vnf_dict['attributes'].get('scaling_group_names')).values()
            mgmt_ips = self._find_mgmt_ips_from_groups(heatclient, vnf_id,
                                                       group_names)
        else:
            mgmt_ips = _find_mgmt_ips(stack.outputs)

        if mgmt_ips:
            vnf_dict['mgmt_url'] = jsonutils.dumps(mgmt_ips)
    def create_wait(self, plugin, context, vnf_dict, vnf_id, auth_attr):
        """Create wait function

        Create wait function will marked VNF is ACTIVE when all status state
        from Pod objects is RUNNING.
        """
        # initialize Kubernetes APIs
        auth_cred, file_descriptor = self._get_auth_creds(auth_attr)
        try:
            core_v1_api_client = \
                self.kubernetes.get_core_v1_api_client(auth=auth_cred)
            deployment_info = vnf_id.split(COMMA_CHARACTER)
            mgmt_ips = dict()
            pods_information = self._get_pods_information(
                core_v1_api_client=core_v1_api_client,
                deployment_info=deployment_info)
            status = self._get_pod_status(pods_information)
            stack_retries = self.STACK_RETRIES
            error_reason = None
            while status == 'Pending' and stack_retries > 0:
                time.sleep(self.STACK_RETRY_WAIT)
                pods_information = \
                    self._get_pods_information(
                        core_v1_api_client=core_v1_api_client,
                        deployment_info=deployment_info)
                status = self._get_pod_status(pods_information)
                LOG.debug('status: %s', status)
                stack_retries = stack_retries - 1

            LOG.debug('VNF initializing status: %(service_name)s %(status)s',
                      {'service_name': str(deployment_info), 'status': status})
            if stack_retries == 0 and status != 'Running':
                error_reason = _("Resource creation is not completed within"
                                " {wait} seconds as creation of stack {stack}"
                                " is not completed").format(
                    wait=(self.STACK_RETRIES *
                          self.STACK_RETRY_WAIT),
                    stack=vnf_id)
                LOG.warning("VNF Creation failed: %(reason)s",
                            {'reason': error_reason})
                raise vnfm.VNFCreateWaitFailed(reason=error_reason)
            elif stack_retries != 0 and status != 'Running':
                raise vnfm.VNFCreateWaitFailed(reason=error_reason)

            for i in range(0, len(deployment_info), 2):
                namespace = deployment_info[i]
                deployment_name = deployment_info[i + 1]
                service_info = core_v1_api_client.read_namespaced_service(
                    name=deployment_name,
                    namespace=namespace)
                if service_info.metadata.labels.get("management_connection"):
                    vdu_name = service_info.metadata.labels.\
                        get("vdu_name").split("-")[1]
                    mgmt_ip = service_info.spec.cluster_ip
                    mgmt_ips.update({vdu_name: mgmt_ip})
                    vnf_dict['mgmt_url'] = jsonutils.dumps(mgmt_ips)
        except Exception as e:
            LOG.error('Creating wait VNF got an error due to %s', e)
            raise
        finally:
            self.clean_authenticate_vim(auth_cred, file_descriptor)