Пример #1
0
def test_customer_subscribe_service(mock_send_message, mock_send_message_json):
    customer = Customer(global_customer_id="test_customer_id",
                        subscriber_name="test_subscriber_name",
                        subscriber_type="test_subscriber_type")
    mock_send_message_json.side_effect = (ResourceNotFound,
                                          SERVICE_SUBSCRIPTION)
    customer.subscribe_service("test_service")
Пример #2
0
def test_customer_subscribe_service(mock_send_message, mock_send_message_json):
    customer = Customer(global_customer_id="test_customer_id",
                        subscriber_name="test_subscriber_name",
                        subscriber_type="test_subscriber_type")
    service = SdcService("test_service")
    service._unique_uuid = "1234"
    mock_send_message_json.side_effect = (ValueError, SERVICE_SUBSCRIPTION)
    customer.subscribe_service(service)
Пример #3
0
def test_customers_get_all(mock_send):
    """Test get_all Customer class method."""
    mock_send.return_value = {}
    customers = list(Customer.get_all())
    assert len(customers) == 0

    mock_send.return_value = CUSTOMERS
    customers = list(Customer.get_all())
    assert len(customers) == 1
Пример #4
0
def test_customers(mock_send):
    """Test get_customer function of A&AI."""
    mock_send.return_value = SIMPLE_CUSTOMER
    assert len(list(Customer.get_all())) == 1
    aai_customer_1 = next(Customer.get_all())
    assert aai_customer_1.global_customer_id == "generic"
    assert aai_customer_1.subscriber_name == "generic"
    assert aai_customer_1.subscriber_type == "INFRA"
    assert aai_customer_1.resource_version == "1561218640404"
    mock_send.assert_called_with("GET", 'get customers', mock.ANY)
    def execute(self):
        """Create cutomer.

        Use settings values:
         - GLOBAL_CUSTOMER_ID.
        """
        super().execute()
        try:
            Customer.create(settings.GLOBAL_CUSTOMER_ID,
                            settings.GLOBAL_CUSTOMER_ID, "INFRA")
        except APIError:
            self._logger.warn("Try to update the Customer failed.")
def test_create_customer():

    requests.get(f"{Customer.base_url}/reset")

    customers = list(Customer.get_all())
    assert len(customers) == 0

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    assert customer.global_customer_id == "test_global_customer_id"
    assert customer.subscriber_name == "test_subscriber_name"
    assert customer.subscriber_type == "test_subscriber_type"

    customers = list(Customer.get_all())
    assert len(customers) == 1
def test_link_service_subscription_to_cloud_region_and_tenant():

    requests.get(f"{Customer.base_url}/reset")

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    customer.subscribe_service("service_type")
    service_subscription = customer.get_service_subscription_by_service_type(
        "service_type")

    assert len(list(service_subscription.relationships)) == 0
    with pytest.raises(ParameterError):
        service_subscription.cloud_region
    with pytest.raises(ParameterError):
        service_subscription.tenant

    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)
    assert service_subscription.cloud_region
    assert service_subscription.tenant
Пример #8
0
def test_customer_service_subscription_cloud_region(mock_cloud_region,
                                                    mock_send_serv_sub,
                                                    mock_send):
    """Test Customer's service subscription cloud region object."""
    mock_send.return_value = CUSTOMERS
    customer = next(Customer.get_all())
    mock_send.return_value = SERVICE_SUBSCRIPTION
    service_subscription = customer.get_service_subscription_by_service_type(
        "freeradius")

    mock_send_serv_sub.return_value = {}
    relationships = list(service_subscription.relationships)
    assert len(relationships) == 0
    with pytest.raises(AttributeError):
        service_subscription.cloud_region
    with pytest.raises(AttributeError):
        service_subscription.tenant

    mock_cloud_region.return_value = CLOUD_REGION
    mock_send_serv_sub.return_value = SERVICE_SUBSCRIPTION_RELATIONSHIPS
    relationships = list(service_subscription.relationships)
    assert len(relationships) == 1
    cloud_region = service_subscription.cloud_region
    assert cloud_region.cloud_owner == "OPNFV"
    assert cloud_region.cloud_region_id == "RegionOne"
    assert cloud_region.cloud_type == "openstack"

    mock_cloud_region.side_effect = ValueError
    with pytest.raises(AttributeError):
        service_subscription.tenant
    mock_cloud_region.side_effect = [CLOUD_REGION, TENANT]
    tenant = service_subscription.tenant
    assert tenant.tenant_id == "4bdc6f0f2539430f9428c852ba606808"
    assert tenant.name == "onap-dublin-daily-vnfs"
Пример #9
0
def test_customer_url():
    """Test Customer's url property."""
    customer = Customer("generic", "generic", "INFRA")
    assert customer.url == (
        f"{customer.base_url}{customer.api_version}/business/customers/"
        f"customer/{customer.global_customer_id}?"
        f"resource-version={customer.resource_version}")
    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)
Пример #11
0
def test_customer_get_service_subscription_by_service_type(mock_send):
    """Test Customer's get_service_subscription_by_service_type method."""
    mock_send.return_value = CUSTOMERS
    customer = next(Customer.get_all())

    mock_send.return_value = SERVICE_SUBSCRIPTION
    service_subscription = customer.get_service_subscription_by_service_type("freeradius")
    assert service_subscription.service_type == "freeradius"
Пример #12
0
def test_customer_service_tenant_relations(mock_send):
    """Test the retrieval of service/tenant relations in A&AI."""
    mock_send.return_value = SIMPLE_CUSTOMER
    customer = next(Customer.get_all())
    mock_send.return_value = SERVICE_SUBSCRIPTION
    res = list(customer.service_subscriptions)
    assert len(res) == 2
    assert res[0].service_type == "freeradius"
