Skip to content

Commit

Permalink
Fixes stratos config and cluster cache sync (#277) (#274)
Browse files Browse the repository at this point in the history
Address:
1. Fix stratos_config initiation
2. Fix cluster-name sync, (for both version <3.7.0 and >= 3.7.0).
3. Fixes release workflow

(cherry picked from commit f6b1f8351cf1c1c805f23b37d05753e57dd6d699)
  • Loading branch information
abhijeetkaurav1st authored Aug 28, 2023
1 parent f61c671 commit 56c5270
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
8 changes: 7 additions & 1 deletion calm/dsl/cli/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ def get_accounts(name, filter_by, limit, offset, quiet, all_items, account_type)

def get_account(client, account_name):

params = {"filter": "name=={};child_account==true".format(account_name)}
params = {"filter": "name=={}".format(account_name)}

ContextObj = get_context()
stratos_config = ContextObj.get_stratos_config()
if stratos_config.get("stratos_status", False):
params["filter"] += ";child_account==true"

res, err = client.account.list(params=params)
if err:
raise Exception("[{}] - {}".format(err["code"], err["error"]))
Expand Down
14 changes: 10 additions & 4 deletions calm/dsl/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ def get_approval_policy_config(self):
def get_stratos_config(self):
"""returns stratos config"""

if "STRATOS" in self._CONFIG:
return self._CONFIG["STRATOS"]
stratos_config = {}
if "STRATOS" in self._CONFIG_PARSER_OBJECT:
for k, v in self._CONFIG_PARSER_OBJECT.items("STRATOS"):
if k == "stratos_status":
stratos_config[k] = self._CONFIG_PARSER_OBJECT[
"STRATOS"
].getboolean(k)
else:
stratos_config[k] = v

else:
return {}
return stratos_config

def get_categories_config(self):
"""returns categories config"""
Expand Down
49 changes: 20 additions & 29 deletions calm/dsl/db/table_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,23 @@ def sync(cls):
AhvObj = AhvVmProvider.get_api_obj()

for pc_acc_name, pc_acc_uuid in account_name_uuid_map.items():

# Get pe-accoun-uuid to cluster-uuid map
res, err = client.account.read(pc_acc_uuid)
if err:
LOG.error("[{}] - {}".format(err["code"], err["error"]))
continue

pc_acc_data = res.json()
cluster_uuid_pe_account_uuid_map = {}
for _cluster_data in pc_acc_data["status"]["resources"]["data"].get(
"cluster_account_reference_list", []
):
_cluster_uuid = _cluster_data["resources"]["data"].get(
"cluster_uuid", ""
)
cluster_uuid_pe_account_uuid_map[_cluster_uuid] = _cluster_data["uuid"]

try:
res = AhvObj.clusters(account_uuid=pc_acc_uuid)
except Exception:
Expand All @@ -797,37 +814,13 @@ def sync(cls):
)
continue

# TODO the order of cache sync is how their model is defined in table_config.py file
account = AccountCache.get(uuid=pc_acc_uuid)
account_clusters_data = json.loads(account.data).get("clusters", {})
account_clusters_data_rev = {v: k for k, v in account_clusters_data.items()}

for entity in res.get("entities", []):
cluster_name = entity["status"]["name"]
calm_account_name = re.sub(
NON_ALPHA_NUMERIC_CHARACTER,
REPLACED_CLUSTER_NAME_CHARACTER,
entity["status"]["name"],
)
cluster_uuid = entity["metadata"]["uuid"]
cluster_resources = entity["status"]["resources"]
service_list = cluster_resources.get("config", {}).get(
"service_list", []
)

# Here, AHV denotes the 'PE' functionality of a cluster
if "AOS" not in service_list:
LOG.debug(
"Cluster '{}' with UUID '{}' having function {} is not an AHV PE cluster".format(
cluster_name, cluster_uuid, service_list
)
)
continue

# For esxi clusters, there will not be any pe account
if not account_clusters_data_rev.get(calm_account_name, ""):
if not cluster_uuid_pe_account_uuid_map.get(cluster_uuid, ""):
LOG.debug(
"Ignoring cluster '{}' with uuid '{}', as it doesn't have any pc account".format(
"Ignoring cluster '{}' with uuid '{}', as it doesn't have any pe account".format(
cluster_name, cluster_uuid
)
)
Expand All @@ -836,9 +829,7 @@ def sync(cls):
cls.create_entry(
name=cluster_name,
uuid=cluster_uuid,
pe_account_uuid=account_clusters_data_rev.get(
calm_account_name, ""
),
pe_account_uuid=cluster_uuid_pe_account_uuid_map[cluster_uuid],
account_uuid=pc_acc_uuid,
)

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_dsl_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from calm.dsl.config import get_context


def test_stratos_config():
ContextObj = get_context()
stratos_config = ContextObj.get_stratos_config()
assert stratos_config.get("stratos_status", False) in [True, False]


def test_connection_config():
ContextObj = get_context()
connection_config = ContextObj.get_connection_config()
assert isinstance(connection_config["retries_enabled"], bool)
assert isinstance(connection_config["connection_timeout"], int)
assert isinstance(connection_config["read_timeout"], int)

0 comments on commit 56c5270

Please sign in to comment.