Exemple #1
0
    def execute(self):
        """Create cloud region.

        Use settings values:
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID,
         - CLOUD_REGION_TYPE,
         - CLOUD_REGION_VERSION,
         - CLOUD_OWNER_DEFINED_TYPE,
         - COMPLEX_PHYSICAL_LOCATION_ID.

        """
        super().execute()
        self._logger.info("*Check if cloud region exists *")
        try:
            CloudRegion.get_by_id(
                cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
                cloud_region_id=settings.CLOUD_REGION_ID,
            )
        except ResourceNotFound:
            CloudRegion.create(
                cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
                cloud_region_id=settings.CLOUD_REGION_ID,
                orchestration_disabled=False,
                in_maint=False,
                cloud_type=settings.CLOUD_REGION_TYPE,
                cloud_region_version=settings.CLOUD_REGION_VERSION,
                owner_defined_type=settings.CLOUD_OWNER_DEFINED_TYPE,
                complex_name=settings.COMPLEX_PHYSICAL_LOCATION_ID
            )
Exemple #2
0
def test_tenants_info_wrong_cloud_name(mock_send, mock_cloud_regions):
    """Test get Tenant from A&AI."""
    mock_cloud_regions.return_value = CLOUD_REGIONS_ITERATOR
    mock_send.return_value = TENANT
    cloud_name = "Wrong_cloud_name"
    with pytest.raises(Exception) as excinfo:
        CloudRegion.get_by_id("DT", cloud_name)
    assert "not found" in str(excinfo.value)
    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)
def test_cloud_region_get_all():
    requests.get(f"{CloudRegion.base_url}/reset")
    cloud_regions = list(CloudRegion.get_all())
    assert len(cloud_regions) == 0

    with pytest.raises(ResourceNotFound):
        CloudRegion.get_by_id("test_owner", "test_cloud_region")

    cloud_region: CloudRegion = CloudRegion.create("test_owner",
                                                   "test_cloud_region",
                                                   orchestration_disabled=True,
                                                   in_maint=False)
    cloud_regions = list(CloudRegion.get_all())
    assert len(cloud_regions) == 1
    cloud_region = cloud_regions[0]
    assert cloud_region.cloud_owner == "test_owner"
    assert cloud_region.cloud_region_id == "test_cloud_region"
    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
Exemple #6
0
def test_tenants_info(mock_send, mock_cloud_regions):
    """Test get Tenant from A&AI."""
    mock_cloud_regions.return_value = CLOUD_REGIONS_ITERATOR
    mock_send.return_value = TENANT
    cloud_name = "RegionOne"
    cloud_region = CloudRegion.get_by_id("DT", cloud_name)
    res = list(cloud_region.tenants)
    assert len(res) == 1
    assert isinstance(res[0], Tenant)
    tenant = res[0]
    assert tenant.tenant_id == "4bdc6f0f2539430f9428c852ba606808"
    assert tenant.name == "onap-dublin-daily-vnfs"
    assert tenant.context is None
    assert tenant.resource_version == "1562591004273"
    assert tenant.url == (
        f"{tenant.base_url}{tenant.api_version}/cloud-infrastructure/cloud-regions/cloud-region/"
        f"OPNFV/RegionOne/tenants/tenant/4bdc6f0f2539430f9428c852ba606808?"
        f"resource-version=1562591004273")
    def execute(self):
        """Link cloud region to complex.

        Use settings values:
         - COMPLEX_PHYSICAL_LOCATION_ID,
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID.
        """
        super().execute()
        cmplx = Complex(
            physical_location_id=settings.COMPLEX_PHYSICAL_LOCATION_ID,
            name=settings.COMPLEX_PHYSICAL_LOCATION_ID
        )
        cloud_region = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID,
        )
        cloud_region.link_to_complex(cmplx)
Exemple #8
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
    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
    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)
    def execute(self):
        """Register cloud region.

        Use settings values:
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID,
         - CLOUD_DOMAIN,
         - VIM_USERNAME,
         - VIM_PASSWORD,
         - VIM_SERVICE_URL,
         - TENANT_NAME.
        """
        super().execute()
        cloud_region: CloudRegion = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID)
        cloud_region.add_esr_system_info(esr_system_info_id=str(uuid4()),
                                         user_name=settings.VIM_USERNAME,
                                         password=settings.VIM_PASSWORD,
                                         system_type="VIM",
                                         service_url=settings.VIM_SERVICE_URL,
                                         ssl_insecure=False,
                                         system_status="active",
                                         cloud_domain=settings.CLOUD_DOMAIN,
                                         default_tenant=settings.TENANT_NAME)
        if settings.USE_MULTICLOUD:
            self._logger.info("*Multicloud registration *")
            cloud_region.register_to_multicloud()
            time.sleep(20)
            nb_try = 0
            nb_try_max = 3
            while nb_try < nb_try_max:
                try:
                    if not cloud_region.tenants:
                        self._logger.debug(
                            "No tenats available, check one more time")
                        time.sleep(20)
                    else:
                        break
                except ResourceNotFound:
                    self._logger.debug(
                        "No tenats available, check one more time")
                    time.sleep(20)
                nb_try += 1

        # Retrieve the tenant, created by multicloud registration
        # if it does not exist, create it
        try:
            cloud_region.get_tenant(settings.TENANT_ID)
        except ResourceNotFound:
            self._logger.warning(
                "Impossible to retrieve the Specificed Tenant")
            self._logger.debug(
                "If no multicloud selected, add the tenant, reraise otherwise")
            if not settings.USE_MULTICLOUD:
                cloud_region.add_tenant(tenant_id=settings.TENANT_ID,
                                        tenant_name=settings.TENANT_NAME)
            else:
                raise

        # be sure that an availability zone has been created
        # if not, create it
        try:
            cloud_region.get_availability_zone_by_name(
                settings.AVAILABILITY_ZONE_NAME)
        except ResourceNotFound:
            cloud_region.add_availability_zone(settings.AVAILABILITY_ZONE_NAME,
                                               settings.AVAILABILITY_ZONE_TYPE)