예제 #1
0
    def test_getTimeLeft(self):
        #     for batch, retValue in [( 'LSF', LSF_ReturnValue ), ( 'SGE', SGE_ReturnValue )]:

        for batch, retValue in [('LSF', LSF_ReturnValue)]:
            self.tl = importlib.import_module(
                "DIRAC.Core.Utilities.TimeLeft.TimeLeft")
            rcMock = MagicMock()
            rcMock.return_value = S_OK(retValue)
            self.tl.runCommand = rcMock

            tl = TimeLeft()
            #      res = tl.getTimeLeft()
            #      self.assertEqual( res['OK'], True )

            batchSystemName = '%sTimeLeft' % batch
            batchPlugin = __import__(
                'DIRAC.Core.Utilities.TimeLeft.%s' % batchSystemName,
                globals(), locals(), [batchSystemName])
            batchStr = 'batchPlugin.%s()' % (batchSystemName)
            tl.batchPlugin = eval(batchStr)

            tl.scaleFactor = 10.0
            tl.normFactor = 10.0
            tl.batchPlugin.bin = '/usr/bin'
            tl.batchPlugin.hostNorm = 10.0
            tl.batchPlugin.cpuLimit = 1000
            tl.batchPlugin.wallClockLimit = 1000

            res = tl.getTimeLeft()
            self.assertEqual(res['OK'], True)

        for batch, retValue in [('SGE', SGE_ReturnValue)]:
            self.tl = importlib.import_module(
                "DIRAC.Core.Utilities.TimeLeft.TimeLeft")
            rcMock = MagicMock()
            rcMock.return_value = S_OK(retValue)
            self.tl.runCommand = rcMock

            tl = TimeLeft()
            #       res = tl.getTimeLeft()
            #       self.assertFalse( res['OK'] )

            batchSystemName = '%sTimeLeft' % batch
            batchPlugin = __import__(
                'DIRAC.Core.Utilities.TimeLeft.%s' % batchSystemName,
                globals(), locals(), [batchSystemName])
            batchStr = 'batchPlugin.%s()' % (batchSystemName)
            tl.batchPlugin = eval(batchStr)

            tl.scaleFactor = 10.0
            tl.normFactor = 10.0
            tl.batchPlugin.bin = '/usr/bin'
            tl.batchPlugin.hostNorm = 10.0
            tl.batchPlugin.cpuLimit = 1000
            tl.batchPlugin.wallClockLimit = 1000

            res = tl.getTimeLeft()
            self.assert_(res['OK'])
            self.assertEqual(res['Value'], 9400.0)
예제 #2
0
  def test_getTimeLeft( self ):
#     for batch, retValue in [( 'LSF', LSF_ReturnValue ), ( 'SGE', SGE_ReturnValue )]:

    for batch, retValue in [( 'LSF', LSF_ReturnValue )]:
      self.tl = importlib.import_module( "DIRAC.Core.Utilities.TimeLeft.TimeLeft" )
      rcMock = MagicMock()
      rcMock.return_value = S_OK( retValue )
      self.tl.runCommand = rcMock

      timeMock = MagicMock()

      tl = TimeLeft()
#      res = tl.getTimeLeft()
#      self.assertEqual( res['OK'], True )

      batchSystemName = '%sTimeLeft' % batch
      batchPlugin = __import__( 'DIRAC.Core.Utilities.TimeLeft.%s' %
                                batchSystemName, globals(), locals(), [batchSystemName] )
      batchStr = 'batchPlugin.%s()' % ( batchSystemName )
      tl.batchPlugin = eval( batchStr )

      tl.scaleFactor = 10.0
      tl.normFactor = 10.0
      tl.batchPlugin.bin = '/usr/bin'
      tl.batchPlugin.hostNorm = 10.0
      tl.batchPlugin.cpuLimit = 1000
      tl.batchPlugin.wallClockLimit = 1000

      with patch( "DIRAC.Core.Utilities.TimeLeft.LSFTimeLeft.runCommand", new=rcMock ):
        with patch( "DIRAC.Core.Utilities.TimeLeft.LSFTimeLeft.time", new=timeMock ):
          res = tl.getTimeLeft()
          self.assertEqual( res['OK'], True, res.get('Message', '') )

    for batch, retValue in [( 'SGE', SGE_ReturnValue )]:
      self.tl = importlib.import_module( "DIRAC.Core.Utilities.TimeLeft.TimeLeft" )
      rcMock = MagicMock()
      rcMock.return_value = S_OK( retValue )
      self.tl.runCommand = rcMock

      tl = TimeLeft()
