Exemplo n.º 1
0
def test__requestProxyFromProxyManager(mocker, mockGCReply, mockPMReply,
                                       expected):
    """Testing JobAgent()._requestProxyFromProxyManager()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule")
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.gConfig.getValue",
        return_value=mockGCReply)
    module_str = "DIRAC.WorkloadManagementSystem.Agent.JobAgent.gProxyManager.getPayloadProxyFromDIRACGroup"
    mocker.patch(module_str, return_value=mockPMReply)

    jobAgent = JobAgent("Test", "Test1")

    ownerDN = "DIRAC"
    ownerGroup = "DIRAC"

    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    result = jobAgent._requestProxyFromProxyManager(ownerDN, ownerGroup)

    assert result["OK"] == expected["OK"]

    if result["OK"]:
        assert result["Value"] == expected["Value"]

    else:
        assert result["Message"] == expected["Message"]
Exemplo n.º 2
0
def test__requestProxyFromProxyManager(mocker, mockGCReplyInput,
                                       mockPMReplyInput, expected):
    """ Testing JobAgent()._requestProxyFromProxyManager()
  """

    mockGCReply.return_value = mockGCReplyInput
    mockPMReply.return_value = mockPMReplyInput

    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule",
                 side_effect=mockAM)
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.gConfig.getValue",
        side_effect=mockGCReply)
    module_str = "DIRAC.WorkloadManagementSystem.Agent.JobAgent.gProxyManager.getPayloadProxyFromDIRACGroup"
    mocker.patch(module_str, side_effect=mockPMReply)

    jobAgent = JobAgent('Test', 'Test1')

    ownerDN = 'DIRAC'
    ownerGroup = 'DIRAC'

    jobAgent.log = gLogger
    jobAgent.log.setLevel('DEBUG')

    result = jobAgent._requestProxyFromProxyManager(ownerDN, ownerGroup)

    assert result['OK'] == expected['OK']

    if result['OK']:
        assert result['Value'] == expected['Value']

    else:
        assert result['Message'] == expected['Message']
Exemplo n.º 3
0
def test_submitJob(mocker, mockJWInput, expected):
    """ Testing JobAgent()._submitJob()
  """

    mockJW.return_value = mockJWInput

    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.am_getOption",
        side_effect=mockAM)
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.createJobWrapper",
        side_effect=mockJW)

    jobAgent = JobAgent('Test', 'Test1')
    jobAgent.log = gLogger
    jobAgent.log.setLevel('DEBUG')
    jobAgent.ceName = 'Test'

    result = jobAgent._submitJob(101, {}, {}, {}, {}, {})

    assert result['OK'] == expected['OK']

    if not result['OK']:
        assert result['Message'] == expected['Message']
Exemplo n.º 4
0
def test__getJDLParameters(mocker):
    """ Testing JobAgent()._getJDLParameters()
  """

    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")

    jobAgent = JobAgent('Test', 'Test1')
    jobAgent.log = gLogger
    jobAgent.log.setLevel('DEBUG')

    jdl = """
        [
            Origin = "DIRAC";
            Executable = "$DIRACROOT/scripts/dirac-jobexec";
            StdError = "std.err";
            LogLevel = "info";
            Site = "ANY";
            JobName = "helloWorld";
            Priority = "1";
            InputSandbox =
                {
                    "../../Integration/WorkloadManagementSystem/exe-script.py",
                    "exe-script.py",
                    "/tmp/tmpMQEink/jobDescription.xml",
                    "SB:FedericoSandboxSE|/SandBox/f/fstagni.lhcb_user/0c2/9f5/0c29f53a47d051742346b744c793d4d0.tar.bz2"
                };
            Arguments = "jobDescription.xml -o LogLevel=info";
            JobGroup = "lhcb";
            OutputSandbox =
                {
                    "helloWorld.log",
                    "std.err",
                    "std.out"
                };
            StdOutput = "std.out";
            InputData = "";
            JobType = "User";
            NumberOfProcessors = 16;
            Tags =
                {
                    "16Processors",
                    "MultiProcessor"
                };
        ]
        """

    result = jobAgent._getJDLParameters(jdl)

    assert result['OK']
    assert result['Value']['Origin'] == 'DIRAC'
    assert result['Value']['NumberOfProcessors'] == '16'
    assert result['Value']['Tags'] == ['16Processors', 'MultiProcessor']
Exemplo n.º 5
0
def test__getCPUTimeLeft(mocker):
  """ Testing JobAgent()._getCPUTimeLeft()
  """

  mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
  mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule", side_effect=mockAM)

  jobAgent = JobAgent('Test', 'Test1')
  jobAgent.log = gLogger
  jobAgent.log.setLevel('DEBUG')

  result = jobAgent._getCPUTimeLeft()

  assert 0 == result
Exemplo n.º 6
0
def test__checkInstallSoftware(mocker):
  """ Testing JobAgent()._checkInstallSoftware()
  """

  mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")

  jobAgent = JobAgent('Test', 'Test1')
  jobAgent.log = gLogger
  jobAgent.log.setLevel('DEBUG')

  result = jobAgent._checkInstallSoftware(101, {}, {})

  assert result['OK']
  assert result['Value'] == 'Job has no software installation requirement'
Exemplo n.º 7
0
def test__checkInstallSoftware(mocker):
    """Testing JobAgent()._checkInstallSoftware()"""

    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    result = jobAgent._checkInstallSoftware(101, {}, {}, JobReport(123))

    assert result["OK"], result["Message"]
    assert result["Value"] == "Job has no software installation requirement"
Exemplo n.º 8
0
def test__rescheduleFailedJob(mocker, mockJMInput, expected):
    """Testing JobAgent()._rescheduleFailedJob()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    jobAgent = JobAgent("Test", "Test1")

    jobID = 101
    message = "Test"

    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    result = jobAgent._rescheduleFailedJob(jobID, message)
    result = jobAgent._finish(result["Message"], False)

    assert result == expected
