コード例 #1
0
ファイル: CEBaseTest.py プロジェクト: besdiracgrid/BESDIRAC
  def __getJobOutput( self, jobID, vo ):
    status = self.dirac.status( jobID )
    if not status[ 'OK' ]:
      return status
    status = status[ 'Value' ][ jobID ][ 'Status' ]

    if status in ( 'Done', 'Failed' ):
      LOCK.acquire()
      proxyPath = BESUtils.getProxyByVO( 'zhangxm', vo )
      if not proxyPath[ 'OK' ]:
        LOCK.release()
        return proxyPath
      proxyPath = proxyPath[ 'Value' ]
      oldProxy = os.environ.get( 'X509_USER_PROXY' )
      os.environ[ 'X509_USER_PROXY' ] = proxyPath
      outputRes = self.dirac.getOutputSandbox( jobID, self.__logPath )
      if oldProxy is None:
        del os.environ[ 'X509_USER_PROXY' ]
      else:
        os.environ[ 'X509_USER_PROXY' ] = oldProxy
      LOCK.release()

      if not outputRes[ 'OK' ]:
        ret = S_OK( { 'Download'  : False, 'Log' : outputRes[ 'Message' ] } )
      else:
        try:
          logfile = open( '%s/%d/Script1_CodeOutput.log' % ( self.__logPath, jobID ), 'r' )
          log = logfile.read()
          logfile.close()
        except IOError, e:
          raise IOError
        os.system( 'rm -rf %s/%d' % ( self.__logPath, jobID ) )
        ret = S_OK( { 'Download' : True, 'Log' : log } )
コード例 #2
0
ファイル: CEBaseTest.py プロジェクト: besdiracgrid/BESDIRAC
  def __submit( self, site, CE, vo ):
    """
      set the job and submit.
    """

    job = Job()
    job.setName( self.testType )
    job.setJobGroup( 'CE-Test' )
    job.setExecutable( self.executable )
    job.setInputSandbox( '%s/%s' % ( self.__scriptPath, self.executable ) )
    if site and not CE:
      job.setDestination( site )
    if CE:
      job.setDestinationCE( CE )

    LOCK.acquire()
    proxyPath = BESUtils.getProxyByVO( 'zhangxm', vo )
    if not proxyPath[ 'OK' ]:
      LOCK.release()
      return proxyPath
    proxyPath = proxyPath[ 'Value' ]
    oldProxy = os.environ.get( 'X509_USER_PROXY' )
    os.environ[ 'X509_USER_PROXY' ] = proxyPath
    result = self.dirac.submit( job )
    if oldProxy is None:
      del os.environ[ 'X509_USER_PROXY' ]
    else:
      os.environ[ 'X509_USER_PROXY' ] = oldProxy
    LOCK.release()

    return result
コード例 #3
0
ファイル: SETest.py プロジェクト: besdiracgrid/BESDIRAC
  def doTest( self, elementDict ):
    """
      Test upload and download for specified SE.
    """

    elementName = elementDict[ 'ElementName' ]
    vo = elementDict[ 'VO' ]

    testFilePath = self.__localPath + self.__testFile
    if not os.path.exists( testFilePath ) or not os.path.isfile( testFilePath ):
      f = open( testFilePath, 'w' )
      f.write( 'hello' )
      f.close()

    status = 'OK'
    log = ''
    lfnPath = self.__lfnPath.format(vo=vo) + elementName + '-' + self.__testFile
    submissionTime = datetime.utcnow().replace( microsecond = 0 )

    proxyPath = BESUtils.getProxyByVO( 'zhangxm', vo )
    if not proxyPath[ 'OK' ]:
      gLogger.error('Can not get proxy for VO %s' % vo)
      return proxyPath
    proxyPath = proxyPath[ 'Value' ]

    env_test = os.environ.copy()
    env_test[ 'X509_USER_PROXY' ] = proxyPath
    cmd = [os.path.join(self.__scriptPath, self.__scriptName), '-o', '/DIRAC/Security/UseServerCertificate=no', lfnPath, testFilePath, elementName]
    result = systemCall(300, cmd, env=env_test)
    print result
    if not result['OK']:
      status = 'Bad'
      log += 'Call %s failed: %s' % (self.__scriptName, result['Message'])
    elif result['Value'][0] != 0:
      status = 'Bad'
      log += '%s exit with error %s:\n%s' % (self.__scriptName, result['Value'][0], result['Value'][1])
    else:
      log += '%s exit successfully:\n%s' % (self.__scriptName, result['Value'][1])

    completionTime = datetime.utcnow().replace( microsecond = 0 )
    applicationTime = ( completionTime - submissionTime ).total_seconds()

    result = { 'Result' : { 'Status' : status,
                            'Log' : log,
                            'SubmissionTime' : submissionTime,
                            'CompletionTime' : completionTime,
                            'ApplicationTime' : applicationTime },
               'Finish' : True }

#    if os.path.exists( testFilePath ) and os.path.isfile( testFilePath ):
#      os.remove( testFilePath )
    localFile = self.__localPath + elementName +'-' + self.__testFile
    if os.path.exists( localFile ) and os.path.isfile( localFile ):
      os.remove( localFile )

    return S_OK( result )