Manage situations where ODU workflows fail before it is launched (empty workflow_name)
Change-Id: I63a2113eee3626b6bc018519ca324b95ada1dc73
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py
index 744e5c0..445c3a2 100644
--- a/osm_lcm/k8s.py
+++ b/osm_lcm/k8s.py
@@ -98,7 +98,7 @@
self.logger.info("cluster Create Enter")
db_cluster = content["cluster"]
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_cluster", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -247,7 +247,7 @@
self.logger.info("cluster delete Enter")
db_cluster = content["cluster"]
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_cluster", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -358,7 +358,7 @@
self.logger.info("profile type is : {}".format(profile_type))
self.logger.info("profile id is : {}".format(profile_id))
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"attach_profile_to_cluster", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -421,7 +421,7 @@
self.logger.info("profile type is : {}".format(profile_type))
self.logger.info("profile id is : {}".format(profile_id))
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"detach_profile_from_cluster", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -479,7 +479,7 @@
self.logger.info("cluster register enter")
db_cluster = content["cluster"]
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"register_cluster", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -538,7 +538,7 @@
self.logger.info("db_cluster is : {}".format(db_cluster))
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"deregister_cluster", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -625,7 +625,7 @@
self.logger.info("Cluster update Enter")
db_cluster = content["cluster"]
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"update_cluster", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -699,7 +699,7 @@
async def add(self, op_id, op_params, content):
self.logger.info("Cloud Credentials create")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_cloud_credentials", op_id, op_params, content
)
@@ -739,7 +739,7 @@
return
async def edit(self, op_id, op_params, content):
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"update_cloud_credentials", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -770,7 +770,7 @@
async def remove(self, op_id, op_params, content):
self.logger.info("Cloud Credentials delete")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_cloud_credentials", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -805,7 +805,7 @@
async def create(self, op_id, op_params, content):
self.logger.info("App Create Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -853,7 +853,7 @@
async def delete(self, op_id, op_params, content):
self.logger.info("App delete Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -914,7 +914,7 @@
async def create(self, op_id, op_params, content):
self.logger.info("Resource Create Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -963,7 +963,7 @@
self.logger.info("Resource delete Enter")
content = self.db.get_one("k8sresource", {"_id": content["_id"]})
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1024,7 +1024,7 @@
async def create(self, op_id, op_params, content):
self.logger.info("Infra controller Create Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1072,7 +1072,7 @@
async def delete(self, op_id, op_params, content):
self.logger.info("Infra controller delete Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1133,7 +1133,7 @@
async def create(self, op_id, op_params, content):
self.logger.info("Infra config Create Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1181,7 +1181,7 @@
async def delete(self, op_id, op_params, content):
self.logger.info("Infra config delete Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_profile", op_id, op_params, content
)
self.logger.info("workflow_name is :{}".format(workflow_name))
@@ -1244,7 +1244,7 @@
self.logger.info("OKA Create Enter")
db_content = content
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_oka", op_id, op_params, db_content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1295,7 +1295,7 @@
self.logger.info("OKA Edit Enter")
db_content = content
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"update_oka", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1343,7 +1343,7 @@
self.logger.info("OKA delete Enter")
db_content = content
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_oka", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1406,7 +1406,7 @@
async def create(self, op_id, op_params, content):
self.logger.info("ksu Create Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"create_ksus", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1466,7 +1466,7 @@
async def edit(self, op_id, op_params, content):
self.logger.info("ksu edit Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"update_ksus", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1531,7 +1531,7 @@
async def delete(self, op_id, op_params, content):
self.logger.info("ksu delete Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"delete_ksus", op_id, op_params, content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1585,7 +1585,7 @@
async def clone(self, op_id, op_params, db_content):
self.logger.info("ksu clone Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"clone_ksus", op_id, op_params, db_content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
@@ -1631,7 +1631,7 @@
async def move(self, op_id, op_params, db_content):
self.logger.info("ksu move Enter")
- workflow_name = await self.odu.launch_workflow(
+ _, workflow_name = await self.odu.launch_workflow(
"move_ksus", op_id, op_params, db_content
)
workflow_status, workflow_msg = await self.odu.check_workflow_status(
diff --git a/osm_lcm/odu_libs/cluster_mgmt.py b/osm_lcm/odu_libs/cluster_mgmt.py
index 81d85ec..4c24b96 100644
--- a/osm_lcm/odu_libs/cluster_mgmt.py
+++ b/osm_lcm/odu_libs/cluster_mgmt.py
@@ -62,12 +62,16 @@
secret_namespace = "osm-workflows"
secret_key = "agekey"
secret_value = private_key_new_cluster
- await self.create_secret(
- secret_name,
- secret_namespace,
- secret_key,
- secret_value,
- )
+ try:
+ await self.create_secret(
+ secret_name,
+ secret_namespace,
+ secret_key,
+ secret_value,
+ )
+ except Exception as e:
+ self.logger.info(f"Cannot create secret {secret_name}: {e}")
+ return False, ""
# Additional params for the workflow
cluster_kustomization_name = cluster_name
@@ -131,7 +135,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def update_cluster(self, op_id, op_params, content):
@@ -156,12 +160,16 @@
secret_namespace = "osm-workflows"
secret_key = "agekey"
secret_value = private_key_cluster
- await self.create_secret(
- secret_name,
- secret_namespace,
- secret_key,
- secret_value,
- )
+ try:
+ await self.create_secret(
+ secret_name,
+ secret_namespace,
+ secret_key,
+ secret_value,
+ )
+ except Exception as e:
+ self.logger.info(f"Cannot create secret {secret_name}: {e}")
+ return False, ""
# Additional params for the workflow
cluster_kustomization_name = cluster_name
@@ -213,7 +221,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def delete_cluster(self, op_id, op_params, content):
@@ -254,7 +262,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def register_cluster(self, op_id, op_params, content):
@@ -277,12 +285,18 @@
secret_namespace = "osm-workflows"
secret_key = "agekey"
secret_value = private_key_new_cluster
- await self.create_secret(
- secret_name,
- secret_namespace,
- secret_key,
- secret_value,
- )
+ try:
+ await self.create_secret(
+ secret_name,
+ secret_namespace,
+ secret_key,
+ secret_value,
+ )
+ except Exception as e:
+ self.logger.info(
+ f"Cannot create secret {secret_name} in namespace {secret_namespace}: {e}"
+ )
+ return False, ""
# Create secret with kubeconfig
secret_name2 = f"kubeconfig-{cluster_name}"
@@ -327,7 +341,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def deregister_cluster(self, op_id, op_params, content):
@@ -367,7 +381,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def get_cluster_credentials(self, db_cluster):
diff --git a/osm_lcm/odu_libs/ksu.py b/osm_lcm/odu_libs/ksu.py
index 188da8f..7f4d699 100644
--- a/osm_lcm/odu_libs/ksu.py
+++ b/osm_lcm/odu_libs/ksu.py
@@ -163,7 +163,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def update_ksus(self, op_id, op_params_list, content_list):
@@ -300,7 +300,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def delete_ksus(self, op_id, op_params_list, content_list):
@@ -346,21 +346,21 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def clone_ksu(self, op_id, op_params, content):
self.logger.info(f"clone_ksu Enter. Operation {op_id}. Params: {op_params}")
# self.logger.debug(f"Content: {content}")
workflow_name = f"clone-ksu-{content['_id']}"
- return workflow_name
+ return True, workflow_name
async def move_ksu(self, op_id, op_params, content):
self.logger.info(f"move_ksu Enter. Operation {op_id}. Params: {op_params}")
# self.logger.debug(f"Content: {content}")
workflow_name = f"move-ksu-{content['_id']}"
- return workflow_name
+ return True, workflow_name
async def clean_items_ksu_create(self, op_id, op_params_list, content_list):
diff --git a/osm_lcm/odu_libs/oka.py b/osm_lcm/odu_libs/oka.py
index c9205ed..62207a3 100644
--- a/osm_lcm/odu_libs/oka.py
+++ b/osm_lcm/odu_libs/oka.py
@@ -75,7 +75,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def update_oka(self, op_id, op_params, content):
@@ -131,7 +131,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def delete_oka(self, op_id, op_params, content):
@@ -169,4 +169,4 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
diff --git a/osm_lcm/odu_libs/profiles.py b/osm_lcm/odu_libs/profiles.py
index 323250e..782d056 100644
--- a/osm_lcm/odu_libs/profiles.py
+++ b/osm_lcm/odu_libs/profiles.py
@@ -54,7 +54,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def delete_profile(self, op_id, op_params, content):
@@ -92,7 +92,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def attach_profile_to_cluster(self, op_id, op_params, content):
@@ -136,7 +136,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def detach_profile_from_cluster(self, op_id, op_params, content):
@@ -181,4 +181,4 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
diff --git a/osm_lcm/odu_libs/vim_mgmt.py b/osm_lcm/odu_libs/vim_mgmt.py
index edb16ab..5569f89 100644
--- a/osm_lcm/odu_libs/vim_mgmt.py
+++ b/osm_lcm/odu_libs/vim_mgmt.py
@@ -93,7 +93,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def delete_cloud_credentials(self, op_id, op_params, content):
@@ -136,7 +136,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def update_cloud_credentials(self, op_id, op_params, content):
@@ -207,7 +207,7 @@
api_plural="workflows",
api_version="v1alpha1",
)
- return workflow_name
+ return True, workflow_name
async def clean_items_cloud_credentials_create(self, op_id, op_params, content):
diff --git a/osm_lcm/odu_libs/workflows.py b/osm_lcm/odu_libs/workflows.py
index f3b9295..094aa9e 100644
--- a/osm_lcm/odu_libs/workflows.py
+++ b/osm_lcm/odu_libs/workflows.py
@@ -23,6 +23,8 @@
async def check_workflow_status(self, workflow_name):
self.logger.info(f"check_workflow_status Enter: {workflow_name}")
+ if not workflow_name:
+ return False, "Workflow was not launched"
try:
return await self.readiness_loop(
item="workflow",