From: Felipe Vicens Date: Wed, 5 Jun 2019 23:03:00 +0000 (+0200) Subject: Fix [Bug 675] User is able to delete NS instance before deleting NetworkSlice intance X-Git-Tag: v6.0.0~11 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F7620%2F2;p=osm%2FNBI.git Fix [Bug 675] User is able to delete NS instance before deleting NetworkSlice intance Change-Id: I232c449d363d014664ea187f46df190871c3b26f Signed-off-by: Felipe Vicens --- diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index 48503a9..100c9b4 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -763,6 +763,15 @@ class NsLcmOpTopic(BaseTopic): :param headers: http request headers :return: id of the nslcmops """ + def check_if_nsr_is_not_slice_member(session, nsr_id): + nsis = None + db_filter = self._get_project_filter(session) + db_filter["_admin.nsrs-detailed-list.ANYINDEX.nsrId"] = nsr_id + nsis = self.db.get_one("nsis", db_filter, fail_on_empty=False, fail_on_more=False) + if nsis: + raise EngineException("The NS instance {} cannot be terminate because is used by the slice {}".format( + nsr_id, nsis["_id"]), http_code=HTTPStatus.CONFLICT) + try: # Override descriptor with query string kwargs self._update_input_with_kwargs(indata, kwargs) @@ -776,6 +785,8 @@ class NsLcmOpTopic(BaseTopic): nsr = self.db.get_one("nsrs", _filter) # initial checking + if operation == "terminate" and slice_object is False: + check_if_nsr_is_not_slice_member(session, nsr["_id"]) if not nsr["_admin"].get("nsState") or nsr["_admin"]["nsState"] == "NOT_INSTANTIATED": if operation == "terminate" and indata.get("autoremove"): # NSR must be deleted