def execute(self):
        """Connect service subsription to cloud region and tenant.

        Use settings values:
         - GLOBAL_CUSTOMER_ID,
         - SERVICE_NAME,
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID.

        """
        super().execute()
        customer: Customer = Customer.get_by_global_customer_id(
            settings.GLOBAL_CUSTOMER_ID)
        service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(
            settings.SERVICE_NAME)
        cloud_region: CloudRegion = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID,
        )

        # retrieve tenant
        # for which we are sure that an availability zone has been created
        tenant: Tenant = cloud_region.get_tenant(settings.TENANT_ID)

        service_subscription.link_to_cloud_region_and_tenant(
            cloud_region=cloud_region, tenant=tenant)
예제 #2
0
def test_customer_get_by_global_customer_id(mock_send):
    """Test Customer's get_by_global_customer_id method."""
    mock_send.return_value = SIMPLE_CUSTOMER_2
    customer = Customer.get_by_global_customer_id("generic")
    assert customer.global_customer_id == "generic"
    assert customer.subscriber_name == "generic"
    assert customer.subscriber_type == "INFRA"
    assert customer.resource_version is not None
예제 #3
0
    def execute(self):
        """Create customer service subsription.

        Use settings values:
         - GLOBAL_CUSTOMER_ID,
         - SERVICE_NAME.
        """
        super().execute()
        service = Service(name=settings.SERVICE_NAME)
        customer = Customer.get_by_global_customer_id(
            settings.GLOBAL_CUSTOMER_ID)
        customer.subscribe_service(service)
예제 #4
0
    def execute(self):
        """Creation of k8s profile for resource bundle definition

        Use settings values:
         - GLOBAL_CUSTOMER_ID
         - K8S_PROFILE_K8S_VERSION
         - K8S_PROFILE_ARTIFACT_PATH.
        """
        self._logger.info("Create the k8s profile if it doesn't exist")
        super().execute()
        customer: Customer = Customer.get_by_global_customer_id(
            settings.GLOBAL_CUSTOMER_ID)
        service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(
            self.service_name)
        self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(
            self.service_instance_name)

        for vnf_instance in self._service_instance.vnf_instances:
            # possible to have several modules for 1 VNF
            for vf_module in vnf_instance.vnf.vf_modules:
                # Define profile (rb_profile) for resource bundle definition
                # Retrieve resource bundle definition (rbdef) corresponding to vf module
                rbdef_name = vf_module.metadata["vfModuleModelInvariantUUID"]
                rbdef_version = vf_module.metadata["vfModuleModelUUID"]
                rbdef = Definition.get_definition_by_name_version(
                    rbdef_name, rbdef_version)
                # Get k8s profile name from yaml service template
                vnf_parameters = self.get_vnf_parameters(vnf_instance.vnf.name)
                k8s_profile_name = ""
                k8s_profile_namespace = ""
                for param in vnf_parameters:
                    if param.name == "k8s-rb-profile-name":
                        k8s_profile_name = param.value
                    if param.name == "k8s-rb-profile-namespace":
                        k8s_profile_namespace = param.value
                if k8s_profile_name == "" or k8s_profile_namespace == "":
                    self._logger.error("Missing rb profile information")
                    raise onap_test_exceptions.ProfileInformationException

                ######## Check profile for Definition ###################################
                try:
                    rbdef.get_profile_by_name(k8s_profile_name)
                except ResourceNotFound:
                    ######## Create profile for Definition ###################################
                    profile = rbdef.create_profile(
                        k8s_profile_name, k8s_profile_namespace,
                        settings.K8S_PROFILE_K8S_VERSION)
                    ####### Upload artifact for created profile ##############################
                    profile.upload_artifact(
                        open(settings.K8S_PROFILE_ARTIFACT_PATH, 'rb').read())
    def execute(self):
        """Instantiate service.

        Use settings values:
         - SERVICE_NAME,
         - GLOBAL_CUSTOMER_ID,
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID,
         - TENANT_ID,
         - OWNING_ENTITY,
         - PROJECT,
         - SERVICE_INSTANCE_NAME.
        """
        super().execute()
        service = Service(settings.SERVICE_NAME)
        customer: Customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID)
        cloud_region: CloudRegion = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID,
        )
        tenant: Tenant = cloud_region.get_tenant(settings.TENANT_ID)
        try:
            owning_entity = AaiOwningEntity.get_by_owning_entity_name(
                settings.OWNING_ENTITY)
        except ResourceNotFound:
            self._logger.info("Owning entity not found, create it")
            owning_entity = AaiOwningEntity.create(settings.OWNING_ENTITY)
        vid_project = Project.create(settings.PROJECT)

        service_instantiation = ServiceInstantiation.instantiate_so_ala_carte(
            service,
            cloud_region,
            tenant,
            customer,
            owning_entity,
            vid_project,
            service_instance_name=settings.SERVICE_INSTANCE_NAME
        )
        try:
            service_instantiation.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT)
        except TimeoutError:
            self._logger.error("Service instantiation %s timed out", self.service_instance_name)
            raise onap_test_exceptions.ServiceInstantiateException
        if service_instantiation.failed:
            self._logger.error("Service instantiation %s failed", self.service_instance_name)
            raise onap_test_exceptions.ServiceInstantiateException
