[v1] dts: clean up close in remote session
Checks
Commit Message
The close method was split into two methods, one with common code and
one that's subclass specific. There wasn't any common code so the split
doesn't make sense. And if we ever need such a split, we can use super()
in the future.
There was also an unused argument, force and the order of methods was
cleaned up a little (close is usually the last thing we call in the
lifecycle of a session object, so it was moved to the last place among
public methods).
Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
.../remote_session/remote_session.py | 21 ++++---------------
dts/framework/remote_session/ssh_session.py | 11 +++++-----
dts/framework/testbed_model/os_session.py | 12 ++++-------
3 files changed, 14 insertions(+), 30 deletions(-)
Comments
Makes perfect sense to me to just get rid of the unneeded method and
argument, and the new order also makes things more clear.
Reviewed-by: Jeremy Spewock <jspewock@iol.unh.edu>
Reviewed-by: Luca Vizzarro <luca.vizzarro@arm.com>
@@ -190,23 +190,6 @@ def _send_command(self, command: str, timeout: float, env: dict | None) -> Comma
* SSHTimeoutError if the command execution times out.
"""
- def close(self, force: bool = False) -> None:
- """Close the remote session and free all used resources.
-
- Args:
- force: Force the closure of the connection. This may not clean up all resources.
- """
- self._close(force)
-
- @abstractmethod
- def _close(self, force: bool = False) -> None:
- """Protocol specific steps needed to close the session properly.
-
- Args:
- force: Force the closure of the connection. This may not clean up all resources.
- This doesn't have to be implemented in the overloaded method.
- """
-
@abstractmethod
def is_alive(self) -> bool:
"""Check whether the remote session is still responding."""
@@ -242,3 +225,7 @@ def copy_to(
source_file: The file on the local filesystem.
destination_file: A file or directory path on the remote Node.
"""
+
+ @abstractmethod
+ def close(self) -> None:
+ """Close the remote session and free all used resources."""
@@ -74,10 +74,6 @@ def _connect(self) -> None:
else:
raise SSHConnectionError(self.hostname, errors)
- def is_alive(self) -> bool:
- """Overrides :meth:`~.remote_session.RemoteSession.is_alive`."""
- return self.session.is_connected
-
def _send_command(self, command: str, timeout: float, env: dict | None) -> CommandResult:
"""Send a command and return the result of the execution.
@@ -103,6 +99,10 @@ def _send_command(self, command: str, timeout: float, env: dict | None) -> Comma
return CommandResult(self.name, command, output.stdout, output.stderr, output.return_code)
+ def is_alive(self) -> bool:
+ """Overrides :meth:`~.remote_session.RemoteSession.is_alive`."""
+ return self.session.is_connected
+
def copy_from(
self,
source_file: str | PurePath,
@@ -119,5 +119,6 @@ def copy_to(
"""Overrides :meth:`~.remote_session.RemoteSession.copy_to`."""
self.session.put(str(source_file), str(destination_file))
- def _close(self, force: bool = False) -> None:
+ def close(self) -> None:
+ """Overrides :meth:`~.remote_session.RemoteSession.close`."""
self.session.close()
@@ -86,14 +86,6 @@ def __init__(
self.remote_session = create_remote_session(node_config, name, logger)
self.interactive_session = create_interactive_session(node_config, logger)
- def close(self, force: bool = False) -> None:
- """Close the underlying remote session.
-
- Args:
- force: Force the closure of the connection.
- """
- self.remote_session.close(force)
-
def is_alive(self) -> bool:
"""Check whether the underlying remote session is still responding."""
return self.remote_session.is_alive()
@@ -159,6 +151,10 @@ def create_interactive_shell(
timeout,
)
+ def close(self) -> None:
+ """Close the underlying remote session."""
+ self.remote_session.close()
+
@staticmethod
@abstractmethod
def _get_privileged_command(command: str) -> str: