Skip to content

Commit

Permalink
Remote client: Report connection status where it was missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Dec 12, 2024
1 parent 7318cca commit ba40e20
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions spyder/plugins/remoteclient/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ async def __start_remote_server(self):
"""Start remote server."""
if not self.ssh_is_connected:
self._logger.error("SSH connection is not open")
self.__emit_connection_status(
ConnectionStatus.Error,
_("The SSH connection is not open"),
)
return False

if info := await self.get_server_info():
Expand Down Expand Up @@ -391,7 +395,11 @@ async def __start_remote_server(self):
if info is None:
self._logger.error("Faield to get server info")
self.__emit_connection_status(
ConnectionStatus.Error, _("Error getting server info")
ConnectionStatus.Error,
_(
"There was an error when trying to get the remote server "
"information"
),
)
return False

Expand All @@ -410,7 +418,6 @@ async def __start_remote_server(self):
return True

self._logger.error("Error forwarding local port.")

self.__emit_connection_status(
ConnectionStatus.Error,
_("It was not possible to forward the local port"),
Expand All @@ -421,6 +428,10 @@ async def ensure_server_installed(self) -> bool:
"""Check remote server version."""
if not self.ssh_is_connected:
self._logger.error("SSH connection is not open")
self.__emit_connection_status(
ConnectionStatus.Error,
_("The SSH connection is not open"),
)
return ""

commnad = get_server_version_command(self.options["platform"])
Expand All @@ -435,6 +446,10 @@ async def ensure_server_installed(self) -> bool:
return await self.install_remote_server()
except asyncssh.TimeoutError:
self._logger.error("Checking server version timed out")
self.__emit_connection_status(
ConnectionStatus.Error,
_("The server version check timed out"),
)
return False

version = output.stdout.splitlines()[-1].strip()
Expand Down Expand Up @@ -483,6 +498,10 @@ async def __install_remote_server(self):
"""Install remote server."""
if not self.ssh_is_connected:
self._logger.error("SSH connection is not open")
self.__emit_connection_status(
ConnectionStatus.Error,
_("The SSH connection is not open"),
)
return False

self._logger.debug(
Expand All @@ -491,21 +510,33 @@ async def __install_remote_server(self):

try:
command = get_installer_command(self.options["platform"])
except NotImplementedError as e:
except NotImplementedError:
self._logger.error(
f"Cannot install spyder-remote-server on "
f"{self.options['platform']} automatically. Please install it "
f"manually."
)
self.__emit_connection_status(
status=ConnectionStatus.Error,
message=_("There was an error installing the remote server"),
)
return False

try:
await self._ssh_connection.run(command, check=True)
except asyncssh.ProcessError as err:
self._logger.error(f"Instalation script failed: {err.stderr}")
self._logger.error(f"Installation script failed: {err.stderr}")
self.__emit_connection_status(
status=ConnectionStatus.Error,
message=_("There was an error installing the remote server"),
)
return False
except asyncssh.TimeoutError:
self._logger.error("Instalation script timed out")
self._logger.error("Installation script timed out")
self.__emit_connection_status(
status=ConnectionStatus.Error,
message=_("There was an error installing the remote server"),
)
return False

self._logger.info(
Expand Down Expand Up @@ -567,7 +598,6 @@ async def __create_new_connection(self) -> bool:
)
except (OSError, asyncssh.Error) as e:
self._logger.error(f"Failed to open ssh connection: {e}")

self.__emit_connection_status(
ConnectionStatus.Error,
_("It was not possible to open a connection to this machine"),
Expand All @@ -582,10 +612,18 @@ async def forward_local_port(self):
"""Forward local port."""
if not self.server_port:
self._logger.error("Server port is not set")
self.__emit_connection_status(
status=ConnectionStatus.Error,
message=_("The server port is not set"),
)
return False

if not self.ssh_is_connected:
self._logger.error("SSH connection is not open")
self.__emit_connection_status(
status=ConnectionStatus.Error,
message=_("The SSH connection is not open"),
)
return False

self._logger.debug(
Expand Down Expand Up @@ -645,6 +683,10 @@ async def stop_remote_server(self):

if not self.ssh_is_connected:
self._logger.error("SSH connection is not open")
self.__emit_connection_status(
ConnectionStatus.Error,
_("The SSH connection is not open"),
)
return False

# bug in jupyterhub, need to send SIGINT twice
Expand Down

0 comments on commit ba40e20

Please sign in to comment.