From: yshah Date: Fri, 22 Nov 2024 12:08:57 +0000 (+0000) Subject: Update op_id in update_operation_history and check_kustomization_timeout in cluster... X-Git-Tag: v17.0.0~22 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=cb9075f358f16d59fdaf8abff928614971c1cb7d;p=osm%2FLCM.git Update op_id in update_operation_history and check_kustomization_timeout in cluster creation Change-Id: I75294abc040a8ee0ec4611c1969832399d2ac0d2 Signed-off-by: yshah --- diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 51e04aef..bef5d586 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -58,15 +58,13 @@ class GitOpsLcm(LcmBase): self.db.set_one(self.db_collection, {"_id": item_id}, db_item) def update_operation_history( - self, content, workflow_status=None, resource_status=None + self, content, op_id, workflow_status=None, resource_status=None ): self.logger.info( f"Update Operation History in DB. Workflow status: {workflow_status}. Resource status: {resource_status}" ) self.logger.debug(f"Content: {content}") - op_id = content["current_operation"] - self.logger.debug("OP_id: {}".format(op_id)) op_num = 0 for operation in content["operationHistory"]: self.logger.debug("Operations: {}".format(operation)) @@ -97,7 +95,7 @@ class GitOpsLcm(LcmBase): return content - async def common_check_list(self, checkings_list, db_collection, db_item): + async def common_check_list(self, op_id, checkings_list, db_collection, db_item): try: for checking in checkings_list: if checking["enable"]: @@ -113,7 +111,7 @@ class GitOpsLcm(LcmBase): else: db_item["resourceState"] = checking["resourceState"] db_item = self.update_operation_history( - db_item, "COMPLETED", checking["resourceState"] + db_item, op_id, "COMPLETED", checking["resourceState"] ) self.db.set_one(db_collection, {"_id": db_item["_id"]}, db_item) except Exception as e: @@ -206,7 +204,9 @@ class ClusterLcm(GitOpsLcm): db_cluster["state"] = "FAILED_CREATION" db_cluster["resourceState"] = "ERROR" # has to call update_operation_history return content - db_cluster = self.update_operation_history(db_cluster, workflow_status, None) + db_cluster = self.update_operation_history( + db_cluster, op_id, workflow_status, None + ) self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) # Clean items used in the workflow, no matter if the workflow succeeded @@ -233,7 +233,7 @@ class ClusterLcm(GitOpsLcm): db_cluster["operatingState"] = "IDLE" db_cluster = self.update_operation_history( - db_cluster, workflow_status, resource_status + db_cluster, op_id, workflow_status, resource_status ) db_cluster["current_operation"] = None self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) @@ -264,7 +264,7 @@ class ClusterLcm(GitOpsLcm): "name": cluster_kustomization_name, "namespace": "managed-resources", "flag": "Ready", - "timeout": self._checkloop_kustomization_timeout, + "timeout": 1500, "enable": True, "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY", }, @@ -291,7 +291,7 @@ class ClusterLcm(GitOpsLcm): "name": f"{cluster_kustomization_name}-bstrp-fluxctrl", "namespace": "managed-resources", "flag": "Ready", - "timeout": self._checkloop_kustomization_timeout, + "timeout": self._checkloop_resource_timeout, "enable": bootstrap, "resourceState": "IN_PROGRESS.BOOTSTRAP_OK", }, @@ -309,7 +309,9 @@ class ClusterLcm(GitOpsLcm): "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL", } checkings_list.insert(3, nodepool_check) - return await self.common_check_list(checkings_list, "clusters", db_cluster) + return await self.common_check_list( + op_id, checkings_list, "clusters", db_cluster + ) async def check_register_cluster(self, op_id, op_params, content): self.logger.info( @@ -331,7 +333,9 @@ class ClusterLcm(GitOpsLcm): "resourceState": "IN_PROGRESS.BOOTSTRAP_OK", }, ] - return await self.common_check_list(checkings_list, "clusters", db_cluster) + return await self.common_check_list( + op_id, checkings_list, "clusters", db_cluster + ) async def check_update_cluster(self, op_id, op_params, content): self.logger.info( @@ -392,7 +396,9 @@ class ClusterLcm(GitOpsLcm): "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL", } checkings_list.append(nodepool_check) - return await self.common_check_list(checkings_list, "clusters", db_cluster) + return await self.common_check_list( + op_id, checkings_list, "clusters", db_cluster + ) def update_profile_state(self, db_cluster, workflow_status, resource_status): profiles = [ @@ -414,13 +420,14 @@ class ClusterLcm(GitOpsLcm): self.logger.info("the db_collection is :{}".format(db_collection)) db_profile = self.db.get_one(db_collection, {"_id": profile_id}) self.logger.info("the db_profile is :{}".format(db_profile)) + op_id = db_profile["operationHistory"][-1].get("op_id") db_profile["state"] = db_cluster["state"] db_profile["resourceState"] = db_cluster["resourceState"] db_profile["operatingState"] = db_cluster["operatingState"] db_profile["age_pubkey"] = db_cluster["age_pubkey"] db_profile["age_privkey"] = db_profile["age_privkey"] db_profile = self.update_operation_history( - db_profile, workflow_status, resource_status + db_profile, op_id, workflow_status, resource_status ) self.logger.info("the db_profile is :{}".format(db_profile)) self.db.set_one(db_collection, {"_id": db_profile["_id"]}, db_profile) @@ -451,7 +458,9 @@ class ClusterLcm(GitOpsLcm): db_cluster["state"] = "FAILED_DELETION" db_cluster["resourceState"] = "ERROR" # has to call update_operation_history return content - db_cluster = self.update_operation_history(db_cluster, workflow_status, None) + db_cluster = self.update_operation_history( + db_cluster, op_id, workflow_status, None + ) self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) if workflow_status: @@ -470,7 +479,7 @@ class ClusterLcm(GitOpsLcm): db_cluster["operatingState"] = "IDLE" db_cluster = self.update_operation_history( - db_cluster, workflow_status, resource_status + db_cluster, op_id, workflow_status, resource_status ) db_cluster["current_operation"] = None self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) @@ -561,7 +570,9 @@ class ClusterLcm(GitOpsLcm): else: db_cluster["resourceState"] = "ERROR" # has to call update_operation_history return content - db_cluster = self.update_operation_history(db_cluster, workflow_status, None) + db_cluster = self.update_operation_history( + db_cluster, op_id, workflow_status, None + ) self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) if workflow_status: @@ -580,7 +591,7 @@ class ClusterLcm(GitOpsLcm): db_cluster["operatingState"] = "IDLE" db_cluster = self.update_operation_history( - db_cluster, workflow_status, resource_status + db_cluster, op_id, workflow_status, resource_status ) profile_list = db_cluster[profile_type] self.logger.info("profile list is : {}".format(profile_list)) @@ -625,7 +636,9 @@ class ClusterLcm(GitOpsLcm): else: db_cluster["resourceState"] = "ERROR" # has to call update_operation_history return content - db_cluster = self.update_operation_history(db_cluster, workflow_status, None) + db_cluster = self.update_operation_history( + db_cluster, op_id, workflow_status, None + ) self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) if workflow_status: @@ -644,7 +657,7 @@ class ClusterLcm(GitOpsLcm): db_cluster["operatingState"] = "IDLE" db_cluster = self.update_operation_history( - db_cluster, workflow_status, resource_status + db_cluster, op_id, workflow_status, resource_status ) profile_list = db_cluster[profile_type] self.logger.info("profile list is : {}".format(profile_list)) @@ -688,7 +701,9 @@ class ClusterLcm(GitOpsLcm): db_cluster["state"] = "FAILED_CREATION" db_cluster["resourceState"] = "ERROR" # has to call update_operation_history return content - db_cluster = self.update_operation_history(db_cluster, workflow_status, None) + db_cluster = self.update_operation_history( + db_cluster, op_id, workflow_status, None + ) self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) # Clean items used in the workflow, no matter if the workflow succeeded @@ -715,7 +730,7 @@ class ClusterLcm(GitOpsLcm): db_cluster["operatingState"] = "IDLE" db_cluster = self.update_operation_history( - db_cluster, workflow_status, resource_status + db_cluster, op_id, workflow_status, resource_status ) db_cluster["current_operation"] = None self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) @@ -747,7 +762,9 @@ class ClusterLcm(GitOpsLcm): db_cluster["state"] = "FAILED_DELETION" db_cluster["resourceState"] = "ERROR" # has to call update_operation_history return content - db_cluster = self.update_operation_history(db_cluster, workflow_status, None) + db_cluster = self.update_operation_history( + db_cluster, op_id, workflow_status, None + ) self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) # Clean items used in the workflow or in the cluster, no matter if the workflow succeeded @@ -774,7 +791,7 @@ class ClusterLcm(GitOpsLcm): db_cluster["operatingState"] = "IDLE" db_cluster = self.update_operation_history( - db_cluster, workflow_status, resource_status + db_cluster, op_id, workflow_status, resource_status ) db_cluster["current_operation"] = None self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) @@ -826,7 +843,9 @@ class ClusterLcm(GitOpsLcm): else: db_cluster["resourceState"] = "ERROR" - db_cluster = self.update_operation_history(db_cluster, workflow_status, None) + db_cluster = self.update_operation_history( + db_cluster, op_id, workflow_status, None + ) # self.logger.info("Db content: {}".format(db_content)) # self.db.set_one(self.db_collection, {"_id": _id}, db_cluster) self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster) @@ -854,7 +873,7 @@ class ClusterLcm(GitOpsLcm): db_cluster["resourceState"] = "ERROR" db_cluster = self.update_operation_history( - db_cluster, workflow_status, resource_status + db_cluster, op_id, workflow_status, resource_status ) db_cluster["operatingState"] = "IDLE" @@ -1013,7 +1032,7 @@ class K8sAppLcm(GitOpsLcm): content["state"] = "FAILED_CREATION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sapp", {"_id": content["_id"]}, content) if workflow_status: @@ -1032,7 +1051,7 @@ class K8sAppLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sapp", {"_id": content["_id"]}, content) @@ -1062,7 +1081,7 @@ class K8sAppLcm(GitOpsLcm): content["state"] = "FAILED_DELETION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sapp", {"_id": content["_id"]}, content) if workflow_status: @@ -1081,7 +1100,7 @@ class K8sAppLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sapp", {"_id": content["_id"]}, content) @@ -1124,7 +1143,7 @@ class K8sResourceLcm(GitOpsLcm): content["state"] = "FAILED_CREATION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sresource", {"_id": content["_id"]}, content) if workflow_status: @@ -1143,7 +1162,7 @@ class K8sResourceLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sresource", {"_id": content["_id"]}, content) @@ -1174,7 +1193,7 @@ class K8sResourceLcm(GitOpsLcm): content["state"] = "FAILED_DELETION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sresource", {"_id": content["_id"]}, content) if workflow_status: @@ -1193,7 +1212,7 @@ class K8sResourceLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sresource", {"_id": content["_id"]}, content) @@ -1236,7 +1255,7 @@ class K8sInfraControllerLcm(GitOpsLcm): content["state"] = "FAILED_CREATION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) if workflow_status: @@ -1255,7 +1274,7 @@ class K8sInfraControllerLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) @@ -1285,7 +1304,7 @@ class K8sInfraControllerLcm(GitOpsLcm): content["state"] = "FAILED_DELETION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) if workflow_status: @@ -1304,7 +1323,7 @@ class K8sInfraControllerLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sinfra_controller", {"_id": content["_id"]}, content) @@ -1347,7 +1366,7 @@ class K8sInfraConfigLcm(GitOpsLcm): content["state"] = "FAILED_CREATION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) if workflow_status: @@ -1366,7 +1385,7 @@ class K8sInfraConfigLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) @@ -1396,7 +1415,7 @@ class K8sInfraConfigLcm(GitOpsLcm): content["state"] = "FAILED_DELETION" content["resourceState"] = "ERROR" # has to call update_operation_history return content - content = self.update_operation_history(content, workflow_status, None) + content = self.update_operation_history(content, op_id, workflow_status, None) self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) resource_status, resource_msg = await self.check_resource_status( @@ -1414,7 +1433,7 @@ class K8sInfraConfigLcm(GitOpsLcm): content["operatingState"] = "IDLE" content = self.update_operation_history( - content, workflow_status, resource_status + content, op_id, workflow_status, resource_status ) content["current_operation"] = None self.db.set_one("k8sinfra_config", {"_id": content["_id"]}, content) @@ -1459,7 +1478,9 @@ class OkaLcm(GitOpsLcm): db_content["state"] = "FAILED_CREATION" db_content["resourceState"] = "ERROR" - db_content = self.update_operation_history(db_content, workflow_status, None) + db_content = self.update_operation_history( + db_content, op_id, workflow_status, None + ) self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: @@ -1479,7 +1500,7 @@ class OkaLcm(GitOpsLcm): # self.logger.info("Db content: {}".format(db_content)) db_content = self.update_operation_history( - db_content, workflow_status, resource_status + db_content, op_id, workflow_status, resource_status ) db_content["operatingState"] = "IDLE" @@ -1509,7 +1530,9 @@ class OkaLcm(GitOpsLcm): else: db_content["resourceState"] = "ERROR" - db_content = self.update_operation_history(db_content, workflow_status, None) + db_content = self.update_operation_history( + db_content, op_id, workflow_status, None + ) # self.logger.info("Db content: {}".format(db_content)) self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) @@ -1529,7 +1552,7 @@ class OkaLcm(GitOpsLcm): db_content["resourceState"] = "ERROR" db_content = self.update_operation_history( - db_content, workflow_status, resource_status + db_content, op_id, workflow_status, resource_status ) db_content["operatingState"] = "IDLE" @@ -1560,7 +1583,9 @@ class OkaLcm(GitOpsLcm): db_content["state"] = "FAILED_DELETION" db_content["resourceState"] = "ERROR" - db_content = self.update_operation_history(db_content, workflow_status, None) + db_content = self.update_operation_history( + db_content, op_id, workflow_status, None + ) self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: @@ -1579,7 +1604,7 @@ class OkaLcm(GitOpsLcm): db_content["resourceState"] = "ERROR" db_content = self.update_operation_history( - db_content, workflow_status, resource_status + db_content, op_id, workflow_status, resource_status ) db_content["operatingState"] = "IDLE" @@ -1625,7 +1650,7 @@ class KsuLcm(GitOpsLcm): db_ksu["state"] = "FAILED_CREATION" db_ksu["resourceState"] = "ERROR" - db_ksu = self.update_operation_history(db_ksu, workflow_status, None) + db_ksu = self.update_operation_history(db_ksu, op_id, workflow_status, None) self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) # Clean items used in the workflow, no matter if the workflow succeeded @@ -1653,7 +1678,7 @@ class KsuLcm(GitOpsLcm): db_ksu["resourceState"] = "ERROR" db_ksu = self.update_operation_history( - db_ksu, workflow_status, resource_status + db_ksu, op_id, workflow_status, resource_status ) for db_ksu in content: @@ -1684,7 +1709,7 @@ class KsuLcm(GitOpsLcm): else: db_ksu["resourceState"] = "ERROR" - db_ksu = self.update_operation_history(db_ksu, workflow_status, None) + db_ksu = self.update_operation_history(db_ksu, op_id, workflow_status, None) self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) # Clean items used in the workflow, no matter if the workflow succeeded @@ -1711,7 +1736,7 @@ class KsuLcm(GitOpsLcm): db_ksu["resourceState"] = "ERROR" db_ksu = self.update_operation_history( - db_ksu, workflow_status, resource_status + db_ksu, op_id, workflow_status, resource_status ) for db_ksu, ksu_params in zip(content, op_params): @@ -1752,7 +1777,7 @@ class KsuLcm(GitOpsLcm): db_ksu["state"] = "FAILED_DELETION" db_ksu["resourceState"] = "ERROR" - db_ksu = self.update_operation_history(db_ksu, workflow_status, None) + db_ksu = self.update_operation_history(db_ksu, op_id, workflow_status, None) self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) if workflow_status: @@ -1772,7 +1797,7 @@ class KsuLcm(GitOpsLcm): db_ksu["resourceState"] = "ERROR" db_ksu = self.update_operation_history( - db_ksu, workflow_status, resource_status + db_ksu, op_id, workflow_status, resource_status ) for db_ksu in content: @@ -1804,7 +1829,9 @@ class KsuLcm(GitOpsLcm): else: db_content["resourceState"] = "ERROR" - db_content = self.update_operation_history(db_content, workflow_status, None) + db_content = self.update_operation_history( + db_content, op_id, workflow_status, None + ) self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: @@ -1823,7 +1850,7 @@ class KsuLcm(GitOpsLcm): db_content["resourceState"] = "ERROR" db_content = self.update_operation_history( - db_content, workflow_status, resource_status + db_content, op_id, workflow_status, resource_status ) db_content["operatingState"] = "IDLE" @@ -1851,7 +1878,9 @@ class KsuLcm(GitOpsLcm): else: db_content["resourceState"] = "ERROR" - db_content = self.update_operation_history(db_content, workflow_status, None) + db_content = self.update_operation_history( + db_content, op_id, workflow_status, None + ) self.db.set_one(self.db_collection, {"_id": db_content["_id"]}, db_content) if workflow_status: @@ -1869,7 +1898,7 @@ class KsuLcm(GitOpsLcm): db_content["resourceState"] = "ERROR" db_content = self.update_operation_history( - db_content, workflow_status, resource_status + db_content, op_id, workflow_status, resource_status ) db_content["operatingState"] = "IDLE"