From 5e10915ab41327d2b20b078f626b0ee5c3feb252 Mon Sep 17 00:00:00 2001 From: yshah Date: Mon, 19 May 2025 12:29:01 +0000 Subject: [PATCH] Fix OKA usage state while deleting cluster, profiles and KSU Change-Id: Iab717e3a72f12d5fd8d77c83ff18cd983e14c32b Signed-off-by: yshah --- osm_lcm/k8s.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 21df2b18..83f57e40 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -310,9 +310,39 @@ class GitOpsLcm(LcmBase): ) return content_copy + def delete_ksu_dependency(self, _id, data): + used_oka = [] + existing_oka = [] + + for oka_data in data["oka"]: + if oka_data.get("_id"): + used_oka.append(oka_data["_id"]) + + all_ksu_data = self.db.get_list("ksus", {}) + for ksu_data in all_ksu_data: + if ksu_data["_id"] != _id: + for oka_data in ksu_data["oka"]: + if oka_data.get("_id"): + if oka_data["_id"] not in existing_oka: + existing_oka.append(oka_data["_id"]) + + self.logger.info(f"Used OKA: {used_oka}") + self.logger.info(f"Existing OKA: {existing_oka}") + + for oka_id in used_oka: + if oka_id not in existing_oka: + self.db.set_one( + "okas", {"_id": oka_id}, {"_admin.usageState": "NOT_IN_USE"} + ) + + return + def delete_profile_ksu(self, _id, profile_type): filter_q = {"profile": {"_id": _id, "profile_type": profile_type}} ksu_list = self.db.get_list("ksus", filter_q) + for ksu_data in ksu_list: + self.delete_ksu_dependency(ksu_data["_id"], ksu_data) + if ksu_list: self.db.del_list("ksus", filter_q) return @@ -2216,6 +2246,7 @@ class KsuLcm(GitOpsLcm): if resource_status: db_ksu["state"] == "DELETED" + self.delete_ksu_dependency(db_ksu["_id"], db_ksu) self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) self.db.del_one(self.db_collection, {"_id": db_ksu["_id"]}) -- 2.25.1