From: garciadeblas Date: Thu, 7 Nov 2024 11:41:54 +0000 (+0100) Subject: Refactor check resource functions from odu_workflows to k8s X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F13%2F14713%2F4;p=osm%2FLCM.git Refactor check resource functions from odu_workflows to k8s Change-Id: Ie5c13ad84dfeab47476b92e4ce64f772dd7af7ca Signed-off-by: garciadeblas --- diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 572b902..744e5c0 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -20,13 +20,61 @@ __author__ = ( import logging from time import time +import traceback from osm_lcm.lcm_utils import LcmBase from copy import deepcopy from osm_lcm import odu_workflows from osm_lcm import vim_sdn -class ClusterLcm(LcmBase): +class GitOpsLcm(LcmBase): + def __init__(self, msg, lcm_tasks, config): + self.logger = logging.getLogger("lcm.gitops") + self.lcm_tasks = lcm_tasks + self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) + self._checkloop_kustomization_timeout = 900 + self._checkloop_resource_timeout = 900 + self._workflows = {} + super().__init__(msg, self.logger) + + async def check_dummy_operation(self, op_id, op_params, content): + self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") + return True, "OK" + + async def common_check_list(self, checkings_list): + try: + for checking in checkings_list: + if checking["enable"]: + status, message = await self.odu.readiness_loop( + item=checking["item"], + name=checking["name"], + namespace=checking["namespace"], + flag=checking["flag"], + timeout=checking["timeout"], + ) + if not status: + return status, message + except Exception as e: + self.logger.debug(traceback.format_exc()) + self.logger.debug(f"Exception: {e}", exc_info=True) + return False, f"Unexpected exception: {e}" + return True, "OK" + + async def check_resource_status(self, key, op_id, op_params, content): + self.logger.info( + f"Check resource status. Key: {key}. Operation: {op_id}. Params: {op_params}. Content: {content}" + ) + check_resource_function = self._workflows.get(key, {}).get( + "check_resource_function" + ) + self.logger.info("check_resource function : {}".format(check_resource_function)) + if check_resource_function: + return await check_resource_function(op_id, op_params, content) + else: + return await self.check_dummy_operation(op_id, op_params, content) + + +class ClusterLcm(GitOpsLcm): db_collection = "clusters" def __init__(self, msg, lcm_tasks, config): @@ -35,14 +83,17 @@ class ClusterLcm(LcmBase): :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) + super().__init__(msg, lcm_tasks, config) + self._workflows = { + "create_cluster": { + "check_resource_function": self.check_create_cluster, + }, + "deregister_cluster": { + "check_resource_function": self.check_deregister_cluster, + }, + } self.regist = vim_sdn.K8sClusterLcm(msg, self.lcm_tasks, config) - super().__init__(msg, self.logger) - async def create(self, op_id, op_params, content): self.logger.info("cluster Create Enter") db_cluster = content["cluster"] @@ -79,7 +130,7 @@ class ClusterLcm(LcmBase): ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_cluster", op_id, op_params, content ) self.logger.info( @@ -100,6 +151,69 @@ class ClusterLcm(LcmBase): self.update_profile_state(db_cluster, workflow_status, resource_status) return + async def check_create_cluster(self, op_id, op_params, content): + self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") + db_cluster = content["cluster"] + cluster_name = db_cluster["git_name"].lower() + cluster_kustomization_name = cluster_name + db_vim_account = content["vim_account"] + cloud_type = db_vim_account["vim_type"] + nodepool_name = "" + if cloud_type == "aws": + nodepool_name = f"{cluster_name}-nodegroup" + cluster_name = f"{cluster_name}-cluster" + elif cloud_type == "gcp": + nodepool_name = f"nodepool-{cluster_name}" + bootstrap = op_params.get("bootstrap", True) + if cloud_type in ("azure", "gcp", "aws"): + checkings_list = [ + { + "item": "kustomization", + "name": cluster_kustomization_name, + "namespace": "managed-resources", + "flag": "Ready", + "timeout": self._checkloop_kustomization_timeout, + "enable": True, + }, + { + "item": f"cluster_{cloud_type}", + "name": cluster_name, + "namespace": "", + "flag": "Synced", + "timeout": self._checkloop_resource_timeout, + "enable": True, + }, + { + "item": f"cluster_{cloud_type}", + "name": cluster_name, + "namespace": "", + "flag": "Ready", + "timeout": self._checkloop_resource_timeout, + "enable": True, + }, + { + "item": "kustomization", + "name": f"{cluster_kustomization_name}-bstrp-fluxctrl", + "namespace": "managed-resources", + "flag": "Ready", + "timeout": self._checkloop_kustomization_timeout, + "enable": bootstrap, + }, + ] + else: + return False, "Not suitable VIM account to check cluster status" + if nodepool_name: + nodepool_check = { + "item": f"nodepool_{cloud_type}", + "name": nodepool_name, + "namespace": "", + "flag": "Ready", + "timeout": self._checkloop_resource_timeout, + "enable": True, + } + checkings_list.insert(3, nodepool_check) + return await self.common_check_list(checkings_list) + def update_profile_state(self, db_cluster, workflow_status, resource_status): profiles = [ "infra_controller_profiles", @@ -157,7 +271,7 @@ class ClusterLcm(LcmBase): self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_cluster", op_id, op_params, content ) self.logger.info( @@ -266,7 +380,7 @@ class ClusterLcm(LcmBase): self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "attach_profile_to_cluster", op_id, op_params, content ) self.logger.info( @@ -329,7 +443,7 @@ class ClusterLcm(LcmBase): self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "detach_profile_from_cluster", op_id, op_params, content ) self.logger.info( @@ -397,7 +511,7 @@ class ClusterLcm(LcmBase): ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "register_cluster", op_id, op_params, content ) self.logger.info( @@ -448,7 +562,7 @@ class ClusterLcm(LcmBase): self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "deregister_cluster", op_id, op_params, content ) self.logger.info( @@ -472,6 +586,27 @@ class ClusterLcm(LcmBase): self.db.del_one("clusters", {"_id": db_cluster["_id"]}) return + async def check_deregister_cluster(self, op_id, op_params, content): + self.logger.info("check_deregister_cluster Enter") + self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") + # Clean secrets + self.logger.info("Cleaning kubeconfig") + cluster_name = content["cluster"]["git_name"].lower() + items = { + "secrets": [ + { + "name": f"kubeconfig-{cluster_name}", + "namespace": "managed-resources", + }, + ] + } + + try: + await self.odu.clean_items(items) + except Exception as e: + return False, f"Error while cleaning items: {e}" + return True, "OK" + async def get_creds(self, op_id, db_cluster): self.logger.info("Cluster get creds Enter") result, cluster_creds = await self.odu.get_cluster_credentials(db_cluster) @@ -520,7 +655,7 @@ class ClusterLcm(LcmBase): f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "update_cluster", op_id, op_params, content ) self.logger.info( @@ -551,7 +686,7 @@ class ClusterLcm(LcmBase): return -class CloudCredentialsLcm(LcmBase): +class CloudCredentialsLcm(GitOpsLcm): db_collection = "vim_accounts" def __init__(self, msg, lcm_tasks, config): @@ -560,12 +695,7 @@ class CloudCredentialsLcm(LcmBase): :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) - - super().__init__(msg, self.logger) + super().__init__(msg, lcm_tasks, config) async def add(self, op_id, op_params, content): self.logger.info("Cloud Credentials create") @@ -590,7 +720,7 @@ class CloudCredentialsLcm(LcmBase): ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_cloud_credentials", op_id, op_params, content ) self.logger.info( @@ -628,7 +758,7 @@ class CloudCredentialsLcm(LcmBase): ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "update_cloud_credentials", op_id, op_params, content ) self.logger.info( @@ -651,7 +781,7 @@ class CloudCredentialsLcm(LcmBase): ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_cloud_credentials", op_id, op_params, content ) self.logger.info( @@ -663,19 +793,14 @@ class CloudCredentialsLcm(LcmBase): return -class K8sAppLcm(LcmBase): +class K8sAppLcm(GitOpsLcm): def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) - - super().__init__(msg, self.logger) + super().__init__(msg, lcm_tasks, config) async def create(self, op_id, op_params, content): self.logger.info("App Create Enter") @@ -704,7 +829,7 @@ class K8sAppLcm(LcmBase): self.db.set_one("k8sapp", {"_id": content["_id"]}, content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_profile", op_id, op_params, content ) self.logger.info( @@ -752,7 +877,7 @@ class K8sAppLcm(LcmBase): self.db.set_one("k8sapp", {"_id": content["_id"]}, content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_profile", op_id, op_params, content ) self.logger.info( @@ -777,19 +902,14 @@ class K8sAppLcm(LcmBase): return -class K8sResourceLcm(LcmBase): +class K8sResourceLcm(GitOpsLcm): def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) - - super().__init__(msg, self.logger) + super().__init__(msg, lcm_tasks, config) async def create(self, op_id, op_params, content): self.logger.info("Resource Create Enter") @@ -818,7 +938,7 @@ class K8sResourceLcm(LcmBase): self.db.set_one("k8sresource", {"_id": content["_id"]}, content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_profile", op_id, op_params, content ) self.logger.info( @@ -867,7 +987,7 @@ class K8sResourceLcm(LcmBase): self.db.set_one("k8sresource", {"_id": content["_id"]}, content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_profile", op_id, op_params, content ) self.logger.info( @@ -892,19 +1012,14 @@ class K8sResourceLcm(LcmBase): return -class K8sInfraControllerLcm(LcmBase): +class K8sInfraControllerLcm(GitOpsLcm): def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) - - super().__init__(msg, self.logger) + super().__init__(msg, lcm_tasks, config) async def create(self, op_id, op_params, content): self.logger.info("Infra controller Create Enter") @@ -933,7 +1048,7 @@ class K8sInfraControllerLcm(LcmBase): self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_profile", op_id, op_params, content ) self.logger.info( @@ -981,7 +1096,7 @@ class K8sInfraControllerLcm(LcmBase): self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_profile", op_id, op_params, content ) self.logger.info( @@ -1006,19 +1121,14 @@ class K8sInfraControllerLcm(LcmBase): return -class K8sInfraConfigLcm(LcmBase): +class K8sInfraConfigLcm(GitOpsLcm): def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) - - super().__init__(msg, self.logger) + super().__init__(msg, lcm_tasks, config) async def create(self, op_id, op_params, content): self.logger.info("Infra config Create Enter") @@ -1047,7 +1157,7 @@ class K8sInfraConfigLcm(LcmBase): self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_profile", op_id, op_params, content ) self.logger.info( @@ -1094,7 +1204,7 @@ class K8sInfraConfigLcm(LcmBase): content = self.update_operation_history(content, workflow_status, None) self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_profile", op_id, op_params, content ) self.logger.info( @@ -1119,7 +1229,7 @@ class K8sInfraConfigLcm(LcmBase): return -class OkaLcm(LcmBase): +class OkaLcm(GitOpsLcm): db_collection = "okas" def __init__(self, msg, lcm_tasks, config): @@ -1128,12 +1238,7 @@ class OkaLcm(LcmBase): :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) - - super().__init__(msg, self.logger) + super().__init__(msg, lcm_tasks, config) async def create(self, op_id, op_params, content): self.logger.info("OKA Create Enter") @@ -1162,7 +1267,7 @@ class OkaLcm(LcmBase): self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_oka", op_id, op_params, db_content ) self.logger.info( @@ -1212,7 +1317,7 @@ class OkaLcm(LcmBase): self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "update_oka", op_id, op_params, db_content ) self.logger.info( @@ -1261,7 +1366,7 @@ class OkaLcm(LcmBase): self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_oka", op_id, op_params, db_content ) self.logger.info( @@ -1287,7 +1392,7 @@ class OkaLcm(LcmBase): return -class KsuLcm(LcmBase): +class KsuLcm(GitOpsLcm): db_collection = "ksus" def __init__(self, msg, lcm_tasks, config): @@ -1296,12 +1401,7 @@ class KsuLcm(LcmBase): :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', :return: None """ - - self.logger = logging.getLogger("lcm.gitops") - self.lcm_tasks = lcm_tasks - self.odu = odu_workflows.OduWorkflow(msg, self.lcm_tasks, config) - - super().__init__(msg, self.logger) + super().__init__(msg, lcm_tasks, config) async def create(self, op_id, op_params, content): self.logger.info("ksu Create Enter") @@ -1338,7 +1438,7 @@ class KsuLcm(LcmBase): ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "create_ksus", op_id, op_params, content ) self.logger.info( @@ -1395,7 +1495,7 @@ class KsuLcm(LcmBase): f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" ) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "update_ksus", op_id, op_params, content ) self.logger.info( @@ -1455,7 +1555,7 @@ class KsuLcm(LcmBase): self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "delete_ksus", op_id, op_params, content ) self.logger.info( @@ -1506,7 +1606,7 @@ class KsuLcm(LcmBase): self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "clone_ksus", op_id, op_params, db_content ) self.logger.info( @@ -1552,7 +1652,7 @@ class KsuLcm(LcmBase): self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: - resource_status, resource_msg = await self.odu.check_resource_status( + resource_status, resource_msg = await self.check_resource_status( "move_ksus", op_id, op_params, db_content ) self.logger.info( diff --git a/osm_lcm/odu_libs/cluster_mgmt.py b/osm_lcm/odu_libs/cluster_mgmt.py index bfaad75..81d85ec 100644 --- a/osm_lcm/odu_libs/cluster_mgmt.py +++ b/osm_lcm/odu_libs/cluster_mgmt.py @@ -446,104 +446,3 @@ async def clean_items_cluster_register(self, op_id, op_params, content): return True, "OK" except Exception as e: return False, f"Error while cleaning items: {e}" - - -async def check_create_cluster(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - db_cluster = content["cluster"] - cluster_name = db_cluster["git_name"].lower() - cluster_kustomization_name = cluster_name - db_vim_account = content["vim_account"] - cloud_type = db_vim_account["vim_type"] - nodepool_name = "" - if cloud_type == "aws": - nodepool_name = f"{cluster_name}-nodegroup" - cluster_name = f"{cluster_name}-cluster" - elif cloud_type == "gcp": - nodepool_name = f"nodepool-{cluster_name}" - bootstrap = op_params.get("bootstrap", True) - if cloud_type in ("azure", "gcp", "aws"): - checkings_list = [ - { - "item": "kustomization", - "name": cluster_kustomization_name, - "namespace": "managed-resources", - "flag": "Ready", - "timeout": self._odu_checkloop_kustomization_timeout, - "enable": True, - }, - { - "item": f"cluster_{cloud_type}", - "name": cluster_name, - "namespace": "", - "flag": "Synced", - "timeout": self._odu_checkloop_resource_timeout, - "enable": True, - }, - { - "item": f"cluster_{cloud_type}", - "name": cluster_name, - "namespace": "", - "flag": "Ready", - "timeout": self._odu_checkloop_resource_timeout, - "enable": True, - }, - { - "item": "kustomization", - "name": f"{cluster_kustomization_name}-bstrp-fluxctrl", - "namespace": "managed-resources", - "flag": "Ready", - "timeout": self._odu_checkloop_kustomization_timeout, - "enable": bootstrap, - }, - ] - else: - return False, "Not suitable VIM account to check cluster status" - if nodepool_name: - nodepool_check = { - "item": f"nodepool_{cloud_type}", - "name": nodepool_name, - "namespace": "", - "flag": "Ready", - "timeout": self._odu_checkloop_resource_timeout, - "enable": True, - } - checkings_list.insert(3, nodepool_check) - return await self.common_check_list(checkings_list) - - -async def check_update_cluster(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_delete_cluster(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_register_cluster(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_deregister_cluster(self, op_id, op_params, content): - self.logger.info("check_deregister_cluster Enter") - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - # Clean secrets - self.logger.info("Cleaning kubeconfig") - cluster_name = content["cluster"]["git_name"].lower() - items = { - "secrets": [ - { - "name": f"kubeconfig-{cluster_name}", - "namespace": "managed-resources", - }, - ] - } - - try: - await self.clean_items(items) - except Exception as e: - return False, f"Error while cleaning items: {e}" - return True, "OK" diff --git a/osm_lcm/odu_libs/ksu.py b/osm_lcm/odu_libs/ksu.py index 886a6cc..188da8f 100644 --- a/osm_lcm/odu_libs/ksu.py +++ b/osm_lcm/odu_libs/ksu.py @@ -403,28 +403,3 @@ async def clean_items_ksu_update(self, op_id, op_params_list, content_list): ) # self.logger.debug(f"Content: {content_list}") return await self.clean_items_ksu_create(op_id, op_params_list, content_list) - - -async def check_create_ksus(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_update_ksus(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_delete_ksus(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_clone_ksu(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_move_ksu(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" diff --git a/osm_lcm/odu_libs/oka.py b/osm_lcm/odu_libs/oka.py index e639a50..c9205ed 100644 --- a/osm_lcm/odu_libs/oka.py +++ b/osm_lcm/odu_libs/oka.py @@ -170,18 +170,3 @@ async def delete_oka(self, op_id, op_params, content): api_version="v1alpha1", ) return workflow_name - - -async def check_create_oka(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_update_oka(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_delete_oka(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" diff --git a/osm_lcm/odu_libs/profiles.py b/osm_lcm/odu_libs/profiles.py index 179bd3a..323250e 100644 --- a/osm_lcm/odu_libs/profiles.py +++ b/osm_lcm/odu_libs/profiles.py @@ -182,23 +182,3 @@ async def detach_profile_from_cluster(self, op_id, op_params, content): api_version="v1alpha1", ) return workflow_name - - -async def check_create_profile(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_delete_profile(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_attach_profile_to_cluster(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_detach_profile_from_cluster(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" diff --git a/osm_lcm/odu_libs/vim_mgmt.py b/osm_lcm/odu_libs/vim_mgmt.py index 08633b0..edb16ab 100644 --- a/osm_lcm/odu_libs/vim_mgmt.py +++ b/osm_lcm/odu_libs/vim_mgmt.py @@ -234,18 +234,3 @@ async def clean_items_cloud_credentials_update(self, op_id, op_params, content): f"clean_items_cloud_credentials_update Enter. Operation {op_id}. Params: {op_params}" ) return await self.clean_items_cloud_credentials_create(op_id, op_params, content) - - -async def check_create_cloud_credentials(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_update_cloud_credentials(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - - -async def check_delete_cloud_credentials(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" diff --git a/osm_lcm/odu_libs/workflows.py b/osm_lcm/odu_libs/workflows.py index 61b9353..f3b9295 100644 --- a/osm_lcm/odu_libs/workflows.py +++ b/osm_lcm/odu_libs/workflows.py @@ -17,7 +17,6 @@ import asyncio -import traceback import yaml from math import ceil @@ -116,23 +115,3 @@ async def readiness_loop(self, item, name, namespace, flag, timeout): False, "{item} {name} was not ready after {max_iterations} iterations (aprox {timeout} seconds)", ) - - -async def common_check_list(self, checkings_list): - try: - for checking in checkings_list: - if checking["enable"]: - status, message = await self.readiness_loop( - item=checking["item"], - name=checking["name"], - namespace=checking["namespace"], - flag=checking["flag"], - timeout=checking["timeout"], - ) - if not status: - return status, message - except Exception as e: - self.logger.debug(traceback.format_exc()) - self.logger.debug(f"Exception: {e}", exc_info=True) - return False, f"Unexpected exception: {e}" - return True, "OK" diff --git a/osm_lcm/odu_workflows.py b/osm_lcm/odu_workflows.py index a563f37..dac29d2 100644 --- a/osm_lcm/odu_workflows.py +++ b/osm_lcm/odu_workflows.py @@ -35,10 +35,8 @@ class OduWorkflow(LcmBase): # self._kubeconfig = kubeconfig # TODO: get it from config self.gitops_config = config["gitops"] self.logger.debug(f"Config: {self.gitops_config}") - self._kubeconfig = self.gitops_config["mgmtcluster_kubeconfig"] - self._odu_checkloop_kustomization_timeout = 900 - self._odu_checkloop_resource_timeout = 900 self._odu_checkloop_retry_time = 15 + self._kubeconfig = self.gitops_config["mgmtcluster_kubeconfig"] self._kubectl = kubectl.Kubectl(config_file=self._kubeconfig) self._repo_base_url = self.gitops_config["git_base_url"] self._repo_user = self.gitops_config["user"] @@ -49,93 +47,72 @@ class OduWorkflow(LcmBase): "create_cluster": { "workflow_function": self.create_cluster, "clean_function": self.clean_items_cluster_create, - "check_resource_function": self.check_create_cluster, }, "update_cluster": { "workflow_function": self.update_cluster, "clean_function": self.clean_items_cluster_update, - "check_resource_function": self.check_update_cluster, }, "delete_cluster": { "workflow_function": self.delete_cluster, - "check_resource_function": self.check_delete_cluster, }, "register_cluster": { "workflow_function": self.register_cluster, "clean_function": self.clean_items_cluster_register, - "check_resource_function": self.check_register_cluster, }, "deregister_cluster": { "workflow_function": self.deregister_cluster, - "check_resource_function": self.check_deregister_cluster, }, "create_profile": { "workflow_function": self.create_profile, - "check_resource_function": self.check_create_profile, }, "delete_profile": { "workflow_function": self.delete_profile, - "check_resource_function": self.check_delete_profile, }, "attach_profile_to_cluster": { "workflow_function": self.attach_profile_to_cluster, - "check_resource_function": self.check_attach_profile_to_cluster, }, "detach_profile_from_cluster": { "workflow_function": self.detach_profile_from_cluster, - "check_resource_function": self.check_detach_profile_from_cluster, }, "create_oka": { "workflow_function": self.create_oka, - "check_resource_function": self.check_create_oka, }, "update_oka": { "workflow_function": self.update_oka, - "check_resource_function": self.check_update_oka, }, "delete_oka": { "workflow_function": self.delete_oka, - "check_resource_function": self.check_delete_oka, }, "create_ksus": { "workflow_function": self.create_ksus, "clean_function": self.clean_items_ksu_create, - "check_resource_function": self.check_create_ksus, }, "update_ksus": { "workflow_function": self.update_ksus, "clean_function": self.clean_items_ksu_update, - "check_resource_function": self.check_update_ksus, }, "delete_ksus": { "workflow_function": self.delete_ksus, - "check_resource_function": self.check_delete_ksus, }, "clone_ksu": { "workflow_function": self.clone_ksu, - "check_resource_function": self.check_clone_ksu, }, "move_ksu": { "workflow_function": self.move_ksu, - "check_resource_function": self.check_move_ksu, }, "create_cloud_credentials": { "workflow_function": self.create_cloud_credentials, "clean_function": self.clean_items_cloud_credentials_create, - "check_resource_function": self.check_create_cloud_credentials, }, "update_cloud_credentials": { "workflow_function": self.update_cloud_credentials, "clean_function": self.clean_items_cloud_credentials_update, - "check_resource_function": self.check_update_cloud_credentials, }, "delete_cloud_credentials": { "workflow_function": self.delete_cloud_credentials, - "check_resource_function": self.check_delete_cloud_credentials, }, "dummy_operation": { "workflow_function": self.dummy_operation, - "check_resource_function": self.check_dummy_operation, }, } @@ -152,9 +129,6 @@ class OduWorkflow(LcmBase): delete_cloud_credentials, clean_items_cloud_credentials_create, clean_items_cloud_credentials_update, - check_create_cloud_credentials, - check_update_cloud_credentials, - check_delete_cloud_credentials, ) from osm_lcm.odu_libs.cluster_mgmt import ( create_cluster, @@ -165,11 +139,6 @@ class OduWorkflow(LcmBase): clean_items_cluster_create, clean_items_cluster_update, clean_items_cluster_register, - check_create_cluster, - check_update_cluster, - check_delete_cluster, - check_register_cluster, - check_deregister_cluster, get_cluster_credentials, ) from osm_lcm.odu_libs.ksu import ( @@ -180,34 +149,21 @@ class OduWorkflow(LcmBase): move_ksu, clean_items_ksu_create, clean_items_ksu_update, - check_create_ksus, - check_update_ksus, - check_delete_ksus, - check_clone_ksu, - check_move_ksu, ) from osm_lcm.odu_libs.oka import ( create_oka, update_oka, delete_oka, - check_create_oka, - check_update_oka, - check_delete_oka, ) from osm_lcm.odu_libs.profiles import ( create_profile, delete_profile, attach_profile_to_cluster, detach_profile_from_cluster, - check_create_profile, - check_delete_profile, - check_attach_profile_to_cluster, - check_detach_profile_from_cluster, ) from osm_lcm.odu_libs.workflows import ( check_workflow_status, readiness_loop, - common_check_list, ) from osm_lcm.odu_libs.render import ( render_jinja_template, @@ -239,18 +195,6 @@ class OduWorkflow(LcmBase): self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") return content["workflow_name"] - async def check_resource_status(self, key, op_id, op_params, content): - self.logger.info( - f"Check resource status. Key: {key}. Operation: {op_id}. Params: {op_params}. Content: {content}" - ) - check_resource_function = self._workflows[key]["check_resource_function"] - self.logger.info("check_resource function : {}".format(check_resource_function)) - return await check_resource_function(op_id, op_params, content) - - async def check_dummy_operation(self, op_id, op_params, content): - self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") - return True, "OK" - async def clean_items(self, items): # Delete secrets for secret in items.get("secrets", []):