Updating current_operation and op_id to be relevant to operationHistory
Change-Id: I4c55cfe6ae874079315c04eb3ec52dfd05ac2fd8
Signed-off-by: yshah <shahithya.y@tataelxsi.co.in>
diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py
index dc656d5..db04559 100644
--- a/osm_nbi/base_topic.py
+++ b/osm_nbi/base_topic.py
@@ -435,6 +435,10 @@
operation["operationState"] = "IN_PROGRESS"
operation["gitOperationInfo"] = None
operation["operationParams"] = operation_params
+ else:
+ operation["workflowState"] = operation["resourceState"] = operation[
+ "operationState"
+ ] = operation["gitOperationInfo"] = operation["operationParams"] = None
content["operationHistory"].append(operation)
return op_id
diff --git a/osm_nbi/k8s_topics.py b/osm_nbi/k8s_topics.py
index b6e688c..7a65e31 100644
--- a/osm_nbi/k8s_topics.py
+++ b/osm_nbi/k8s_topics.py
@@ -18,7 +18,6 @@
import shutil
import os
from http import HTTPStatus
-from uuid import uuid4
from time import time
from osm_nbi.base_topic import BaseTopic, EngineException
@@ -468,11 +467,11 @@
else:
filter_db = self._get_project_filter(session)
filter_db[BaseTopic.id_field(self.topic, _id)] = _id
- op_id = str(uuid4())
operation_params = {}
data = self.db.get_one(self.topic, filter_db)
- data["current_operation"] = op_id
- self.format_on_operation(data, item, operation_params, launch_workflow=False)
+ op_id = self.format_on_operation(
+ data, item, operation_params, launch_workflow=False
+ )
self.db.set_one(self.topic, {"_id": data["_id"]}, data)
self._send_msg("get_creds", {"cluster_id": _id, "operation_id": op_id})
return op_id
@@ -531,14 +530,12 @@
filter_db = self._get_project_filter(session)
# To allow project&user addressing by name AS WELL AS _id
filter_db[BaseTopic.id_field(self.topic, _id)] = _id
- op_id = str(uuid4())
operation_params = {}
data = self.db.get_one(self.topic, filter_db)
- data["current_operation"] = op_id
data["operatingState"] = "PROCESSING"
data["resourceState"] = "IN_PROGRESS"
operation_params = indata
- self.format_on_operation(
+ op_id = self.format_on_operation(
data,
item,
operation_params,
@@ -722,7 +719,6 @@
def new(self, rollback, session, indata=None, kwargs=None, headers=None):
_id_list = []
- op_id = str(uuid4())
for ksus in indata["ksus"]:
content = ksus
oka = content["oka"][0]
@@ -765,7 +761,7 @@
self.format_on_new(
content, project_id=session["project_id"], make_public=session["public"]
)
- content["current_operation"] = op_id
+ content["current_operation"] = None
op_id = self.format_on_operation(
content,
operation_type="create",
@@ -841,7 +837,7 @@
# To allow project addressing by name AS WELL AS _id. Get the _id, just in case the provided one is a name
_id = content.get("_id") or _id
content["current_operation"] = None
- self.format_on_operation(
+ op_id = self.format_on_operation(
content,
"move",
operation_params,
@@ -853,8 +849,6 @@
content["resourceState"] = "IN_PROGRESS"
self.db.replace(self.topic, _id, content)
-
- op_id = content["current_operation"]
data = {"ksus_list": [content["_id"]], "operation_id": op_id}
self._send_msg("move", data)
return op_id
@@ -868,7 +862,7 @@
@staticmethod
def format_on_edit(final_content, edit_content):
- BaseTopic.format_on_operation(
+ op_id = BaseTopic.format_on_operation(
final_content,
"update",
edit_content,
@@ -878,27 +872,26 @@
if final_content.get("_admin"):
now = time()
final_content["_admin"]["modified"] = now
- return final_content["current_operation"]
+ return op_id
def edit(self, session, _id, indata, kwargs):
_id_list = []
- op_id = str(uuid4())
if _id == "update":
for ksus in indata["ksus"]:
content = ksus
_id = content["_id"]
_id_list.append(_id)
content.pop("_id")
- op_id = self.edit_ksu(session, _id, op_id, content, kwargs)
+ op_id = self.edit_ksu(session, _id, content, kwargs)
else:
content = indata
_id_list.append(_id)
- op_id = self.edit_ksu(session, _id, op_id, content, kwargs)
+ op_id = self.edit_ksu(session, _id, content, kwargs)
data = {"ksus_list": _id_list, "operation_id": op_id}
self._send_msg("edit", data)
- def edit_ksu(self, session, _id, op_id, indata, kwargs):
+ def edit_ksu(self, session, _id, indata, kwargs):
content = None
indata = self._remove_envelop(indata)
@@ -927,7 +920,6 @@
_id = content.get("_id") or _id
content = self.check_conflict_on_edit(session, content, indata, _id=_id)
- content["current_operation"] = op_id
op_id = self.format_on_edit(content, indata)
self.db.replace(self.topic, _id, content)
return op_id
@@ -936,23 +928,22 @@
def delete_ksu(self, session, _id, indata, dry_run=False, not_send_msg=None):
_id_list = []
- op_id = str(uuid4())
if _id == "delete":
for ksus in indata["ksus"]:
content = ksus
_id = content["_id"]
_id_list.append(_id)
content.pop("_id")
- op_id = self.delete(session, _id, op_id)
+ op_id = self.delete(session, _id)
else:
_id_list.append(_id)
- op_id = self.delete(session, _id, op_id)
+ op_id = self.delete(session, _id)
data = {"ksus_list": _id_list, "operation_id": op_id}
self._send_msg("delete", data)
return op_id
- def delete(self, session, _id, op_id):
+ def delete(self, session, _id):
if not self.multiproject:
filter_q = {}
else:
@@ -962,8 +953,7 @@
item_content["state"] = "IN_DELETION"
item_content["operatingState"] = "PROCESSING"
item_content["resourceState"] = "IN_PROGRESS"
- item_content["current_operation"] = op_id
- self.format_on_operation(
+ op_id = self.format_on_operation(
item_content,
"delete",
None,
@@ -1080,13 +1070,11 @@
item_content["state"] = "IN_DELETION"
item_content["operatingState"] = "PROCESSING"
self.check_conflict_on_del(session, _id, item_content)
- item_content["current_operation"] = None
- self.format_on_operation(
+ op_id = self.format_on_operation(
item_content,
"delete",
None,
)
- op_id = item_content["current_operation"]
self.db.set_one(self.topic, {"_id": item_content["_id"]}, item_content)
self._send_msg(
"delete", {"oka_id": _id, "operation_id": op_id}, not_send_msg=not_send_msg
@@ -1114,7 +1102,7 @@
content, session["project_id"], make_public=session["public"]
)
content["current_operation"] = None
- self.format_on_operation(
+ op_id = self.format_on_operation(
content,
operation_type="create",
operation_params=operation_params,
@@ -1122,7 +1110,7 @@
content["git_name"] = self.create_gitname(content, session)
_id = self.db.create(self.topic, content)
rollback.append({"topic": self.topic, "_id": _id})
- return _id, None
+ return _id, op_id
def upload_content(self, session, _id, indata, kwargs, headers):
current_desc = self.show(session, _id)
@@ -1249,9 +1237,10 @@
kwargs["package"] = filename
if headers["Method"] == "POST":
current_desc["state"] = "IN_CREATION"
+ op_id = current_desc["current_operation"]
elif headers["Method"] in ("PUT", "PATCH"):
current_desc["current_operation"] = None
- self.format_on_operation(
+ op_id = self.format_on_operation(
current_desc,
"update",
kwargs,
@@ -1267,7 +1256,6 @@
self.db.create(self.topic + "_revisions", revision_desc)
fs_rollback = []
- op_id = current_desc["current_operation"]
if headers["Method"] == "POST":
self._send_msg("create", {"oka_id": _id, "operation_id": op_id})
elif headers["Method"] == "PUT" or "PATCH":