#       res = tl.getTimeLeft()
#       self.assertFalse( res['OK'] )

      batchSystemName = '%sTimeLeft' % batch
      batchPlugin = __import__( 'DIRAC.Core.Utilities.TimeLeft.%s' %
                                batchSystemName, globals(), locals(), [batchSystemName] )
      batchStr = 'batchPlugin.%s()' % ( batchSystemName )
      tl.batchPlugin = eval( batchStr )

      tl.scaleFactor = 10.0
      tl.normFactor = 10.0
      tl.batchPlugin.bin = '/usr/bin'
      tl.batchPlugin.hostNorm = 10.0
      tl.batchPlugin.cpuLimit = 1000
      tl.batchPlugin.wallClockLimit = 1000

      res = tl.getTimeLeft()
      self.assert_( res['OK'] )
      self.assertEqual( res['Value'], 9400.0 )
예제 #3
0
  def test_getScaledCPU( self ):
    tl = TimeLeft()
    res = tl.getScaledCPU()
    self.assertEqual( res, 0 )

    tl.scaleFactor = 5.0
    tl.normFactor = 5.0

    for batch, retValue in [( 'LSF', LSF_ReturnValue )]:
      self.tl = importlib.import_module( "DIRAC.Core.Utilities.TimeLeft.TimeLeft" )
      rcMock = MagicMock()
      rcMock.return_value = S_OK( retValue )
      self.tl.runCommand = rcMock

      batchSystemName = '%sTimeLeft' % batch
      batchPlugin = __import__( 'DIRAC.Core.Utilities.TimeLeft.%s' %
                                batchSystemName, globals(), locals(), [batchSystemName] )
      batchStr = 'batchPlugin.%s()' % ( batchSystemName )
      tl.batchPlugin = eval( batchStr )
      res = tl.getScaledCPU()
      self.assertEqual( res, 0.0 )

    for batch, retValue in [( 'SGE', SGE_ReturnValue )]:
      self.tl = importlib.import_module( "DIRAC.Core.Utilities.TimeLeft.TimeLeft" )
      rcMock = MagicMock()
      rcMock.return_value = S_OK( retValue )
      self.tl.runCommand = rcMock

      batchSystemName = '%sTimeLeft' % batch
      batchPlugin = __import__( 'DIRAC.Core.Utilities.TimeLeft.%s' %
                                batchSystemName, globals(), locals(), [batchSystemName] )
      batchStr = 'batchPlugin.%s()' % ( batchSystemName )
      tl.batchPlugin = eval( batchStr )
      res = tl.getScaledCPU()
      self.assertEqual( res, 300.0 )
예제 #4
0
  def test_getScaledCPU( self ):
    tl = TimeLeft()
    res = tl.getScaledCPU()
    self.assertEqual( res, 0 )

    tl.scaleFactor = 5.0
    tl.normFactor = 5.0

    for batch, retValue in [( 'LSF', LSF_ReturnValue )]:
      self.tl = importlib.import_module( "DIRAC.Core.Utilities.TimeLeft.TimeLeft" )
      rcMock = MagicMock()
      rcMock.return_value = S_OK( retValue )
      self.tl.runCommand = rcMock

      batchSystemName = '%sTimeLeft' % batch
      batchPlugin = __import__( 'DIRAC.Core.Utilities.TimeLeft.%s' % #pylint: disable=unused-variable
                                batchSystemName, globals(), locals(), [batchSystemName] )
      batchStr = 'batchPlugin.%s()' % ( batchSystemName )
      tl.batchPlugin = eval( batchStr )
      res = tl.getScaledCPU()
      self.assertEqual( res, 0.0 )

    for batch, retValue in [( 'SGE', SGE_ReturnValue )]:
      self.tl = importlib.import_module( "DIRAC.Core.Utilities.TimeLeft.TimeLeft" )
      rcMock = MagicMock()
      rcMock.return_value = S_OK( retValue )
      self.tl.runCommand = rcMock

      batchSystemName = '%sTimeLeft' % batch
      batchPlugin = __import__( 'DIRAC.Core.Utilities.TimeLeft.%s' % #pylint: disable=unused-variable
                                batchSystemName, globals(), locals(), [batchSystemName] )
      batchStr = 'batchPlugin.%s()' % ( batchSystemName )
      tl.batchPlugin = eval( batchStr )
      res = tl.getScaledCPU()
      self.assertEqual( res, 300.0 )

      for batch, retValue in [( 'MJF', MJF_ReturnValue )]:
        self.tl = importlib.import_module( "DIRAC.Core.Utilities.TimeLeft.TimeLeft" )
        rcMock = MagicMock()
        rcMock.return_value = S_OK( retValue )
        self.tl.runCommand = rcMock

        batchSystemName = '%sTimeLeft' % batch
        batchPlugin = __import__( 'DIRAC.Core.Utilities.TimeLeft.%s' % #pylint: disable=unused-variable
                                  batchSystemName, globals(), locals(), [batchSystemName] )
        batchStr = 'batchPlugin.%s()' % ( batchSystemName )
        tl.batchPlugin = eval( batchStr )
        res = tl.getScaledCPU()
        self.assertEqual( res, 0.0 )