From 18d1337095c17b86a83bd955aa0c3bf3c5b4e4ca Mon Sep 17 00:00:00 2001 From: abhijeetkaurav1st Date: Mon, 25 Jul 2022 10:11:08 +0530 Subject: [PATCH] Topic/quickfix vpc failures (#155) * fixing vpc enabled check * fixing vpc enabled check * format and fix vpc tests * added missing test file * fixing vpc project query * black formatting (cherry picked from commit 9a193d949c06342e0e9b32db0aba4a6459f1a2f7) (cherry picked from commit a804977835356d6653b810b03e3a58b6110183f3) --- .../ahv/app_edit_overlay_blueprint.py | 15 ++++++++-- tests/testprep.py | 29 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/tests/cli/runtime_helpers/ahv/app_edit_overlay_blueprint.py b/tests/cli/runtime_helpers/ahv/app_edit_overlay_blueprint.py index 5d153623..1b2775ff 100644 --- a/tests/cli/runtime_helpers/ahv/app_edit_overlay_blueprint.py +++ b/tests/cli/runtime_helpers/ahv/app_edit_overlay_blueprint.py @@ -19,9 +19,17 @@ SUBNET = DSL_CONFIG["ACCOUNTS"]["NUTANIX_PC"][0]["SUBNETS"][0]["NAME"] CLUSTER = DSL_CONFIG["ACCOUNTS"]["NUTANIX_PC"][0]["SUBNETS"][0]["CLUSTER"] NETWORK1 = DSL_CONFIG["AHV"]["NETWORK"]["VLAN1211"] -VPC_PROJECT = ( - DSL_CONFIG.get("VPC_PROJECTS", {}).get("PROJECT1", {}).get("NAME", "default") -) + + +def get_vpc_project(config): + project_name = "default" + vpc_enabled = config.get("IS_VPC_ENABLED", False) + if not vpc_enabled: + return project_name + + project_name = ( + config.get("VPC_PROJECTS", {}).get("PROJECT1", {}).get("NAME", "default") + ) def get_local_az_overlay_details_from_dsl_config(config): @@ -51,6 +59,7 @@ def get_local_az_overlay_details_from_dsl_config(config): NETWORK1, VPC1, CLUSTER1 = get_local_az_overlay_details_from_dsl_config(DSL_CONFIG) +VPC_PROJECT = get_vpc_project(DSL_CONFIG) DefaultCred = basic_cred( CRED_USERNAME, diff --git a/tests/testprep.py b/tests/testprep.py index 42bc2de2..63a8f14c 100644 --- a/tests/testprep.py +++ b/tests/testprep.py @@ -335,15 +335,36 @@ def add_tunnel_details(config): config["VPC_TUNNELS"] = config_tunnels_dict +def check_project_exists(project_name="default"): + client = get_api_client() + + payload = { + "length": 200, + "offset": 0, + "filter": "name=={}".format(project_name), + } + project_name_uuid_map = client.project.get_name_uuid_map(payload) + + if not project_name_uuid_map: + print("Project {} not found".format(project_name)) + return False + + return True + + def add_vpc_details(config): config["IS_VPC_ENABLED"] = False + add_project_details(config, "VPC_PROJECTS", "test_vpc_project") # UUID gets populated if the project actually exists - config_projects = ( - config.get("VPC_PROJECTS", {}).get("PROJECT1", {}).get("UUID", None) - ) - if config_projects: + # config_projects = ( + # config.get("VPC_PROJECTS", {}).get("PROJECT1", {}).get("UUID", None) + # ) + # if config_projects: + # config["IS_VPC_ENABLED"] = True + project_exists = check_project_exists("test_vpc_project") + if project_exists: config["IS_VPC_ENABLED"] = True add_tunnel_details(config)