X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fvim_sdn.py;h=b216c77272a7ed6c54559a70ee34597f8c60cf90;hb=50b414357839d03a84cc534a52726a98a36695bc;hp=6b1a338a43d7cc0a2c82b3a32e3439d1ddf5446d;hpb=edc5f33159d10a5d37c6b374c6c7a4f4d15b30b9;p=osm%2FLCM.git diff --git a/osm_lcm/vim_sdn.py b/osm_lcm/vim_sdn.py index 6b1a338..b216c77 100644 --- a/osm_lcm/vim_sdn.py +++ b/osm_lcm/vim_sdn.py @@ -60,7 +60,6 @@ class VimLcm(LcmBase): return vim_id = vim_content["_id"] - vim_content.pop("op_id", None) logging_text = "Task vim_create={} ".format(vim_id) self.logger.debug(logging_text + "Enter") @@ -182,7 +181,6 @@ class VimLcm(LcmBase): return vim_id = vim_content["_id"] - vim_content.pop("op_id", None) logging_text = "Task vim_edit={} ".format(vim_id) self.logger.debug(logging_text + "Enter") @@ -409,7 +407,6 @@ class WimLcm(LcmBase): self.lcm_tasks.lock_HA('wim', 'create', op_id) wim_id = wim_content["_id"] - wim_content.pop("op_id", None) logging_text = "Task wim_create={} ".format(wim_id) self.logger.debug(logging_text + "Enter") @@ -509,7 +506,6 @@ class WimLcm(LcmBase): return wim_id = wim_content["_id"] - wim_content.pop("op_id", None) logging_text = "Task wim_edit={} ".format(wim_id) self.logger.debug(logging_text + "Enter") @@ -712,7 +708,6 @@ class SdnLcm(LcmBase): self.lcm_tasks.lock_HA('sdn', 'create', op_id) sdn_id = sdn_content["_id"] - sdn_content.pop("op_id", None) logging_text = "Task sdn_create={} ".format(sdn_id) self.logger.debug(logging_text + "Enter") @@ -786,7 +781,6 @@ class SdnLcm(LcmBase): return sdn_id = sdn_content["_id"] - sdn_content.pop("op_id", None) logging_text = "Task sdn_edit={} ".format(sdn_id) self.logger.debug(logging_text + "Enter") @@ -965,7 +959,6 @@ class K8sClusterLcm(LcmBase): return k8scluster_id = k8scluster_content["_id"] - k8scluster_content.pop("op_id", None) logging_text = "Task k8scluster_create={} ".format(k8scluster_id) self.logger.debug(logging_text + "Enter") @@ -983,40 +976,47 @@ class K8sClusterLcm(LcmBase): schema_version=db_k8scluster["schema_version"], salt=db_k8scluster["_id"]) k8s_credentials = yaml.safe_dump(db_k8scluster.get("credentials")) error_text_list = [] + init_target = deep_get(db_k8scluster, ("_admin", "init")) # helm-chart - k8s_hc_id = None - try: - k8s_hc_id, uninstall_sw = await self.helm_k8scluster.init_env(k8s_credentials) - db_k8scluster_update["_admin.helm-chart.id"] = k8s_hc_id - db_k8scluster_update["_admin.helm-chart.created"] = uninstall_sw - except Exception as e: - error_text_list.append("Failing init helm-chart: {}".format(e)) - db_k8scluster_update["_admin.helm-chart.error_msg"] = str(e) - if isinstance(e, K8sException): - self.logger.error(logging_text + "Failing init helm-chart: {}".format(e)) - else: - self.logger.error(logging_text + "Failing init helm-chart: {}".format(e), exc_info=True) + if not init_target or "helm-chart" in init_target: + k8s_hc_id = None + try: + k8s_hc_id, uninstall_sw = await self.helm_k8scluster.init_env(k8s_credentials, + reuse_cluster_uuid=k8scluster_id) + db_k8scluster_update["_admin.helm-chart.id"] = k8s_hc_id + db_k8scluster_update["_admin.helm-chart.created"] = uninstall_sw + except Exception as e: + error_text_list.append("Failing init helm-chart: {}".format(e)) + db_k8scluster_update["_admin.helm-chart.error_msg"] = str(e) + if isinstance(e, K8sException): + self.logger.error(logging_text + "Failing init helm-chart: {}".format(e)) + else: + self.logger.error(logging_text + "Failing init helm-chart: {}".format(e), exc_info=True) - # Juju/k8s cluster - k8s_jb_id = None - try: - k8s_jb_id, uninstall_sw = await self.juju_k8scluster.init_env(k8s_credentials) - db_k8scluster_update["_admin.juju-bundle.id"] = k8s_jb_id - db_k8scluster_update["_admin.juju-bundle.created"] = uninstall_sw - except Exception as e: - error_text_list.append("Failing init juju-bundle: {}".format(e)) - db_k8scluster_update["_admin.juju-bundle.error_msg"] = str(e) - if isinstance(e, N2VCException): - self.logger.error(logging_text + "Failing init juju-bundle: {}".format(e)) - else: - self.logger.error(logging_text + "Failing init juju-bundle: {}".format(e), exc_info=True) + if not init_target or "juju-bundle" in init_target: + # Juju/k8s cluster + k8s_jb_id = None + try: + k8s_jb_id, uninstall_sw = await self.juju_k8scluster.init_env( + k8s_credentials, + reuse_cluster_uuid=k8scluster_id + ) + db_k8scluster_update["_admin.juju-bundle.id"] = k8s_jb_id + db_k8scluster_update["_admin.juju-bundle.created"] = uninstall_sw + except Exception as e: + error_text_list.append("Failing init juju-bundle: {}".format(e)) + db_k8scluster_update["_admin.juju-bundle.error_msg"] = str(e) + if isinstance(e, N2VCException): + self.logger.error(logging_text + "Failing init juju-bundle: {}".format(e)) + else: + self.logger.error(logging_text + "Failing init juju-bundle: {}".format(e), exc_info=True) # mark as an error if both helm-chart and juju-bundle have been failed if k8s_hc_id or k8s_jb_id: - self.logger.debug(logging_text + " successfully created") + self.logger.debug(logging_text + "successfully created") db_k8scluster_update["_admin.operationalState"] = "ENABLED" else: - self.logger.debug(logging_text + " successfully created with errors") + self.logger.debug(logging_text + "created with errors") db_k8scluster_update["_admin.operationalState"] = "ERROR" db_k8scluster_update["_admin.detailed-status"] = ";".join(error_text_list) @@ -1042,7 +1042,7 @@ class K8sClusterLcm(LcmBase): detailed_status=detailed_status_HA) except DbException as e: self.logger.error(logging_text + "Cannot update database: {}".format(e)) - self.lcm_tasks.remove("k8sclusters", k8scluster_id, order_id) + self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id) async def delete(self, k8scluster_content, order_id): @@ -1055,7 +1055,6 @@ class K8sClusterLcm(LcmBase): return k8scluster_id = k8scluster_content["_id"] - k8scluster_content.pop("op_id", None) logging_text = "Task k8scluster_delete={} ".format(k8scluster_id) self.logger.debug(logging_text + "Enter") @@ -1073,13 +1072,17 @@ class K8sClusterLcm(LcmBase): uninstall_sw = deep_get(db_k8scluster, ("_admin", "helm-chart", "created")) cluster_removed = True - if k8s_hc_id: + if k8s_jb_id: # delete in reverse order of creation + step = "Removing juju-bundle '{}'".format(k8s_jb_id) uninstall_sw = uninstall_sw or False - cluster_removed = await self.helm_k8scluster.reset(cluster_uuid=k8s_hc_id, uninstall_sw=uninstall_sw) + cluster_removed = await self.juju_k8scluster.reset(cluster_uuid=k8s_jb_id, uninstall_sw=uninstall_sw) + db_k8scluster_update["_admin.juju-bundle.id"] = None - if k8s_jb_id: + if k8s_hc_id: + step = "Removing helm-chart '{}'".format(k8s_hc_id) uninstall_sw = uninstall_sw or False - cluster_removed = await self.juju_k8scluster.reset(cluster_uuid=k8s_jb_id, uninstall_sw=uninstall_sw) + cluster_removed = await self.helm_k8scluster.reset(cluster_uuid=k8s_hc_id, uninstall_sw=uninstall_sw) + db_k8scluster_update["_admin.helm-chart.id"] = None # Try to remove from cluster_inserted to clean old versions if k8s_hc_id and cluster_removed: @@ -1093,14 +1096,15 @@ class K8sClusterLcm(LcmBase): self.update_db_2("k8srepos", k8srepo["_id"], {"_admin.cluster-inserted": cluster_list}) except Exception as e: self.logger.error("{}: {}".format(step, e)) - self.db.del_one("k8sclusters", {"_id": k8scluster_id}) - else: - raise LcmException("An error happened during the reset of the k8s cluster '{}'".format(k8scluster_id)) - # if not cluster_removed: - # raise Exception("K8scluster was not properly removed") + self.db.del_one("k8sclusters", {"_id": k8scluster_id}) + db_k8scluster_update = None + self.logger.debug(logging_text + "Done") except Exception as e: - self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True) + if isinstance(e, (LcmException, DbException, K8sException, N2VCException)): + self.logger.error(logging_text + "Exit Exception {}".format(e)) + else: + self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True) exc = e finally: if exc and db_k8scluster: @@ -1119,7 +1123,7 @@ class K8sClusterLcm(LcmBase): detailed_status=detailed_status_HA) except DbException as e: self.logger.error(logging_text + "Cannot update database: {}".format(e)) - self.lcm_tasks.remove("k8sclusters", k8scluster_id, order_id) + self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id) class K8sRepoLcm(LcmBase): @@ -1213,6 +1217,7 @@ class K8sRepoLcm(LcmBase): db_k8srepo = None db_k8srepo_update = {} + exc = None operationState_HA = '' detailed_status_HA = '' try: @@ -1238,6 +1243,7 @@ class K8sRepoLcm(LcmBase): self.lcm_tasks.register_HA('k8srepo', 'delete', op_id, operationState=operationState_HA, detailed_status=detailed_status_HA) + self.db.del_one("k8srepos", {"_id": k8srepo_id}) except DbException as e: self.logger.error(logging_text + "Cannot update database: {}".format(e)) self.lcm_tasks.remove("k8srepo", k8srepo_id, order_id)