@@ -894,19 +894,21 @@ def ping(self, verbose = 2, contimeout = None):
894894 return False
895895 return True
896896
897- def run_cmd (self , cmd , msg = None , timeout = None , die_on_error = True ):
898- ret = True
897+ def run_cmd (self , command , msg = None , timeout = None , die_on_error = True ):
898+ error = 0
899899 if self .use_ssh :
900900 ssh = self .get_ssh (self .verbose )
901901 else :
902902 tn = self .get_telnet (self .verbose )
903903 if (msg ):
904904 print (msg )
905- cmdlist = []
906- if isinstance (cmd , str ):
907- cmdlist .append (cmd )
905+ cmdlist = [ ]
906+ if isinstance (command , str ):
907+ cmdlist .append (command )
908908 else :
909- cmdlist = cmd
909+ cmdlist = command
910+ if not cmdlist :
911+ raise ValueError ('Incorrect command list' )
910912 for idx , cmd in enumerate (cmdlist ):
911913 if self .use_ssh :
912914 channel = ssh .open_session ()
@@ -920,7 +922,7 @@ def run_cmd(self, cmd, msg = None, timeout = None, die_on_error = True):
920922 channel .wait_eof ()
921923 except ssh2 .exceptions .Timeout :
922924 ssh .set_timeout (100 )
923- ret = False
925+ error = - 4
924926 if die_on_error :
925927 die ("SSH execute command timed out! CMD: \" {}\" " .format (cmd ))
926928 if timeout is not None :
@@ -931,16 +933,16 @@ def run_cmd(self, cmd, msg = None, timeout = None, die_on_error = True):
931933 except Exception :
932934 pass
933935 #status = channel.get_exit_status()
934- if not ret :
935- break
936- else :
936+ else : # telnet
937937 cmd += '\n '
938938 tn .write (cmd .encode ('ascii' ))
939939 tn .read_until (tn .prompt , timeout = 4 if timeout is None else timeout )
940+ if error != 0 :
941+ break
940942 if not self .use_ssh :
941943 tn .write (b"exit\n " )
942- ret = True
943- return ret
944+ tn . close ()
945+ return True if error == 0 else None
944946
945947 def download (self , fn_remote , fn_local , verbose = 1 ):
946948 if verbose and self .verbose :
@@ -1008,7 +1010,7 @@ def get_md5_for_remote_file(self, fn_remote, timeout = 8):
10081010 md5_remote_fn = f"/tmp/{ fname } .{ num } .md5"
10091011 cmd = f'md5sum "{ fn_remote } " > "{ md5_remote_fn } " 2>&1'
10101012 rc = self .run_cmd (cmd , timeout = timeout )
1011- if not rc :
1013+ if rc is None :
10121014 return - 5
10131015 os .remove (md5_local_fn ) if os .path .exists (md5_local_fn ) else None
10141016 self .download (md5_remote_fn , md5_local_fn , verbose = 0 )
0 commit comments