예제 #6
0
    def execute(self) -> None:
        """Instantiate Vf module.

        Use settings values:
         - GLOBAL_CUSTOMER_ID.

        Raises:
            Exception: Vf module instantiation failed

        """
        super().execute()
        customer: Customer = Customer.get_by_global_customer_id(
            settings.GLOBAL_CUSTOMER_ID)
        service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(
            self.service_name)
        self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(
            self.service_instance_name)
        cloud_region: CloudRegion = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID,
        )
        tenant: Tenant = cloud_region.get_tenant(settings.TENANT_ID)

        for vnf_instance in self._service_instance.vnf_instances:
            # possible to have several moduels for 1 VNF
            for vf_module in vnf_instance.vnf.vf_modules:
                vf_module_instantiation = vnf_instance.add_vf_module(
                    vf_module,
                    cloud_region,
                    tenant,
                    self._service_instance_name,
                    vnf_parameters=self.get_vnf_parameters(
                        vnf_instance.vnf.name))
                try:
                    vf_module_instantiation.wait_for_finish(
                        settings.ORCHESTRATION_REQUEST_TIMEOUT)
                    if vf_module_instantiation.failed:
                        self._logger.error("VfModule instantiation %s failed",
                                           vf_module.name)
                        raise onap_test_exceptions.VfModuleInstantiateException
                except TimeoutError:
                    self._logger.error("VfModule instantiation %s timed out",
                                       vf_module.name)
                    raise onap_test_exceptions.VfModuleInstantiateException
예제 #7
0
    def execute(self) -> None:
        """Instantiate Vl.

        Use settings values:
         - GLOBAL_CUSTOMER_ID.

        Raises:
            Exception: Vl instantiation failed

        """
        super().execute()
        service: Service = Service(self.service_name)
        customer: Customer = Customer.get_by_global_customer_id(
            settings.GLOBAL_CUSTOMER_ID)
        service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(
            self.service_name)
        service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(
            self.service_instance_name)
        self._service_instance = service_instance
        line_of_business: LineOfBusiness = LineOfBusiness(
            settings.LINE_OF_BUSINESS)
        platform: Platform = Platform(settings.PLATFORM)
        for idx, network in enumerate(service.networks):
            #for network in self.yaml_template[self.service_name]["networks"]:
            net_instantiation = service_instance.add_network(
                network,
                line_of_business,
                platform,
                network_instance_name=f"{self.service_instance_name}_net_{idx}",
                subnets=self.get_subnets(network.name))
            try:
                net_instantiation.wait_for_finish(
                    settings.ORCHESTRATION_REQUEST_TIMEOUT)
                if net_instantiation.failed:
                    self._logger.error("VL instantiation %s failed",
                                       net_instantiation.name)
                    raise onap_test_exceptions.NetworkInstantiateException
            except TimeoutError:
                self._logger.error("VL instantiation %s timed out",
                                   net_instantiation.name)
                raise onap_test_exceptions.NetworkInstantiateException
    def execute(self):
        """Instantiate vnf.

        Use settings values:
         - GLOBAL_CUSTOMER_ID,
         - LINE_OF_BUSINESS.

        Raises:
            Exception: VNF instantiation failed

        """
        super().execute()
        service: Service = Service(self.service_name)
        customer: Customer = Customer.get_by_global_customer_id(
            settings.GLOBAL_CUSTOMER_ID)
        service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(
            self.service_name)
        self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(
            self.service_instance_name)
        line_of_business: LineOfBusiness = LineOfBusiness(
            settings.LINE_OF_BUSINESS)
        platform: Platform = Platform(settings.PLATFORM)
        cloud_region: CloudRegion = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID,
        )
        tenant: Tenant = cloud_region.get_tenant(settings.TENANT_ID)
        for idx, vnf in enumerate(service.vnfs):
            vnf_instantiation = self._service_instance.add_vnf(
                vnf, line_of_business, platform, cloud_region, tenant,
                f"{self.service_instance_name}_vnf_{idx}")
            try:
                vnf_instantiation.wait_for_finish(
                    settings.ORCHESTRATION_REQUEST_TIMEOUT)
                if vnf_instantiation.failed:
                    self._logger.error("VNF instantiation %s failed", vnf.name)
                    raise onap_test_exceptions.VnfInstantiateException
            except TimeoutError:
                self._logger.error("VNF instantiation %s timed out", vnf.name)
                raise onap_test_exceptions.VnfInstantiateException
