コード例 #1
0
def test_service_instance_aai_service_instance():
    customer_mock = mock.MagicMock()
    service_instantiation = ServiceInstantiation(
        name="test",
        request_id="test_request_id",
        instance_id="test_instance_id",
        sdc_service=mock.MagicMock(),
        cloud_region=mock.MagicMock(),
        tenant=mock.MagicMock(),
        customer=customer_mock,
        owning_entity=mock.MagicMock(),
        project=mock.MagicMock())
    status_mock = mock.PropertyMock(
        return_value=ServiceInstantiation.StatusEnum.IN_PROGRESS)
    type(service_instantiation).status = status_mock
    with pytest.raises(StatusError):
        service_instantiation.aai_service_instance

    status_mock.return_value = return_value = ServiceInstantiation.StatusEnum.COMPLETED
    assert service_instantiation.aai_service_instance is not None

    customer_mock.get_service_subscription_by_service_type.side_effect = APIError
    with pytest.raises(APIError) as err:
        service_instantiation.aai_service_instance
    assert err.type == APIError
コード例 #2
0
def test_a_la_carte_vl_instantiation():
    requests.get(f"{ServiceInstantiation.base_url}/reset")
    requests.get(f"{Customer.base_url}/reset")
    requests.post(f"{ServiceInstantiation.base_url}/set_aai_mock",
                  json={"AAI_MOCK": settings.AAI_URL})

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    service = Service("test_service")
    service.unique_uuid = str(uuid4())
    service.identifier = str(uuid4())
    service.name = str(uuid4())
    customer.subscribe_service("service_type")
    service_subscription = customer.get_service_subscription_by_service_type(
        "service_type")
    cloud_region = CloudRegion.create("test_owner",
                                      "test_cloud_region",
                                      orchestration_disabled=True,
                                      in_maint=False)
    cloud_region.add_tenant(tenant_id="test_tenant_name",
                            tenant_name="test_tenant_name",
                            tenant_context="test_tenant_context")
    tenant = cloud_region.get_tenant(tenant_id="test_tenant_name")
    service_subscription.link_to_cloud_region_and_tenant(
        cloud_region=cloud_region, tenant=tenant)
    owning_entity = "test_owning_entity"
    project = "test_project"

    # Service instantiation
    service._distributed = True
    assert len(list(service_subscription.service_instances)) == 0
    service_instantiation_request = ServiceInstantiation.instantiate_ala_carte(
        service, cloud_region, tenant, customer, owning_entity, project,
        service_subscription)
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.IN_PROGRESS
    service_instantiation_request.wait_for_finish()
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.COMPLETED
    assert len(list(service_subscription.service_instances)) == 1

    # Network instantiation
    service_instance = next(service_subscription.service_instances)
    assert len(list(service_instance.network_instances)) == 0
    owning_entity = "test_owning_entity"
    project = "test_project"
    network = MagicMock()
    line_of_business = "test_line_of_business"
    platform = "test_platform"
    with pytest.raises(AttributeError):
        service_instance.network(network, line_of_business, platform)
    service_instance.orchestration_status = "Active"
    with patch.object(ServiceInstance, "sdc_service", return_value=service):
        network_instantiation_request = service_instance.add_network(
            network, line_of_business, platform)
    assert network_instantiation_request.status == VnfInstantiation.StatusEnum.IN_PROGRESS
    network_instantiation_request.wait_for_finish()
    assert network_instantiation_request.status == VnfInstantiation.StatusEnum.COMPLETED
    assert len(list(service_instance.network_instances)) == 1
