diff --git a/calm/dsl/cli/accounts.py b/calm/dsl/cli/accounts.py index 801fedad..1fff17bb 100644 --- a/calm/dsl/cli/accounts.py +++ b/calm/dsl/cli/accounts.py @@ -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"])) diff --git a/calm/dsl/config/config.py b/calm/dsl/config/config.py index 5bb6bf50..49c19664 100644 --- a/calm/dsl/config/config.py +++ b/calm/dsl/config/config.py @@ -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""" diff --git a/calm/dsl/db/table_config.py b/calm/dsl/db/table_config.py index aef9ad6d..18c9ff6d 100644 --- a/calm/dsl/db/table_config.py +++ b/calm/dsl/db/table_config.py @@ -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: @@ -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 ) ) @@ -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, ) diff --git a/tests/unit/test_dsl_context.py b/tests/unit/test_dsl_context.py new file mode 100644 index 00000000..071df331 --- /dev/null +++ b/tests/unit/test_dsl_context.py @@ -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)