diff options
author | Michal Chabiera <michal.chabiera@orange.com> | 2021-10-25 10:06:13 +0200 |
---|---|---|
committer | Michal Chabiera <michal.chabiera@orange.com> | 2021-10-25 10:06:13 +0200 |
commit | 9480fc39d7a85c6c980395c24bc27636f7dd7b47 (patch) | |
tree | 31cf82e7821a55651a00b00100624710da6b75af | |
parent | 9aa527e48dc4ee5d4284385a8081782f87691a79 (diff) |
[vFW CNF CDS] Fix issues with k8s cloud region creation for honoluluhonolulu
1. Creation of multiple tenants with the same name
2. Availablity zone creation
3. Handle exceptions
Issue-ID: INT-1960
Signed-off-by: Michal Chabiera <michal.chabiera@orange.com>
Change-Id: I830bd3a76164888b427aa94ebd7e839ac335a60a
-rw-r--r-- | heat/vFW_CNF_CDS/automation/create_k8s_region.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/heat/vFW_CNF_CDS/automation/create_k8s_region.py b/heat/vFW_CNF_CDS/automation/create_k8s_region.py index ca680cf1..bd050762 100644 --- a/heat/vFW_CNF_CDS/automation/create_k8s_region.py +++ b/heat/vFW_CNF_CDS/automation/create_k8s_region.py @@ -25,6 +25,7 @@ from so_db_adapter import SoDBUpdate from onapsdk.aai.business import Customer from onapsdk.aai.cloud_infrastructure import Complex, CloudRegion from onapsdk.msb.k8s import ConnectivityInfo +from onapsdk.exceptions import ResourceNotFound logger = logging.getLogger("") logger.setLevel(logging.DEBUG) @@ -40,7 +41,7 @@ logger.info("******** Complex *******") try: complex = list(Complex.get_all(physical_location_id=Config.COMPLEX_ID))[0] logger.info("Complex exists") -except IndexError: +except (IndexError, ResourceNotFound): logger.info("Complex does not exists") complex = Complex.create(physical_location_id=Config.COMPLEX_ID, name=Config.COMPLEX_ID, @@ -57,7 +58,7 @@ 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: +except (IndexError, ResourceNotFound): logger.info("Cloud region does not exists") cloud_region = CloudRegion.create(cloud_owner=Config.CLOUD_OWNER, cloud_region_id=Config.CLOUD_REGION, @@ -75,11 +76,25 @@ 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) +try: + az = cloud_region.get_availability_zone_by_name(Config.AVAILABILITY_ZONE_NAME) + logger.info("Availability zone exists") +except ResourceNotFound: + logger.info("Availability zone does not exist") + cloud_region.add_availability_zone(availability_zone_name=Config.AVAILABILITY_ZONE_NAME, + availability_zone_hypervisor_type=Config.HYPERVISOR_TYPE) + logger.info("Availability zone added to region") logger.info("******** Tenant *******") -cloud_region.add_tenant(str(uuid4()), Config.TENANT_NAME) +try: + next(_tenant for _tenant in cloud_region.tenants if _tenant.name == Config.TENANT_NAME) + logger.info("Tenant exists") +except (StopIteration, ResourceNotFound): + tenant_id = str(uuid4()) + logger.info("Tenant does not exist") + cloud_region.add_tenant(tenant_id=tenant_id, + tenant_name=Config.TENANT_NAME) + logger.info(f"Tenant {Config.TENANT_NAME} added to region") #### Update or create connectivity info #### logger.info("******** Connectivity Info *******") |