def get_inspection_specification(inspection_id: str) -> Tuple[Dict[str, Any], int]: """Get specification for the given build.""" parameters = {"inspection_id": inspection_id} inspection_store = InspectionStore(inspection_id) inspection_store.connect() try: specification = inspection_store.retrieve_specification() except StorageNotFoundError: return {"error": f"No specification for inspection {inspection_id!r} found", "parameters": parameters,}, 404 return {"parameters": parameters, "specification": specification,}, 200
def get_inspection_build_log(inspection_id: str) -> Tuple[Dict[str, Any], int]: """Get build log of an inspection.""" parameters = {"inspection_id": inspection_id} inspection_store = InspectionStore(inspection_id) inspection_store.connect() try: log = inspection_store.build.retrieve_log() except StorageNotFoundError: return {"error": "Build log for the given inspection id was not found", "parameters": parameters}, 404 return {"log": log, "parameters": parameters}, 200
def get_inspection_job_batch_size(inspection_id: str) -> Tuple[Dict[str, Any], int]: """Get batch size for the given inspection.""" parameters = {"inspection_id": inspection_id} inspection_store = InspectionStore(inspection_id) inspection_store.connect() try: batch_size = inspection_store.results.get_results_count() except StorageNotFoundError: return {"error": f"No inspection {inspection_id!r} found", "parameters": parameters,}, 404 return {"batch_size": batch_size, "parameters": parameters}, 200
def get_inspection(page: Optional[int] = None, limit: Optional[int] = None) -> Dict[str, Any]: """Get listing of inspections available on Ceph.""" page = 1 if page is None or page <= 0 else page limit = _PAGE_LIMIT if limit is None or limit <= 0 or limit > _PAGE_LIMIT else limit return { "inspections": list(itertools.islice(InspectionStore.iter_inspections(), page - 1, limit)), "parameters": {"page": page, "limit": limit}, }
def get_inspection_job_result(inspection_id: str, item: int) -> Tuple[Dict[str, Any], int]: """Get logs of the given inspection.""" parameters = {"inspection_id": inspection_id} inspection_store = InspectionStore(inspection_id) inspection_store.connect() try: result = inspection_store.results.retrieve_result(item) except StorageNotFoundError: return ( { "error": f"No result for item {item!r} for inspection {inspection_id!r} or no " f"inspection {inspection_id!r} with item {item} found", "parameters": parameters, }, 404, ) return {"result": result, "parameters": parameters}, 200
def get_inspection_status(inspection_id: str) -> Tuple[Dict[str, Any], int]: """Get status of an inspection.""" parameters = {"inspection_id": inspection_id} inspection_store = InspectionStore(inspection_id) inspection_store.connect() data_stored = inspection_store.exists() workflow_status = None try: wf: Dict[str, Any] = _OPENSHIFT.get_workflow( label_selector=f"inspection_id={inspection_id}", namespace=_OPENSHIFT.amun_inspection_namespace, ) workflow_status = wf["status"] except NotFoundException: pass build_status = None try: # As we treat inspection_id same all over the places (dc, dc, job), we can # safely call gathering info about pod. There will be always only one build # (hopefully) - created per a user request. # OpenShift does not expose any endpoint for a build status anyway. build_status = _OPENSHIFT.get_pod_status_report( inspection_id + "-1-build", Configuration.AMUN_INSPECTION_NAMESPACE) except NotFoundException: pass return ( { "status": { "build": build_status, "data_stored": data_stored, "workflow": workflow_status }, "parameters": parameters, }, 200, )