diff options
author | Michal Chabiera <michal.chabiera@orange.com> | 2021-10-22 15:30:31 +0200 |
---|---|---|
committer | Michal Chabiera <michal.chabiera@orange.com> | 2021-10-24 20:25:33 +0000 |
commit | eb6f96e08346e302b40888c062e654a527c87ad0 (patch) | |
tree | 19ccfd48b3e1e4b6b5664fa7f62387a532a6139d | |
parent | 927d84c4f26a0ca1d4ab68a249207dd4fdbca8f8 (diff) |
[vFW CNF CDS] Fix issue with multiple tenants creation for k8s regionistanbul
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
(cherry picked from commit a8796cca80241822f26e83aea0f5b2dc7b56f92c)
-rwxr-xr-x | heat/vFW_CNF_CDS/automation/config.py | 3 | ||||
-rwxr-xr-x | heat/vFW_CNF_CDS/automation/create_cloud_regions.py | 31 |
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(): |