aboutsummaryrefslogtreecommitdiffstats
path: root/heat/vFW_CNF_CDS/automation/create_cloud_regions.py
diff options
context:
space:
mode:
authorMichal Chabiera <michal.chabiera@orange.com>2021-10-22 15:30:31 +0200
committerMichal Chabiera <michal.chabiera@orange.com>2021-10-22 15:59:54 +0200
commita8796cca80241822f26e83aea0f5b2dc7b56f92c (patch)
tree7251e5cf5c68f4bab8c8c642293702994d4a7e2f /heat/vFW_CNF_CDS/automation/create_cloud_regions.py
parent734b3d2134b4e1dd3cd946b8badd2baf83f97110 (diff)
[vFW CNF CDS] Fix issue with multiple tenants creation for k8s region
Every time create_cloud_regions is run tenant with new id is created for k8s region. With this fix tenants for k8s regions are searched by name. Issue-ID: INT-1960 Signed-off-by: Michal Chabiera <michal.chabiera@orange.com> Change-Id: I0b29fd6049e0b6e1f581eb1bd92882f43a2dbade
Diffstat (limited to 'heat/vFW_CNF_CDS/automation/create_cloud_regions.py')
-rwxr-xr-xheat/vFW_CNF_CDS/automation/create_cloud_regions.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/heat/vFW_CNF_CDS/automation/create_cloud_regions.py b/heat/vFW_CNF_CDS/automation/create_cloud_regions.py
index d4b318f9..eb3e95bb 100755
--- a/heat/vFW_CNF_CDS/automation/create_cloud_regions.py
+++ b/heat/vFW_CNF_CDS/automation/create_cloud_regions.py
@@ -17,6 +17,7 @@
import logging
import os
+from uuid import uuid4
from onapsdk.so.so_db_adapter import SoDbAdapter, IdentityService
@@ -109,17 +110,29 @@ def add_availability_zone(cloud_region):
def add_tenant(cloud_region):
logger.info("******** Tenant *******")
region_id = cloud_region.cloud_region_id
- tenant_id = Config.CLOUD_REGIONS[region_id]["tenant"]["id"]
+ is_k8s = is_k8s_region(region_id)
tenant_name = Config.CLOUD_REGIONS[region_id]["tenant"]["name"]
- try:
- cloud_region.get_tenant(tenant_id)
- logger.info("Tenant exists")
- except ResourceNotFound:
- logger.info("Tenant does not exist")
- cloud_region.add_tenant(tenant_id=tenant_id,
- tenant_name=tenant_name)
- logger.info("Tenant added to region")
+ if is_k8s:
+ try:
+ next(_tenant for _tenant in cloud_region.tenants if _tenant.name == 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=tenant_name)
+ logger.info(f"Tenant {tenant_name} added to region")
+ else:
+ tenant_id = Config.CLOUD_REGIONS[region_id]["tenant"]["id"]
+ try:
+ cloud_region.get_tenant(tenant_id)
+ logger.info("Tenant exists")
+ except ResourceNotFound:
+ logger.info("Tenant does not exist")
+ cloud_region.add_tenant(tenant_id=tenant_id,
+ tenant_name=tenant_name)
+ logger.info(f"Tenant {tenant_name} added to region")
def create_customer():