self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}")
return True, "OK"
- async def common_check_list(self, checkings_list):
+ def update_operation_history(
+ self, content, workflow_status=None, resource_status=None
+ ):
+ self.logger.info(
+ f"Update Operation History in DB. Workflow status: {workflow_status}. Resource status: {resource_status}"
+ )
+ self.logger.debug(f"Content: {content}")
+
+ op_id = content["current_operation"]
+ self.logger.debug("OP_id: {}".format(op_id))
+ op_num = 0
+ for operation in content["operationHistory"]:
+ self.logger.debug("Operations: {}".format(operation))
+ if operation["op_id"] == op_id:
+ self.logger.debug("Found operation number: {}".format(op_num))
+ now = time()
+ if workflow_status:
+ content["operationHistory"][op_num]["workflowState"] = "COMPLETED"
+ content["operationHistory"][op_num]["result"] = True
+ else:
+ content["operationHistory"][op_num]["workflowState"] = "ERROR"
+ content["operationHistory"][op_num]["operationState"] = "FAILED"
+ content["operationHistory"][op_num]["result"] = False
+
+ if resource_status:
+ content["operationHistory"][op_num]["resourceState"] = "READY"
+ content["operationHistory"][op_num]["operationState"] = "COMPLETED"
+ content["operationHistory"][op_num]["result"] = True
+ else:
+ content["operationHistory"][op_num]["resourceState"] = "NOT_READY"
+ content["operationHistory"][op_num]["operationState"] = "FAILED"
+ content["operationHistory"][op_num]["result"] = False
+
+ content["operationHistory"][op_num]["endDate"] = now
+ break
+ op_num += 1
+ self.logger.debug("content: {}".format(content))
+
+ return content
+
+ async def common_check_list(self, checkings_list, db_collection, db_item):
try:
for checking in checkings_list:
if checking["enable"]:
)
if not status:
return status, message
+ else:
+ db_item["resourceState"] = checking["resourceState"]
+ db_item = self.update_operation_history(
+ db_item, "COMPLETED", checking["resourceState"]
+ )
+ self.db.set_one(db_collection, {"_id": db_item["_id"]}, db_item)
except Exception as e:
self.logger.debug(traceback.format_exc())
self.logger.debug(f"Exception: {e}", exc_info=True)
return
async def check_create_cluster(self, op_id, op_params, content):
- self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}")
+ self.logger.info(
+ f"check_create_cluster Operation {op_id}. Params: {op_params}."
+ )
+ # self.logger.debug(f"Content: {content}")
db_cluster = content["cluster"]
cluster_name = db_cluster["git_name"].lower()
cluster_kustomization_name = cluster_name
"flag": "Ready",
"timeout": self._checkloop_kustomization_timeout,
"enable": True,
+ "resourceState": "IN_PROGRESS.KUSTOMIZATION_READY",
},
{
"item": f"cluster_{cloud_type}",
"flag": "Synced",
"timeout": self._checkloop_resource_timeout,
"enable": True,
+ "resourceState": "IN_PROGRESS.RESOURCE_SYNCED.CLUSTER",
},
{
"item": f"cluster_{cloud_type}",
"flag": "Ready",
"timeout": self._checkloop_resource_timeout,
"enable": True,
+ "resourceState": "IN_PROGRESS.RESOURCE_READY.CLUSTER",
},
{
"item": "kustomization",
"flag": "Ready",
"timeout": self._checkloop_kustomization_timeout,
"enable": bootstrap,
+ "resourceState": "IN_PROGRESS.BOOTSTRAP_OK",
},
]
else:
"flag": "Ready",
"timeout": self._checkloop_resource_timeout,
"enable": True,
+ "resourceState": "IN_PROGRESS.RESOURCE_READY.NODEPOOL",
}
checkings_list.insert(3, nodepool_check)
- return await self.common_check_list(checkings_list)
+ return await self.common_check_list(checkings_list, "clusters", db_cluster)
def update_profile_state(self, db_cluster, workflow_status, resource_status):
profiles = [
return
async def check_deregister_cluster(self, op_id, op_params, content):
- self.logger.info("check_deregister_cluster Enter")
- self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}")
+ self.logger.info(
+ f"check_deregister_cluster Operation {op_id}. Params: {op_params}."
+ )
+ # self.logger.debug(f"Content: {content}")
# Clean secrets
self.logger.info("Cleaning kubeconfig")
cluster_name = content["cluster"]["git_name"].lower()
# except DbException as e:
# self.logger.error("Updating {} _id={} with '{}'. Error: {}".format(item, _id, _desc, e))
- def update_operation_history(
- self, content, workflow_status=None, resource_status=None
- ):
- self.logger.info("Update Operation History in LcmBase")
- self.logger.info(
- "Content: {} Workflow Status: {} Resource Status: {}".format(
- content, workflow_status, resource_status
- )
- )
-
- op_id = content["current_operation"]
- self.logger.debug("OP_id: {}".format(op_id))
- op_num = 0
- for operation in content["operationHistory"]:
- self.logger.debug("Operations: {}".format(operation))
- if operation["op_id"] == op_id:
- self.logger.debug("Found operation number: {}".format(op_num))
- now = time()
- if workflow_status:
- content["operationHistory"][op_num]["workflowState"] = "COMPLETED"
- content["operationHistory"][op_num]["result"] = True
- else:
- content["operationHistory"][op_num]["workflowState"] = "ERROR"
- content["operationHistory"][op_num]["operationState"] = "FAILED"
- content["operationHistory"][op_num]["result"] = False
-
- if resource_status:
- content["operationHistory"][op_num]["resourceState"] = "READY"
- content["operationHistory"][op_num]["operationState"] = "COMPLETED"
- content["operationHistory"][op_num]["result"] = True
- else:
- content["operationHistory"][op_num]["resourceState"] = "NOT_READY"
- content["operationHistory"][op_num]["operationState"] = "FAILED"
- content["operationHistory"][op_num]["result"] = False
-
- content["operationHistory"][op_num]["endDate"] = now
- break
- op_num += 1
- self.logger.debug("content: {}".format(content))
-
- return content
-
@staticmethod
def calculate_charm_hash(zipped_file):
"""Calculate the hash of charm files which ends with .charm