Пример #13
0
def test_customer_create(mock_send_json, mock_send):
    """Test Customer's create method."""
    mock_send_json.return_value = SIMPLE_CUSTOMER_2
    customer = Customer.create("generic", "generic", "INFRA")
    assert customer.global_customer_id == "generic"
    assert customer.subscriber_name == "generic"
    assert customer.subscriber_type == "INFRA"
    assert customer.resource_version is not None
Пример #14
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
Пример #15
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
Пример #16
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)
def test_subscribe_service():

    requests.get(f"{Customer.base_url}/reset")

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    assert len(list(customer.service_subscriptions)) == 0

    customer.subscribe_service("service_type")
    assert len(list(customer.service_subscriptions)) == 1
    assert customer.get_service_subscription_by_service_type("service_type")
Пример #18
0
def test_get_service_instance_by_filter_parameter(mock_send_message_json):
    """Test Service Subscription get_service_instance_by_filter_parameter method"""
    customer = Customer("generic", "generic", "INFRA")
    service_subscription = ServiceSubscription(
        customer=customer,
        service_type="test_service_type",
        resource_version="test_resource_version")
    mock_send_message_json.return_value = SERVICE_INSTANCES
    service_instance = service_subscription._get_service_instance_by_filter_parameter(
        filter_parameter_name="service-instance-id",
        filter_parameter_value="5410bf79-2aa3-450e-a324-ec5630dc18cf")
    assert service_instance.instance_name == "test"
    assert service_instance.instance_id == "5410bf79-2aa3-450e-a324-ec5630dc18cf"
def test_subscribe_service():

    requests.get(f"{Customer.base_url}/reset")

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    assert len(list(customer.service_subscriptions)) == 0

    service = Service("test_service")
    service.unique_uuid = str(uuid4())
    customer.subscribe_service(service)
    assert len(list(customer.service_subscriptions)) == 1
    assert customer.get_service_subscription_by_service_type(service.name)
Пример #20
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())
Пример #21
0
def test_customer_service_subscription_service_instance(mock_send_serv_sub, mock_send):
    """Test Customer's service subscription service instances."""
    mock_send.return_value = CUSTOMERS
    customer = next(Customer.get_all())
    mock_send.return_value = SERVICE_SUBSCRIPTION
    service_subscription = customer.get_service_subscription_by_service_type("freeradius")

    mock_send_serv_sub.return_value = SERVICE_INSTANCES
    service_instances = list(service_subscription.service_instances)
    assert len(service_instances) == 1
    service_instance = service_instances[0]
    assert service_instance.instance_name == "test"
    assert service_instance.instance_id == "5410bf79-2aa3-450e-a324-ec5630dc18cf"
    assert service_instance.service_subscription == service_subscription
    assert service_instance.url == (f"{service_subscription.url}/service-instances/"
                                    f"service-instance/{service_instance.instance_id}")
    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
Пример #23
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
Пример #24
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
Пример #26
0
def resolve_hc_inputs():
    logger.info("******** Check Customer *******")
    customer = None
    for found_customer in list(Customer.get_all()):
        logger.debug("Customer %s found", found_customer.subscriber_name)
        if found_customer.subscriber_name == Config.GLOBAL_CUSTOMER_ID:
            logger.info("Customer %s found", found_customer.subscriber_name)
            customer = found_customer
            break
    if customer is None:
        raise Exception("Customer %s wasn't found in ONAP" %
                        Config.GLOBAL_CUSTOMER_ID)
    logger.info("******** Check Service Subscription *******")
    service_subscription = None
    for service_sub in customer.service_subscriptions:
        logger.debug("Service subscription %s is found",
                     service_sub.service_type)
        if service_sub.service_type == Config.SERVICENAME:
            logger.info("Service %s subscribed", Config.SERVICENAME)
            service_subscription = service_sub
            break
    logger.info("******** Retrieve Service Metadata *******")
    service_instance = None
    for single_service in service_subscription.service_instances:
        if single_service.instance_name == Config.SERVICE_INSTANCE_NAME:
            service_instance = single_service
            break
    service_id = service_instance.instance_id
    vnfs = list(service_instance.vnf_instances)
    if len(vnfs) > 1:
        raise NotImplementedError(
            "Service %s is composed of more than one vnf!" % service_id)
    if not vnfs:
        raise Exception("Service %s doesn't contain any vnfs" % service_id)
    vnf_id = vnfs[0].vnf_id
    return service_id, vnf_id
Пример #27
0
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("*******************************")
logger.info("**** SERVICE INSTANTIATION ****")
logger.info("*******************************")

logger.info("******** Create Customer *******")
customer = None
for found_customer in list(Customer.get_all()):
    logger.debug("Customer %s found", found_customer.subscriber_name)
    if found_customer.subscriber_name == Config.GLOBAL_CUSTOMER_ID:
        logger.info("Customer %s found", found_customer.subscriber_name)
        customer = found_customer
        break
if not customer:
    customer = Customer.create(Config.GLOBAL_CUSTOMER_ID,
                               Config.GLOBAL_CUSTOMER_ID, "INFRA")

logger.info("******** Find Service in SDC *******")
service = None
services = Service.get_all()
for found_service in services:
    logger.debug("Service %s is found, distribution %s", found_service.name,
                 found_service.distribution_status)
Пример #28
0
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)
Пример #29
0
def test_customers_no_resources(mock_send):
    """Test get_customer function with no customer declared in A&AI."""
    mock_send.return_value = CUSTOMERS_NO_RESOURCES
    assert len(list(Customer.get_all())) == 0
    mock_send.assert_called_with("GET", 'get customers', mock.ANY)
Пример #30
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