Exemplo n.º 9
0
def test__checkMatchingIssues(mocker, issueMessage, stopAfterFailedMatches,
                              matchFailedCount, expectedResult):
    """Test JobAgent()._checkMatchingIssues()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.am_stopExecution"
    )

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    jobAgent.stopAfterFailedMatches = stopAfterFailedMatches
    jobAgent.matchFailedCount = matchFailedCount

    result = jobAgent._checkMatchingIssues(S_ERROR(issueMessage))
    assert result["OK"] == expectedResult
Exemplo n.º 10
0
def test__setCEDict(mocker, ceDict, mockGCReply, mockGCReply2, expected):
    """Test JobAgent()._setCEDict()"""
    if mockGCReply:
        mocker.patch(
            "DIRAC.WorkloadManagementSystem.Agent.JobAgent.gConfig.getValue",
            return_value=mockGCReply)
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.gConfig.getOptionsDict",
        return_value=mockGCReply2)
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    jobAgent._setCEDict(ceDict)
    assert ceDict == expected
Exemplo n.º 11
0
def test__checkMatcherInfo(mocker, matcherInfo, matcherParams, expectedResult):
    """Test JobAgent()._checkMatcherInfo()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Client.JobReport.JobReport.setJobStatus"
    )

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    result = jobAgent._checkMatcherInfo(matcherInfo, matcherParams,
                                        JobReport(123))
    assert result["OK"] == expectedResult["OK"]
    if "Value" in result:
        assert result["Value"] == expectedResult["Value"]
    if "Message" in result:
        assert result["Message"] == expectedResult["Message"]
