Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit ad5b755

Browse files
committed
driver-ssh: use lazy % formatting with logging
Change logging formatting to use %-formatting so that formatting is deferred until the log is printed [1]. [1] https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/logging-fstring-interpolation.html Signed-off-by: Albert Esteve <aesteve@redhat.com>
1 parent 330db34 commit ad5b755

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

  • packages/jumpstarter-driver-ssh/jumpstarter_driver_ssh

packages/jumpstarter-driver-ssh/jumpstarter_driver_ssh/client.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def run(self, direct, args) -> SSHCommandExecResult:
8585
port = parsed.port
8686
if not host or not port:
8787
raise ValueError(f"Invalid address format: {address}")
88-
self.logger.debug(f"Using direct TCP connection for SSH - host: {host}, port: {port}")
88+
self.logger.debug("Using direct TCP connection for SSH - host: %s, port: %s", host, port)
8989
return self._run_ssh_local(host, port, ssh_command, default_username, ssh_identity, args)
9090
except (DriverMethodNotImplemented, ValueError) as e:
91-
self.logger.error(f"Direct address connection failed ({e}), falling back to SSH port forwarding")
91+
self.logger.error("Direct address connection failed (%s), falling back to SSH port forwarding", e)
9292
return self.run(False, args)
9393
else:
9494
# Use SSH port forwarding (default behavior)
@@ -97,7 +97,7 @@ def run(self, direct, args) -> SSHCommandExecResult:
9797
client=self.tcp,
9898
) as addr:
9999
host, port = addr
100-
self.logger.debug(f"SSH port forward established - host: {host}, port: {port}")
100+
self.logger.debug("SSH port forward established - host: %s, port: %s", host, port)
101101
return self._run_ssh_local(host, port, ssh_command, default_username, ssh_identity, args)
102102

103103
def _run_ssh_local(self, host, port, ssh_command, default_username, ssh_identity, args):
@@ -113,9 +113,9 @@ def _run_ssh_local(self, host, port, ssh_command, default_username, ssh_identity
113113
# Set proper permissions (600) for SSH key
114114
os.chmod(temp_file.name, 0o600)
115115
identity_file = temp_file.name
116-
self.logger.debug(f"Created temporary identity file: {identity_file}")
116+
self.logger.debug("Created temporary identity file: %s", identity_file)
117117
except Exception as e:
118-
self.logger.error(f"Failed to create temporary identity file: {e}")
118+
self.logger.error("Failed to create temporary identity file: %s", e)
119119
if temp_file:
120120
try:
121121
os.unlink(temp_file.name)
@@ -140,9 +140,9 @@ def _run_ssh_local(self, host, port, ssh_command, default_username, ssh_identity
140140
if identity_file:
141141
try:
142142
os.unlink(identity_file)
143-
self.logger.debug(f"Cleaned up temporary identity file: {identity_file}")
143+
self.logger.debug("Cleaned up temporary identity file: %s", identity_file)
144144
except Exception as e:
145-
self.logger.warning(f"Failed to clean up temporary identity file {identity_file}: {e}")
145+
self.logger.warning("Failed to clean up temporary identity file %s: %s", identity_file, e)
146146

147147
def _build_ssh_command_args(self, ssh_command, port, default_username, identity_file, args):
148148
"""Build initial SSH command arguments"""
@@ -214,8 +214,8 @@ def _separate_ssh_options_and_command_args(self, args):
214214
i += 1
215215

216216
# Debug output
217-
self.logger.debug(f"SSH options: {ssh_options}")
218-
self.logger.debug(f"Command args: {command_args}")
217+
self.logger.debug("SSH options: %s", ssh_options)
218+
self.logger.debug("Command args: %s", command_args)
219219
return ssh_options, command_args
220220

221221

@@ -231,7 +231,7 @@ def _build_final_ssh_command(self, ssh_args, ssh_options, host, command_args):
231231
# Add command arguments
232232
ssh_args.extend(command_args)
233233

234-
self.logger.debug(f"Running SSH command: {ssh_args}")
234+
self.logger.debug("Running SSH command: %s", ssh_args)
235235
return ssh_args
236236

237237
def _execute_ssh_command(self, ssh_args) -> SSHCommandExecResult:
@@ -241,7 +241,8 @@ def _execute_ssh_command(self, ssh_args) -> SSHCommandExecResult:
241241
return SSHCommandExecResult.from_completed_process(result)
242242
except FileNotFoundError:
243243
self.logger.error(
244-
f"SSH command '{ssh_args[0]}' not found. Please ensure SSH is installed and available in PATH."
244+
"SSH command '%s' not found. Please ensure SSH is installed and available in PATH.",
245+
ssh_args[0],
245246
)
246247
return SSHCommandExecResult(
247248
return_code=127, # Standard exit code for "command not found"

0 commit comments

Comments
 (0)