コード例 #3
0
def test_instantiation_wait_for_finish():
    with mock.patch.object(ServiceInstantiation,
                           "finished",
                           new_callable=mock.PropertyMock) as mock_finished:
        with mock.patch.object(
                ServiceInstantiation, "completed",
                new_callable=mock.PropertyMock) as mock_completed:
            instantiation = ServiceInstantiation(
                name="test",
                request_id="test",
                instance_id="test",
                sdc_service=mock.MagicMock(),
                cloud_region=mock.MagicMock(),
                tenant=mock.MagicMock(),
                customer=mock.MagicMock(),
                owning_entity=mock.MagicMock(),
                project=mock.MagicMock())
            instantiation.WAIT_FOR_SLEEP_TIME = 0
            mock_finished.side_effect = [False, False, True]
            mock_completed.return_value = True
            rv = namedtuple("Value", ["return_value"])
            instantiation._wait_for_finish(rv)
            assert rv.return_value
コード例 #4
0
    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
コード例 #5
0
    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)
        if any(
                filter(lambda x: x in self.yaml_template[self.service_name].keys(),
                       ["vnfs", "networks"])):
            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)
        else:
            cloud_region, tenant = None, None  # Only PNF is going to be instantiated so
                                               # neither cloud_region nor tenant are needed
        try:
            owning_entity = OwningEntity.get_by_owning_entity_name(
                settings.OWNING_ENTITY)
        except ResourceNotFound:
            self._logger.info("Owning entity not found, create it")
            owning_entity = OwningEntity.create(settings.OWNING_ENTITY)
        vid_project: Project = Project(settings.PROJECT)
        line_of_business: LineOfBusiness = LineOfBusiness(settings.LINE_OF_BUSINESS)
        platform: Platform = Platform(settings.PLATFORM)

        # 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

        vnf_params_list: List[VnfParameters] = []
        for vnf_data in self.yaml_template[self.service_name].get("vnfs", []):
            vnf_params_list.append(VnfParameters(
                vnf_data["vnf_name"],
                [InstantiationParameter(name=parameter["name"], value=parameter["value"]) for parameter in vnf_data.get("vnf_parameters", [])],
                [VfmoduleParameters(vf_module_data["vf_module_name"],
                 [InstantiationParameter(name=parameter["name"], value=parameter["value"]) for parameter in vf_module_data.get("parameters", [])]) \
                     for vf_module_data in vnf_data.get("vf_module_parameters", [])]
            ))

        service_instantiation = ServiceInstantiation.instantiate_macro(
            service,
            customer=customer,
            owning_entity=owning_entity,
            project=vid_project,
            line_of_business=line_of_business,
            platform=platform,
            cloud_region=cloud_region,
            tenant=tenant,
            service_instance_name=self.service_instance_name,
            vnf_parameters=vnf_params_list,
            enable_multicloud=settings.USE_MULTICLOUD
        )
        try:
            service_instantiation.wait_for_finish(timeout=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
        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)
コード例 #6
0
            params.append(
                InstantiationParameter(name=vfmodule_param_name,
                                       value=vfmodule_param_value))

        vfmodules_param.append(VfmoduleParameters(vfmodule, params))

    vnf_params = VnfParameters(name=Config.VFNAME,
                               vnf_parameters=vnf_param,
                               vfmodule_parameters=vfmodules_param)

    service_instantiation = ServiceInstantiation.instantiate_macro(
        sdc_service=service,
        cloud_region=cloud_region,
        tenant=tenant,
        customer=customer,
        owning_entity=owning_entity,
        project=vid_project,
        line_of_business=vid_line_of_business,
        platform=vid_platform,
        service_instance_name=Config.SERVICE_INSTANCE_NAME,
        vnf_parameters=[vnf_params])
    logger.info("Instantiation request ID: %s",
                service_instantiation.request_id)
    logger.info("Service Instance ID: %s", service_instantiation.instance_id)
    status = None
    while not (status == OrchestrationRequest.StatusEnum.COMPLETED
               or status == OrchestrationRequest.StatusEnum.FAILED):
        sleep(10)
        status = service_instantiation.status
        logger.info(f"Orchestration status is: {status.value}")
