Skip to content

Commit

Permalink
Fixed test_overlay_subnet_bp.py test failure (#369)
Browse files Browse the repository at this point in the history
Issue Link: (https://jira.nutanix.com/browse/CALM-42344),
(https://jira.nutanix.com/browse/CALM-42346)

Description:
1. Config mismatch in json assertion fixed

![image](https://github.com/ideadevice/calm-dsl/assets/123161845/5e8faa84-5f29-48c3-abd5-539bc217cf30)

2. Fixed quota not enabling issue with DSL_PROJECT_WITH_VPC_PATH in
`tests/cli/test_project_commands.py`

![image](https://github.com/ideadevice/calm-dsl/assets/123161845/42833fe1-764f-41c9-913d-a9454fc91a10)

4. Moved `get_local_az_overlay_details_from_dsl_config ` in
`tests/utils.py` due to redundant occurrence in test files

(cherry picked from commit aa8b52b5f0a79865782706ff0f42954724afa0a0)
  • Loading branch information
dwivediprab authored and navtejpreetsingh committed Jan 24, 2024
1 parent f557eb8 commit c09a0f6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
"nic_list": [
{
"network_function_nic_type": "INGRESS",
"nic_type": "DIRECT_NIC",
"nic_type": "NORMAL_NIC",
"subnet_reference": {
"kind": "subnet",
"name": "vpc_subnet_1",
Expand Down
29 changes: 1 addition & 28 deletions tests/ahv_vm_overlay_subnet/test_overlay_subnet_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,11 @@
from calm.dsl.builtins import vm_disk_package, AhvVmDisk, AhvVmNic
from calm.dsl.builtins import AhvVmGC, AhvVmResources, AhvVm, Ref

from tests.utils import get_vpc_project
from tests.utils import get_vpc_project, get_local_az_overlay_details_from_dsl_config

DSL_CONFIG = json.loads(read_local_file(".tests/config.json"))
VPC_PROJECT = get_vpc_project(DSL_CONFIG)


def get_local_az_overlay_details_from_dsl_config(config):
networks = config["ACCOUNTS"]["NUTANIX_PC"]
local_az_account = None
for account in networks:
if account.get("NAME") == "NTNX_LOCAL_AZ":
local_az_account = account
break
overlay_subnets_list = local_az_account.get("OVERLAY_SUBNETS", [])
vlan_subnets_list = local_az_account.get("SUBNETS", [])

cluster = ""
vpc = ""
overlay_subnet = ""

for subnet in overlay_subnets_list:
if subnet["NAME"] == "vpc_subnet_1" and subnet["VPC"] == "vpc_name_1":
overlay_subnet = subnet["NAME"]
vpc = subnet["VPC"]

for subnet in vlan_subnets_list:
if subnet["NAME"] == config["AHV"]["NETWORK"]["VLAN1211"]:
cluster = subnet["CLUSTER"]
break
return overlay_subnet, vpc, cluster


NETWORK1, VPC1, CLUSTER1 = get_local_az_overlay_details_from_dsl_config(DSL_CONFIG)

# SSH Credentials
Expand Down
29 changes: 1 addition & 28 deletions tests/cli/runtime_helpers/ahv/app_edit_overlay_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from calm.dsl.builtins import read_local_file, read_spec
from calm.dsl.builtins import readiness_probe, Ref, Metadata
from calm.dsl.builtins import AppEdit, PatchField, AhvUpdateConfigAttrs
from tests.utils import get_vpc_project
from tests.utils import get_vpc_project, get_local_az_overlay_details_from_dsl_config

CRED_USERNAME = read_local_file(".tests/username")
CRED_PASSWORD = read_local_file(".tests/password")
Expand All @@ -21,33 +21,6 @@
CLUSTER = DSL_CONFIG["ACCOUNTS"]["NUTANIX_PC"][0]["SUBNETS"][0]["CLUSTER"]
NETWORK1 = DSL_CONFIG["AHV"]["NETWORK"]["VLAN1211"]


def get_local_az_overlay_details_from_dsl_config(config):
networks = config["ACCOUNTS"]["NUTANIX_PC"]
local_az_account = None
for account in networks:
if account.get("NAME") == "NTNX_LOCAL_AZ":
local_az_account = account
break
overlay_subnets_list = local_az_account.get("OVERLAY_SUBNETS", [])
vlan_subnets_list = local_az_account.get("SUBNETS", [])

cluster = ""
vpc = ""
overlay_subnet = ""

for subnet in overlay_subnets_list:
if subnet["NAME"] == "vpc_subnet_1" and subnet["VPC"] == "vpc_name_1":
overlay_subnet = subnet["NAME"]
vpc = subnet["VPC"]

for subnet in vlan_subnets_list:
if subnet["NAME"] == config["AHV"]["NETWORK"]["VLAN1211"]:
cluster = subnet["CLUSTER"]
break
return overlay_subnet, vpc, cluster


NETWORK1, VPC1, CLUSTER1 = get_local_az_overlay_details_from_dsl_config(DSL_CONFIG)
VPC_PROJECT = get_vpc_project(DSL_CONFIG)

Expand Down
28 changes: 1 addition & 27 deletions tests/cli/runtime_helpers/ahv/test_app_edit_overlay_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from calm.dsl.store import Version
from distutils.version import LooseVersion as LV
from tests.utils import get_local_az_overlay_details_from_dsl_config

CRED_USERNAME = read_local_file(".tests/username")
CRED_PASSWORD = read_local_file(".tests/password")
Expand All @@ -26,33 +27,6 @@

LOG = get_logging_handle(__name__)


def get_local_az_overlay_details_from_dsl_config(config):
networks = config["ACCOUNTS"]["NUTANIX_PC"]
local_az_account = None
for account in networks:
if account.get("NAME") == "NTNX_LOCAL_AZ":
local_az_account = account
break
overlay_subnets_list = local_az_account.get("OVERLAY_SUBNETS", [])
vlan_subnets_list = local_az_account.get("SUBNETS", [])

cluster = ""
vpc = ""
overlay_subnet = ""

for subnet in overlay_subnets_list:
if subnet["NAME"] == "vpc_subnet_1" and subnet["VPC"] == "vpc_name_1":
overlay_subnet = subnet["NAME"]
vpc = subnet["VPC"]

for subnet in vlan_subnets_list:
if subnet["NAME"] == config["AHV"]["NETWORK"]["VLAN1211"]:
cluster = subnet["CLUSTER"]
break
return overlay_subnet, vpc, cluster


NETWORK1, VPC1, CLUSTER1 = get_local_az_overlay_details_from_dsl_config(DSL_CONFIG)


Expand Down
14 changes: 14 additions & 0 deletions tests/project/test_project_update_in_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from calm.dsl.builtins import Project
from calm.dsl.builtins import Provider, Ref, read_local_file
from tests.utils import get_local_az_overlay_details_from_dsl_config

DSL_CONFIG = json.loads(read_local_file(".tests/config.json"))
ACCOUNTS = DSL_CONFIG["ACCOUNTS"]
Expand Down Expand Up @@ -29,6 +30,10 @@
USER = DSL_CONFIG["USERS"][0]
USER_NAME = USER["NAME"]

VLAN_NETWORK = DSL_CONFIG["AHV"]["NETWORK"]["VLAN1211"]

NETWORK1, VPC1, CLUSTER1 = get_local_az_overlay_details_from_dsl_config(DSL_CONFIG)


class TestDslProject(Project):
"""Sample DSL Project"""
Expand All @@ -38,6 +43,15 @@ class TestDslProject(Project):
account=Ref.Account(NTNX_ACCOUNT_NAME),
subnets=[Ref.Subnet(name=NTNX_SUBNET, cluster=NTNX_SUBNET_CLUSTER)],
),
Provider.Ntnx(
account=Ref.Account("NTNX_LOCAL_AZ"),
subnets=[
Ref.Subnet(name=VLAN_NETWORK, cluster=CLUSTER1),
Ref.Subnet(name=NETWORK1, vpc=VPC1),
],
clusters=[Ref.Cluster(name=CLUSTER1, account_name="NTNX_LOCAL_AZ")],
vpcs=[Ref.Vpc(name=VPC1, account_name="NTNX_LOCAL_AZ")],
),
Provider.Aws(account=Ref.Account(AWS_ACCOUNT_NAME)),
Provider.Azure(account=Ref.Account(AZURE_ACCOUNT_NAME)),
Provider.Gcp(account=Ref.Account(GCP_ACCOUNT_NAME)),
Expand Down
33 changes: 6 additions & 27 deletions tests/project/test_project_with_overlay_subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,10 @@
from calm.dsl.builtins import Project
from calm.dsl.builtins import Provider, Ref
from calm.dsl.builtins.models.utils import read_local_file
from tests.utils import get_local_az_overlay_details_from_dsl_config

DSL_CONFIG = json.loads(read_local_file(".tests/config.json"))


def get_local_az_overlay_details_from_dsl_config(config):
networks = config["ACCOUNTS"]["NUTANIX_PC"]
local_az_account = None
for account in networks:
if account.get("NAME") == "NTNX_LOCAL_AZ":
local_az_account = account
break
overlay_subnets_list = local_az_account.get("OVERLAY_SUBNETS", [])
vlan_subnets_list = local_az_account.get("SUBNETS", [])

cluster = ""
vpc = ""
overlay_subnet = ""

for subnet in overlay_subnets_list:
if subnet["NAME"] == "vpc_subnet_1" and subnet["VPC"] == "vpc_name_1":
overlay_subnet = subnet["NAME"]
vpc = subnet["VPC"]

for subnet in vlan_subnets_list:
if subnet["NAME"] == config["AHV"]["NETWORK"]["VLAN1211"]:
cluster = subnet["CLUSTER"]
break
return overlay_subnet, vpc, cluster


VLAN_NETWORK = DSL_CONFIG["AHV"]["NETWORK"]["VLAN1211"]
NETWORK1, VPC1, CLUSTER1 = get_local_az_overlay_details_from_dsl_config(DSL_CONFIG)

Expand All @@ -51,3 +25,8 @@ class TestDslWithOverlaySubnetProject(Project):
vpcs=[Ref.Vpc(name=VPC1, account_name="NTNX_LOCAL_AZ")],
),
]
quotas = {
"vcpus": 1,
"storage": 2,
"memory": 1,
}
29 changes: 1 addition & 28 deletions tests/project/test_project_with_overlay_subnets_and_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from calm.dsl.builtins import Substrate, Environment
from calm.dsl.builtins import AhvVmDisk, AhvVmNic, AhvVmGC
from calm.dsl.builtins import basic_cred, AhvVmResources, AhvVm
from tests.utils import get_local_az_overlay_details_from_dsl_config


CENTOS_KEY = read_local_file(".tests/keys/centos")
Expand Down Expand Up @@ -45,34 +46,6 @@

DSL_CONFIG = json.loads(read_local_file(".tests/config.json"))


def get_local_az_overlay_details_from_dsl_config(config):
networks = config["ACCOUNTS"]["NUTANIX_PC"]
local_az_account = None
for account in networks:
if account.get("NAME") == NTNX_ACCOUNT_NAME:
local_az_account = account
break
overlay_subnets_list = local_az_account.get("OVERLAY_SUBNETS", [])
vlan_subnets_list = local_az_account.get("SUBNETS", [])

cluster = ""
vpc = ""
overlay_subnet = ""

for subnet in overlay_subnets_list:
if subnet["NAME"] == "vpc_subnet_1" and subnet["VPC"] == "vpc_name_1":
overlay_subnet = subnet["NAME"]
vpc = subnet["VPC"]
break

for subnet in vlan_subnets_list:
if subnet["NAME"] == config["AHV"]["NETWORK"]["VLAN1211"]:
cluster = subnet["CLUSTER"]
break
return overlay_subnet, vpc, cluster


VLAN_NETWORK = DSL_CONFIG["AHV"]["NETWORK"]["VLAN1211"]
NETWORK1, VPC1, CLUSTER1 = get_local_az_overlay_details_from_dsl_config(DSL_CONFIG)

Expand Down
26 changes: 26 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,29 @@ def get_escript_language_from_version(script_version="static"):
else:
script_language = "" # we can use .py2 as well for static versions
return script_language


def get_local_az_overlay_details_from_dsl_config(config):
networks = config["ACCOUNTS"]["NUTANIX_PC"]
local_az_account = None
for account in networks:
if account.get("NAME") == "NTNX_LOCAL_AZ":
local_az_account = account
break
overlay_subnets_list = local_az_account.get("OVERLAY_SUBNETS", [])
vlan_subnets_list = local_az_account.get("SUBNETS", [])

cluster = ""
vpc = ""
overlay_subnet = ""

for subnet in overlay_subnets_list:
if subnet["NAME"] == "vpc_subnet_1" and subnet["VPC"] == "vpc_name_1":
overlay_subnet = subnet["NAME"]
vpc = subnet["VPC"]

for subnet in vlan_subnets_list:
if subnet["NAME"] == config["AHV"]["NETWORK"]["VLAN1211"]:
cluster = subnet["CLUSTER"]
break
return overlay_subnet, vpc, cluster

0 comments on commit c09a0f6

Please sign in to comment.