diff options
Diffstat (limited to 'src/onaptests/steps/cloud')
-rw-r--r-- | src/onaptests/steps/cloud/cloud_region_create.py | 51 | ||||
-rw-r--r-- | src/onaptests/steps/cloud/k8s_connectivity_info_create.py | 10 | ||||
-rw-r--r-- | src/onaptests/steps/cloud/register_cloud.py | 77 |
3 files changed, 92 insertions, 46 deletions
diff --git a/src/onaptests/steps/cloud/cloud_region_create.py b/src/onaptests/steps/cloud/cloud_region_create.py new file mode 100644 index 0000000..ba46466 --- /dev/null +++ b/src/onaptests/steps/cloud/cloud_region_create.py @@ -0,0 +1,51 @@ +"""A&AI cloud region creation module.""" +from onapsdk.aai.cloud_infrastructure import CloudRegion +from onapsdk.configuration import settings + +from ..base import BaseStep + + +class CloudRegionCreateStep(BaseStep): + """Cloud region creation step.""" + + @property + def description(self) -> str: + """Step description.""" + return "Create cloud region." + + @property + def component(self) -> str: + """Component name.""" + return "AAI" + + @BaseStep.store_state + 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 ValueError: + 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 + ) diff --git a/src/onaptests/steps/cloud/k8s_connectivity_info_create.py b/src/onaptests/steps/cloud/k8s_connectivity_info_create.py index 279ae0d..de0e683 100644 --- a/src/onaptests/steps/cloud/k8s_connectivity_info_create.py +++ b/src/onaptests/steps/cloud/k8s_connectivity_info_create.py @@ -1,3 +1,4 @@ +"""Connectivity info creation module.""" from onapsdk.configuration import settings from onapsdk.msb.k8s import ConnectivityInfo @@ -18,12 +19,12 @@ class K8SConnectivityInfoStep(BaseStep): @BaseStep.store_state def execute(self): - """Creation k8s connectivity information + """Creation k8s connectivity information. Use settings values: - CLOUD_REGION_ID, - CLOUD_REGION_CLOUD_OWNER, - - K8S_KUBECONFIG_FILE. + - K8S_CONFIG. """ super().execute() ######## Create Connectivity Info ######################################### @@ -34,11 +35,10 @@ class K8SConnectivityInfoStep(BaseStep): self._logger.info("Create the k8s connectivity information") ConnectivityInfo.create(settings.CLOUD_REGION_ID, settings.CLOUD_REGION_CLOUD_OWNER, - open(settings.K8S_KUBECONFIG_FILE, 'rb').read()) + open(settings.K8S_CONFIG, 'rb').read()) def cleanup(self) -> None: - """Cleanup K8S Connectivity information. - """ + """Cleanup K8S Connectivity information.""" self._logger.info("Clean the k8s connectivity information") super().cleanup() connectinfo = ConnectivityInfo.get_connectivity_info_by_region_id(settings.CLOUD_REGION_ID) diff --git a/src/onaptests/steps/cloud/register_cloud.py b/src/onaptests/steps/cloud/register_cloud.py index 341fc1c..72da4f7 100644 --- a/src/onaptests/steps/cloud/register_cloud.py +++ b/src/onaptests/steps/cloud/register_cloud.py @@ -1,3 +1,4 @@ +"""A&AI cloud region registstation module.""" import time from uuid import uuid4 @@ -5,11 +6,21 @@ from onapsdk.aai.cloud_infrastructure import CloudRegion from onapsdk.configuration import settings from ..base import BaseStep +from onaptests.steps.cloud.cloud_region_create import CloudRegionCreateStep class RegisterCloudRegionStep(BaseStep): """Cloud region registration step.""" + def __init__(self, cleanup: bool) -> None: + """Initialize step. + + Substeps: + - CloudRegionCreateStep. + """ + super().__init__(cleanup=cleanup) + self.add_step(CloudRegionCreateStep(cleanup=cleanup)) + @property def description(self) -> str: """Step description.""" @@ -22,39 +33,23 @@ class RegisterCloudRegionStep(BaseStep): @BaseStep.store_state def execute(self): - """Register cloud region + """Register cloud region. Use settings values: - CLOUD_REGION_CLOUD_OWNER, - CLOUD_REGION_ID, - CLOUD_DOMAIN, - - CLOUD_REGION_VERSION, - - CLOUD_OWNER_DEFINED_TYPE, - - COMPLEX_PHYSICAL_LOCATION_ID, - VIM_USERNAME, - VIM_PASSWORD, - VIM_SERVICE_URL, - TENANT_NAME. """ super().execute() - self._logger.info("*Check if cloud region exists *") - try: - cloud_region: CloudRegion = CloudRegion.get_by_id( - cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, - cloud_region_id=settings.CLOUD_REGION_ID, - ) - except ValueError: - self._logger.info("*Create the cloud region *") - cloud_region: CloudRegion = 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 - ) + cloud_region: CloudRegion = CloudRegion.get_by_id( + cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, + cloud_region_id=settings.CLOUD_REGION_ID, + ) + if not list(cloud_region.esr_system_infos): cloud_region.add_esr_system_info( esr_system_info_id=str(uuid4()), user_name=settings.VIM_USERNAME, @@ -79,23 +74,23 @@ class RegisterCloudRegionStep(BaseStep): break 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 ValueError: - self._logger.warning("Impossible to retrieve the Specificed Tenant") - self._logger.debug("If no multicloud selected, add the tenant") - cloud_region.add_tenant( - tenant_id=settings.TENANT_ID, - tenant_name=settings.TENANT_NAME) + # Retrieve the tenant, created by multicloud registration + # if it does not exist, create it + try: + cloud_region.get_tenant(settings.TENANT_ID) + except ValueError: + self._logger.warning("Impossible to retrieve the Specificed Tenant") + self._logger.debug("If no multicloud selected, add the tenant") + cloud_region.add_tenant( + tenant_id=settings.TENANT_ID, + tenant_name=settings.TENANT_NAME) - # 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 ValueError: - cloud_region.add_availability_zone( - settings.AVAILABILITY_ZONE_NAME, - settings.AVAILABILITY_ZONE_TYPE) + # 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 ValueError: + cloud_region.add_availability_zone( + settings.AVAILABILITY_ZONE_NAME, + settings.AVAILABILITY_ZONE_TYPE) |