コード例 #7
0
def test_a_la_carte_instantiation():
    requests.get(f"{ServiceInstantiation.base_url}/reset")
    requests.get(f"{Customer.base_url}/reset")
    requests.post(f"{ServiceInstantiation.base_url}/set_aai_mock",
                  json={"AAI_MOCK": settings.AAI_URL})

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    service = Service("test_service")
    service.unique_uuid = str(uuid4())
    service.identifier = str(uuid4())
    service.name = str(uuid4())
    customer.subscribe_service(service)
    service_subscription = customer.get_service_subscription_by_service_type(
        service.name)
    cloud_region = CloudRegion.create("test_owner",
                                      "test_cloud_region",
                                      orchestration_disabled=True,
                                      in_maint=False)
    cloud_region.add_tenant(tenant_id="test_tenant_name",
                            tenant_name="test_tenant_name",
                            tenant_context="test_tenant_context")
    tenant = cloud_region.get_tenant(tenant_id="test_tenant_name")
    service_subscription.link_to_cloud_region_and_tenant(
        cloud_region=cloud_region, tenant=tenant)
    owning_entity = OwningEntity(name="test_owning_entity")
    project = Project(name="test_project")

    # Service instantiation
    service._distributed = True
    assert len(list(service_subscription.service_instances)) == 0
    service_instantiation_request = ServiceInstantiation.instantiate_so_ala_carte(
        service, cloud_region, tenant, customer, owning_entity, project)
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.COMPLETED
    assert len(list(service_subscription.service_instances)) == 1

    # Vnf instantiation
    service_instance = next(service_subscription.service_instances)
    assert len(list(service_instance.vnf_instances)) == 0
    owning_entity = OwningEntity(name="test_owning_entity")
    project = Project(name="test_project")
    vnf = MagicMock()
    line_of_business = LineOfBusiness(name="test_line_of_business")
    platform = Platform(name="test_platform")
    with pytest.raises(AttributeError):
        service_instance.add_vnf(vnf, line_of_business, platform)
    service_instance.orchestration_status = "Active"
    with patch.object(ServiceSubscription, "sdc_service",
                      return_value=service):
        vnf_instantiation_request = service_instance.add_vnf(
            vnf, line_of_business, platform)
    assert vnf_instantiation_request.status == VnfInstantiation.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert vnf_instantiation_request.status == VnfInstantiation.StatusEnum.COMPLETED
    assert len(list(service_instance.vnf_instances)) == 1
    # VfModule instantiation
    vnf_instance = next(service_instance.vnf_instances)
    assert len(list(vnf_instance.vf_modules)) == 0
    vnf.metadata = {"UUID": vnf_instance.model_version_id}
    vf_module = MagicMock()

    with patch.object(ServiceSubscription, "sdc_service",
                      return_value=service) as service_mock:
        service_mock.vnfs = [vnf]
        vf_module_instantiation_request = vnf_instance.add_vf_module(vf_module)
    assert vf_module_instantiation_request.status == VfModuleInstantiation.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert vf_module_instantiation_request.status == VfModuleInstantiation.StatusEnum.COMPLETED
    assert len(list(vnf_instance.vf_modules)) == 1

    # Cleanup
    vf_module_instance = next(vnf_instance.vf_modules)
    vf_module_deletion_request = vf_module_instance.delete()
    assert vf_module_deletion_request.status == VfModuleDeletionRequest.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert vf_module_deletion_request.status == VfModuleDeletionRequest.StatusEnum.COMPLETED
    assert len(list(vnf_instance.vf_modules)) == 0

    vnf_deletion_request = vnf_instance.delete()
    assert vnf_deletion_request.status == VnfDeletionRequest.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert vnf_deletion_request.status == VnfDeletionRequest.StatusEnum.COMPLETED
    assert len(list(service_instance.vnf_instances)) == 0

    with patch.object(ServiceSubscription, "sdc_service",
                      return_value=service) as service_mock:
        service_deletion_request = service_instance.delete()
    assert service_deletion_request.status == ServiceDeletionRequest.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert service_deletion_request.status == ServiceDeletionRequest.StatusEnum.COMPLETED
    assert len(list(service_subscription.service_instances)) == 0
