@@ -106,16 +106,13 @@ def missing_host_key(self, client, hostname, key):
106
106
def _can_connect (host : str , port : int = DEFAULT_SSH_PORT ) -> bool :
107
107
"""Check if the connection to the provided host and port is possible."""
108
108
try :
109
- import paramiko
110
-
111
109
logger .debug ("Testing connection to host %s" , host )
112
- client = paramiko .SSHClient ()
113
- client .load_system_host_keys ()
114
- client .set_missing_host_key_policy (CustomHostKeyPolicy ())
115
- client .connect (host , port = port )
116
- client .close ()
117
- logger .info ("Can connect to host %s" , host )
118
- return True
110
+ with paramiko .SSHClient () as client :
111
+ client .load_system_host_keys ()
112
+ client .set_missing_host_key_policy (CustomHostKeyPolicy ())
113
+ client .connect (host , port = port )
114
+ logger .info ("Can connect to host %s" , host )
115
+ return True
119
116
except Exception as e : # pylint: disable=W0703
120
117
logger .info ("Cannot connect to host %s" , host )
121
118
logger .debug (f"Connection failed with exception: { e } " )
@@ -211,9 +208,9 @@ def validate_smddpmprun() -> bool:
211
208
212
209
def write_env_vars_to_file ():
213
210
"""Write environment variables to /etc/environment file."""
214
- with open ("/etc/environment" , "a" ) as f :
211
+ with open ("/etc/environment" , "a" , encoding = "utf-8" ) as f :
215
212
for name in os .environ :
216
- f .write ("{ }={} \n " . format ( name , os .environ .get (name )) )
213
+ f .write (f" { name } ={ os .environ .get (name )} \n " )
217
214
218
215
219
216
def get_mpirun_command (
0 commit comments