예제 #9
0
파일: delete.py 프로젝트: rajewluk/demo
from config import Config

logger = logging.getLogger("")
logger.setLevel(logging.DEBUG)
fh = logging.StreamHandler()
fh_formatter = logging.Formatter(
    '%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s'
)
fh.setFormatter(fh_formatter)
logger.addHandler(fh)

logger.info("******** Get Customer *******")
customer = None
try:
    customer = Customer.get_by_global_customer_id(Config.GLOBAL_CUSTOMER_ID)
except:
    logger.error("Customer not found")
    exit(1)

logger.info("******** Check Service Subscription *******")
service_subscription = None
for service_sub in customer.service_subscriptions:
    if service_sub.service_type == Config.SERVICENAME:
        logger.info("Service %s subscribed", Config.SERVICENAME)
        service_subscription = service_sub
        break
if not service_subscription:
    logger.error("Service Subscription not found")
    exit(1)
    def execute(self):
        """Instantiate service.

        Use settings values:
         - GLOBAL_CUSTOMER_ID,
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID,
         - TENANT_ID,
         - OWNING_ENTITY,
         - PROJECT.

        Raises:
            Exception: Service instantiation failed

        """
        super().execute()
        service = Service(self.service_name)
        customer: Customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID)
        cloud_region: CloudRegion = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID,
        )
        tenant: Tenant = cloud_region.get_tenant(settings.TENANT_ID)
        try:
            owning_entity = AaiOwningEntity.get_by_owning_entity_name(
                settings.OWNING_ENTITY)
        except ResourceNotFound:
            self._logger.info("Owning entity not found, create it")
            owning_entity = AaiOwningEntity.create(settings.OWNING_ENTITY)
        vid_project = Project.create(settings.PROJECT)

        # Before instantiating, be sure that the service has been distributed
        self._logger.info("******** Check Service Distribution *******")
        distribution_completed = False
        nb_try = 0
        nb_try_max = 10
        while distribution_completed is False and nb_try < nb_try_max:
            distribution_completed = service.distributed
            if distribution_completed is True:
                self._logger.info(
                "Service Distribution for %s is sucessfully finished",
                service.name)
                break
            self._logger.info(
                "Service Distribution for %s ongoing, Wait for 60 s",
                service.name)
            time.sleep(60)
            nb_try += 1

        if distribution_completed is False:
            self._logger.error(
                "Service Distribution for %s failed !!",service.name)
            raise onap_test_exceptions.ServiceDistributionException

        service_instantiation = ServiceInstantiation.instantiate_so_ala_carte(
            service,
            cloud_region,
            tenant,
            customer,
            owning_entity,
            vid_project,
            service_instance_name=self.service_instance_name
        )
        try:
            service_instantiation.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT)
        except TimeoutError:
            self._logger.error("Service instantiation %s timed out", self.service_instance_name)
            raise onap_test_exceptions.ServiceCleanupException
        if service_instantiation.failed:
            self._logger.error("Service instantiation %s failed", self.service_instance_name)
            raise onap_test_exceptions.ServiceInstantiateException
        else:
            service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(self.service_name)
            self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name)