コード例 #8
0
    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)
コード例 #9
0
def test_instantiate_macro_multiple_vnf(mock_service_components,
                                        mock_service_vnfs):
    requests.get(f"{ServiceInstantiation.base_url}/reset")
    requests.get(f"{Customer.base_url}/reset")
    requests.post(f"{ServiceInstantiation.base_url}/set_aai_mock",
                  json={"AAI_MOCK": settings.AAI_URL})

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    service = Service("test_service")
    service._tosca_template = "n/a"

    mock_service_vnfs.return_value = [
        Vnf(name="test_vnf",
            node_template_type="vf",
            model_name="test_vnf_model",
            model_version_id=str(uuid4()),
            model_invariant_id=str(uuid4()),
            model_version="1.0",
            model_customization_id=str(uuid4()),
            model_instance_name=str(uuid4()),
            component=MagicMock(),
            vf_modules=[
                VfModule(name="TestVnfModel..base..module-0",
                         group_type="vf-module",
                         model_name="TestVnfModel..base..module-0",
                         model_version_id=str(uuid4()),
                         model_invariant_uuid=str(uuid4()),
                         model_version="1",
                         model_customization_id=str(uuid4()),
                         properties=None)
            ])
    ]
    service.unique_uuid = str(uuid4())
    service.identifier = str(uuid4())
    service.name = str(uuid4())
    customer.subscribe_service("service_type")
    service_subscription = customer.get_service_subscription_by_service_type(
        "service_type")
    cloud_region = CloudRegion.create("test_owner",
                                      "test_cloud_region",
                                      orchestration_disabled=True,
                                      in_maint=False)
    cloud_region.add_tenant(tenant_id="test_tenant_name",
                            tenant_name="test_tenant_name",
                            tenant_context="test_tenant_context")
    tenant = cloud_region.get_tenant(tenant_id="test_tenant_name")
    service_subscription.link_to_cloud_region_and_tenant(
        cloud_region=cloud_region, tenant=tenant)
    owning_entity = "test_owning_entity"
    project = "test_project"
    line_of_business = "test_line_of_business"
    platform = "test_platform"

    so_service = SoService.load({
        "subscription_service_type":
        "service_type",
        "vnfs": [{
            "model_name":
            "test_vnf_model",
            "instance_name":
            "vnf0",
            "parameters": {
                "param1": "value1"
            },
            "vf_modules": [{
                "instance_name": "vnf0_vfm0",
                "model_name": "base",
                "parameters": {
                    "vfm_param1": "vfm_value1"
                }
            }]
        }, {
            "model_name":
            "test_vnf_model",
            "instance_name":
            "vnf1",
            "parameters": {
                "param2": "value2"
            },
            "vf_modules": [{
                "instance_name": "vnf1_vfm0",
                "model_name": "base",
                "parameters": {
                    "vfm_param2": "vfm_value2"
                }
            }]
        }]
    })

    # Service instantiation
    service._distributed = True
    assert len(list(service_subscription.service_instances)) == 0
    service_instantiation_request = ServiceInstantiation.instantiate_macro(
        sdc_service=service,
        customer=customer,
        owning_entity=owning_entity,
        project=project,
        line_of_business=line_of_business,
        platform=platform,
        cloud_region=cloud_region,
        tenant=tenant,
        so_service=so_service)
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.COMPLETED
    assert len(list(service_subscription.service_instances)) == 1
    service_instance = next(service_subscription.service_instances)

    # Cleanup
    with patch.object(ServiceInstance, "sdc_service",
                      return_value=service) as service_mock:
        service_deletion_request = service_instance.delete()
    assert service_deletion_request.status == ServiceDeletionRequest.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert service_deletion_request.status == ServiceDeletionRequest.StatusEnum.COMPLETED
    assert len(list(service_subscription.service_instances)) == 0