Exemplo n.º 12
0
def test__rescheduleFailedJob(mocker, mockJMInput, expected):
  """ Testing JobAgent()._rescheduleFailedJob()
  """

  mockJM.return_value = mockJMInput

  mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
  mocker.patch("DIRAC.WorkloadManagementSystem.Agent.JobAgent.JobManagerClient.executeRPC", side_effect=mockJM)

  jobAgent = JobAgent('Test', 'Test1')

  jobID = 101
  message = 'Test'

  jobAgent.log = gLogger
  jobAgent.log.setLevel('DEBUG')

  result = jobAgent._rescheduleFailedJob(jobID, message, stop=False)

  assert result == expected
Exemplo n.º 13
0
def test__checkCPUWorkLeft(mocker, cpuWorkLeft, fillingMode, expectedResult):
    """Test JobAgent()._checkCPUWorkLeft()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.am_stopExecution"
    )

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    jobAgent.fillingMode = fillingMode

    result = jobAgent._checkCPUWorkLeft(cpuWorkLeft)
    assert result["OK"] == expectedResult["OK"]
    if "Value" in result:
        assert result["Value"] == expectedResult["Value"]
    if "Message" in result:
        assert result["Message"] == expectedResult["Message"]
Exemplo n.º 14
0
def test__computeCPUWorkLeft(mocker, initTimeLeft, timeLeft, cpuFactor,
                             mockTimeLeftReply, expectedTimeLeft):
    """Test JobAgent()._computeCPUWorkLeft()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch(
        "DIRAC.Resources.Computing.BatchSystems.TimeLeft.TimeLeft.TimeLeft.getTimeLeft",
        return_value=mockTimeLeftReply)

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")
    jobAgent.timeLeftUtil = TimeLeft()

    jobAgent.initTimeLeft = initTimeLeft
    jobAgent.timeLeft = timeLeft
    jobAgent.cpuFactor = cpuFactor
    result = jobAgent._computeCPUWorkLeft()

    assert abs(result - expectedTimeLeft) < 10
Exemplo n.º 15
0
def test__getCEDict(mocker, ceType, expectedType, expectedNumberElement):
    """Test JobAgent()._getCEDict()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    result = ComputingElementFactory().getCE(ceType)
    assert result["OK"]

    ce = result["Value"]
    ce.ceParameters["MultiProcessorStrategy"] = True
    ce.ceParameters["NumberOfProcessors"] = 4
    result = jobAgent._getCEDict(ce)
    assert result["OK"]
    ceDict = result["Value"]
    assert isinstance(ceDict, expectedType)
    assert len(ceDict) == expectedNumberElement
Exemplo n.º 16
0
def test__checkCEAvailability(mocker, ceType, mockCEReply, expectedResult):
    """Test JobAgent()._checkAvailability()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch(
        "DIRAC.Resources.Computing.ComputingElement.ComputingElement.available",
        return_value=mockCEReply)

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")

    result = ComputingElementFactory().getCE(ceType)
    assert result["OK"]

    ce = result["Value"]
    result = jobAgent._checkCEAvailability(ce)
    assert result["OK"] == expectedResult["OK"]
    if "Value" in expectedResult:
        assert result["Value"] == expectedResult["Value"]
    if "Message" in expectedResult:
        assert result["Message"] == expectedResult["Message"]
Exemplo n.º 17
0
def test_submitJob(mocker, mockJWInput, expected):
    """Testing JobAgent()._submitJob()"""
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule.__init__")
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.AgentModule._AgentModule__moduleProperties",
        side_effect=lambda x, y=None: y,
        create=True,
    )
    mocker.patch(
        "DIRAC.WorkloadManagementSystem.Agent.JobAgent.createJobWrapper",
        return_value=mockJWInput)

    jobAgent = JobAgent("Test", "Test1")
    jobAgent.log = gLogger
    jobAgent.log.setLevel("DEBUG")
    jobAgent.ceName = "Test"

    result = jobAgent._submitJob(101, {}, {}, {}, "", 1)

    assert result["OK"] == expected["OK"]

    if not result["OK"]:
        assert result["Message"] == expected["Message"]