From 9b23b5a3aaa1254ad3279b2bd8e35ca63307eda0 Mon Sep 17 00:00:00 2001 From: Elia Palme Date: Tue, 27 Feb 2024 13:54:19 +0100 Subject: [PATCH] Fixed SSH connection error catching. --- CHANGELOG.md | 1 + src/common/cscs_api_common.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da3a2e2d..7db3800c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed demo images dependency declarations preventing docker-compose to build successfully. - Fixed check when submitted an empty batch file on `POST /compute/jobs/upload` - Fixed error message when `GET /status/systems` encounters error in one filesystem +- Fixed SSH connection error catching ### Changed diff --git a/src/common/cscs_api_common.py b/src/common/cscs_api_common.py index 724ade74..28168b95 100644 --- a/src/common/cscs_api_common.py +++ b/src/common/cscs_api_common.py @@ -256,7 +256,11 @@ def get_username(header): return {"result": True, "reason":"", "username": decoded['preferred_username']} def in_str(stringval, substring): - return substring in stringval + if isinstance(stringval, str): + return substring in stringval + else: + return False + # SSH certificates creation # returns pub key certificate name @@ -958,7 +962,7 @@ def check_command_error(error_str, error_code, service_msg): header = {"X-Permission-Denied": "User does not have permissions to access path"} return {"description": service_msg, "error": error_str, "status_code": 400, "header": header} - if ("File exists" in error_str) and ("mkdir: cannot create directory" in error_str or "ln: failed to create symbolic link" in error_str): + if in_str(error_str,"File exists") and (in_str(error_str,"mkdir: cannot create directory") or in_str(error_str,"ln: failed to create symbolic link")): header = {"X-Exists": "targetPath already exists"} return {"description": service_msg, "error": error_str, "status_code": 400, "header": header}