Ejemplo n.º 1
0
def test_getScaledCPU(mocker, batch, requiredVariables, returnValue, expected):
    """ Test getScaledCPU()
  """
    mocker.patch(
        "DIRAC.Resources.Computing.BatchSystems.TimeLeft.TimeLeft.runCommand",
        return_value=S_OK(returnValue))
    tl = TimeLeft()
    res = tl.getScaledCPU()
    assert res == 0

    tl.scaleFactor = 5.0
    tl.normFactor = 5.0

    batchSystemName = '%sResourceUsage' % batch
    batchSystemPath = 'DIRAC.Resources.Computing.BatchSystems.TimeLeft.%s' % batchSystemName
    batchPlugin = __import__(batchSystemPath, globals(), locals(),
                             [batchSystemName])  # pylint: disable=unused-variable
    # Need to be reloaded to update the mock within the module, else, it will reuse the one when loaded the first time
    reload_module(batchPlugin)

    batchStr = 'batchPlugin.%s()' % (batchSystemName)
    tl.batchPlugin = eval(batchStr)

    # Update attributes of the batch systems to get scaled CPU
    tl.batchPlugin.__dict__.update(requiredVariables)

    res = tl.getScaledCPU()
    assert res == expected
Ejemplo n.º 2
0
def test_getTimeLeft(mocker, batch, requiredVariables, returnValue, expected_1,
                     expected_2):
    """Test getTimeLeft()"""
    mocker.patch(
        "DIRAC.Resources.Computing.BatchSystems.TimeLeft.TimeLeft.runCommand",
        return_value=S_OK(returnValue))
    tl = TimeLeft()

    batchSystemName = "%sResourceUsage" % batch
    batchSystemPath = "DIRAC.Resources.Computing.BatchSystems.TimeLeft.%s" % batchSystemName
    batchPlugin = __import__(batchSystemPath, globals(), locals(),
                             [batchSystemName])
    # Need to be reloaded to update the mock within the module, else, it will reuse the one when loaded the first time
    reload(batchPlugin)

    batchStr = "batchPlugin.%s()" % (batchSystemName)
    tl.batchPlugin = eval(batchStr)
    tl.cpuPower = 10.0

    # Update attributes of the batch systems to get scaled CPU
    tl.batchPlugin.__dict__.update(requiredVariables)

    res = tl.getTimeLeft()
    assert res["OK"] is expected_1
    if res["OK"]:
        assert res["Value"] == expected_2