From 3424be62dc5fefe74a9b5fb9bd6dea57f373c301 Mon Sep 17 00:00:00 2001
From: Stefano Alberto Russo <stefano.russo@gmail.com>
Date: Thu, 7 Apr 2022 11:47:19 +0200
Subject: [PATCH] Fixes in error reporting and computing manager mappings.

---
 services/webapp/code/rosetta/core_app/api.py    |  2 +-
 services/webapp/code/rosetta/core_app/models.py | 10 ++++++++--
 services/webapp/code/rosetta/core_app/utils.py  |  6 +++---
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/services/webapp/code/rosetta/core_app/api.py b/services/webapp/code/rosetta/core_app/api.py
index 4953ac0..9a44798 100644
--- a/services/webapp/code/rosetta/core_app/api.py
+++ b/services/webapp/code/rosetta/core_app/api.py
@@ -441,7 +441,7 @@ class FileManagerAPI(PrivateGETAPI, PrivatePOSTAPI):
                 if computing.auth_mode == 'user_keys':
                     computing_user = user.profile.get_extra_conf('computing_user', storage.computing)
                     if not computing_user:
-                        raise Exception('Computing resource \'{}\' user is not configured'.format(storage.computing.name))
+                        raise ValueError('No \'computing_user\' parameter found for computing resource \'{}\' in user profile'.format(storage.computing.name))
                     base_path_expanded = base_path_expanded.replace('$SSH_USER', computing_user)
                 else:
                     base_path_expanded = base_path_expanded.replace('$SSH_USER', computing.conf.get('user'))
diff --git a/services/webapp/code/rosetta/core_app/models.py b/services/webapp/code/rosetta/core_app/models.py
index 291e663..4ea37b7 100644
--- a/services/webapp/code/rosetta/core_app/models.py
+++ b/services/webapp/code/rosetta/core_app/models.py
@@ -246,14 +246,20 @@ class Computing(models.Model):
         managers_mapping = {}
         managers_mapping['cluster'+'ssh+cli'+'user_keys'+'slurm'] = computing_managers.SlurmSSHClusterComputingManager
         managers_mapping['standalone'+'ssh+cli'+'user_keys'+'None'] = computing_managers.SSHStandaloneComputingManager
+        managers_mapping['standalone'+'ssh+cli'+'platform_keys'+'None'] = computing_managers.SSHStandaloneComputingManager        
         managers_mapping['standalone'+'internal'+'internal'+'None'] = computing_managers.InternalStandaloneComputingManager
         
         # Instantiate the computing manager and return (if not already done)
         try:
             return self._manager
         except AttributeError:
-            self._manager = managers_mapping[self.type+self.access_mode+self.auth_mode+str(self.wms)](self)
-            return self._manager
+            try:
+                self._manager = managers_mapping[self.type+self.access_mode+self.auth_mode+str(self.wms)](self)
+            except KeyError:
+                raise ValueError('No computing resource manager for type="{}", access_mode="{}", auth_mode="{}", wms="{}"'
+                                 .format(self.type, self.access_mode, self.auth_mode, self.wms)) from None
+            else:
+                return self._manager
 
     
 
diff --git a/services/webapp/code/rosetta/core_app/utils.py b/services/webapp/code/rosetta/core_app/utils.py
index 35021f1..16e3502 100644
--- a/services/webapp/code/rosetta/core_app/utils.py
+++ b/services/webapp/code/rosetta/core_app/utils.py
@@ -715,13 +715,13 @@ def get_ssh_access_mode_credentials(computing, user):
     except AttributeError:
         computing_host = None
     if not computing_host:
-        raise Exception('No computing host?!')
+        raise ValueError('No computing host?!')
             
     # Get computing user and keys
     if computing.auth_mode == 'user_keys':
         computing_user = user.profile.get_extra_conf('computing_user', computing)
         if not computing_user:
-            raise Exception('Computing resource \'{}\' user is not configured'.format(computing.name))
+            raise ValueError('No \'computing_user\' parameter found for computing resource \'{}\' in user profile'.format(computing.name))
         # Get user key
         computing_keys = KeyPair.objects.get(user=user, default=True)
     elif computing.auth_mode == 'platform_keys':        
@@ -730,7 +730,7 @@ def get_ssh_access_mode_credentials(computing, user):
     else:
         raise NotImplementedError('Auth modes other than user_keys and platform_keys not supported.')
     if not computing_user:
-        raise Exception('No computing user?!')
+            raise ValueError('No \'user\' parameter found for computing resource \'{}\' in its configuration'.format(computing.name))
     return (computing_user, computing_host, computing_keys)
 
 
-- 
GitLab