OpenSecurity/bin/cygwin.py
changeset 218 327f282364b9
parent 212 59ebaa44c12c
child 219 9480e5ba1a82
     1.1 --- a/OpenSecurity/bin/cygwin.py	Thu Jul 17 10:20:10 2014 +0100
     1.2 +++ b/OpenSecurity/bin/cygwin.py	Fri Aug 22 09:35:02 2014 +0100
     1.3 @@ -153,7 +153,7 @@
     1.4          result, res_stdout, res_stderr = None, None, None
     1.5          try:
     1.6              # quote the executable otherwise we run into troubles
     1.7 -            # when the path contains spaces and additonal arguments
     1.8 +            # when the path contains spaces and additional arguments
     1.9              # are presented as well.
    1.10              # special: invoking bash as login shell here with
    1.11              # an unquoted command does not execute /etc/profile
    1.12 @@ -166,14 +166,15 @@
    1.13              res_stdout, res_stderr = process.communicate()
    1.14              result = process.returncode
    1.15              logger.debug('Finished: ' + program + ' ' + ''.join(arguments))
    1.16 -            #result = process.wait()
    1.17 -            #res_stdout = process.stdout.read();
    1.18 -            #res_stderr = process.stderr.read();
    1.19  
    1.20          except Exception as ex:
    1.21              res_stderr = ''.join(str(ex.args))
    1.22              result = 1 
    1.23 -            
    1.24 +    
    1.25 +        if result != 0:
    1.26 +            logger.error('Command failed:' + ''.join(res_stderr))
    1.27 +            raise OpenSecurityException('Command failed:' + ''.join(res_stderr))
    1.28 +        
    1.29          return result, res_stdout, res_stderr
    1.30      
    1.31      @staticmethod
    1.32 @@ -182,12 +183,17 @@
    1.33          result = None
    1.34          while retry < try_count:
    1.35              if Cygwin.executeLock.acquire(True):
    1.36 -                result = Cygwin.execute(Cygwin.vbox_man, command, wait_return, window)
    1.37 -                Cygwin.executeLock.release()
    1.38 -                if result[0] == 0:
    1.39 +                try:
    1.40 +                    result = Cygwin.execute(Cygwin.vbox_man, command, wait_return, window)
    1.41 +                except Exception as ex:
    1.42 +                    Cygwin.executeLock.release()
    1.43 +                    if (retry+1) == try_count:
    1.44 +                        raise ex
    1.45 +                else:
    1.46 +                    Cygwin.executeLock.release()
    1.47                      return result
    1.48 -                retry+=1
    1.49 -        return result
    1.50 +            retry+=1
    1.51 +        raise OpenSecurityException('Command max retry reached: ' + ''.join(command))
    1.52  
    1.53  
    1.54      @staticmethod
    1.55 @@ -206,6 +212,8 @@
    1.56      # executes command over ssh on guest vm
    1.57      @staticmethod
    1.58      def sshExecute(command, address, user_name, certificate, wait_return=True, window = False):
    1.59 +        if command == None or address == None or user_name == None or certificate == None:
    1.60 +            raise OpenSecurityException('Invalid parameter value')
    1.61          command = ' -v -o StrictHostKeyChecking=no -i "' + certificate + '" ' + user_name + '@' + address + ' ' + command        
    1.62          return Cygwin.execute(Cygwin.cygwin_ssh, command, wait_return, window)
    1.63  
    1.64 @@ -248,9 +256,9 @@
    1.65      
    1.66      @staticmethod
    1.67      def checkResult(result):
    1.68 -        if result[0] != 0:
    1.69 -            logger.error('Command failed:' + ''.join(result[2]))
    1.70 -            raise OpenSecurityException('Command failed:' + ''.join(result[2]))
    1.71 +        #if result[0] != 0:
    1.72 +        #    logger.error('Command failed:' + ''.join(result[2]))
    1.73 +        #    raise OpenSecurityException('Command failed:' + ''.join(result[2]))
    1.74          return result
    1.75                  
    1.76  # start