aboutsummaryrefslogtreecommitdiffstats
path: root/heat
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
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')
-rwxr-xr-xheat/vFW_CNF_CDS/automation/config.py3
-rwxr-xr-xheat/vFW_CNF_CDS/automation/create_cloud_regions.py31
2 files changed, 22 insertions, 12 deletions
diff --git a/heat/vFW_CNF_CDS/automation/config.py b/heat/vFW_CNF_CDS/automation/config.py
index c0f7b1b4..2c1c96e1 100755
--- a/heat/vFW_CNF_CDS/automation/config.py
+++ b/heat/vFW_CNF_CDS/automation/config.py
@@ -14,8 +14,6 @@
# limitations under the License.
#
# ============LICENSE_END=========================================================
-from uuid import uuid4
-
class Config:
SCENARIO = 1
@@ -117,7 +115,6 @@ class Config:
"cloud_type": "k8s",
"availability_zone": "k8s-availability-zone",
"tenant": {
- "id": str(uuid4()),
"name": K8S_REGION + "-tenant"
},
"customer_resource_definitions": [
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():