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 )
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
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
def test_cloud_region_tenants(): cloud_region: CloudRegion = CloudRegion.create("test_owner", "test_cloud_region", orchestration_disabled=True, in_maint=False) assert len(list(cloud_region.tenants)) == 0 cloud_region.add_tenant(tenant_id="test_tenant_id", tenant_name="test_tenant_name", tenant_context="test_tenant_context") assert len(list(cloud_region.tenants)) == 1 tenant = cloud_region.get_tenant(tenant_id="test_tenant_id")
def test_link_cloud_region_to_complex(): requests.get(f"{Complex.base_url}/reset") cmplx: Complex = Complex.create( name="test_complex", physical_location_id="test_physical_location_id") cloud_region: CloudRegion = CloudRegion.create("test_owner", "test_cloud_region", orchestration_disabled=True, in_maint=False) assert len(list(cloud_region.relationships)) == 0 cloud_region.link_to_complex(cmplx) assert len(list(cloud_region.relationships)) == 1
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 test_cloud_region_creation(mock_send): """Test cloud region creation""" cloud_region = CloudRegion.create(cloud_owner="test_owner", cloud_region_id="test_cloud_region", orchestration_disabled=False, in_maint=True, owner_defined_type="Test", cloud_zone="Test zone", sriov_automation="Test", upgrade_cycle="Test") assert cloud_region.cloud_owner == "test_owner" assert cloud_region.cloud_region_id == "test_cloud_region" assert cloud_region.orchestration_disabled == False assert cloud_region.in_maint == True assert cloud_region.cloud_type == "" assert cloud_region.owner_defined_type == "Test" assert cloud_region.cloud_region_version == "" assert cloud_region.identity_url == "" assert cloud_region.cloud_zone == "Test zone" assert cloud_region.complex_name == "" assert cloud_region.sriov_automation == "Test" assert cloud_region.cloud_extra_info == "" assert cloud_region.upgrade_cycle == "Test"
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
#### Create cloud region if not exists #### logger.info("******** Cloud Region *******") try: cloud_region = list( CloudRegion.get_all(cloud_owner=Config.CLOUD_OWNER, cloud_region_id=Config.CLOUD_REGION))[0] logger.info("Cloud region exists") except IndexError: logger.info("Cloud region does not exists") cloud_region = CloudRegion.create( cloud_owner=Config.CLOUD_OWNER, cloud_region_id=Config.CLOUD_REGION, cloud_type="k8s", owner_defined_type="t1", cloud_region_version="1.0", complex_name=complex.physical_location_id, cloud_zone="CloudZone", sriov_automation="false", orchestration_disabled=False, in_maint=False) logger.info("Cloud region created") logger.info("******** Cloud regiongion <-> Complex *******") cloud_region.link_to_complex(complex) logger.info("******** Availability zone *******") cloud_region.add_availability_zone( availability_zone_name=Config.AVAILABILITY_ZONE_NAME, availability_zone_hypervisor_type=Config.HYPERVISOR_TYPE)
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