def test_getJobStatus(mocker): """Test HTCondorCE getJobStatus""" mocker.patch(MODNAME + ".commands.getstatusoutput", side_effect=([(0, "\n".join(STATUS_LINES)), (0, 0)])) patchPopen = mocker.patch( "DIRAC.Resources.Computing.BatchSystems.Condor.subprocess.Popen") patchPopen.return_value.communicate.side_effect = [ ("\n".join(HISTORY_LINES), "") ] patchPopen.return_value.returncode = 0 mocker.patch( MODNAME + ".HTCondorCEComputingElement._HTCondorCEComputingElement__cleanup") htce = HTCE.HTCondorCEComputingElement(12345) ret = htce.getJobStatus([ "htcondorce://condorce.foo.arg/123.0:::abc321", "htcondorce://condorce.foo.arg/123.1:::c3b2a1", "htcondorce://condorce.foo.arg/123.2:::c3b2a2", "htcondorce://condorce.foo.arg/333.3:::c3b2a3", ]) expectedResults = { "htcondorce://condorce.foo.arg/123.0": "Done", "htcondorce://condorce.foo.arg/123.1": "Aborted", "htcondorce://condorce.foo.arg/123.2": "Aborted", "htcondorce://condorce.foo.arg/333.3": "Unknown", } assert ret["OK"] is True assert expectedResults == ret["Value"]
def test_getJobStatus(self): htce = HTCE.HTCondorCEComputingElement(12345) with patch( MODNAME+".commands.getstatusoutput", new=Mock( side_effect=( [ (0, "\n".join(STATUS_LINES) ), # condor_q (0, "\n".join(HISTORY_LINES)), # condor_history (0, 0), # condor_rm, ignored in any case ] ))), \ patch( MODNAME+".HTCondorCEComputingElement._HTCondorCEComputingElement__cleanup", new=Mock() ) \ : ret = htce.getJobStatus([ "htcondorce://condorce.foo.arg/123.0:::abc321", "htcondorce://condorce.foo.arg/123.1:::c3b2a1", "htcondorce://condorce.foo.arg/123.2:::c3b2a2", "htcondorce://condorce.foo.arg/333.3:::c3b2a3", ]) expectedResults = { "htcondorce://condorce.foo.arg/123.0": "Done", "htcondorce://condorce.foo.arg/123.1": "Aborted", "htcondorce://condorce.foo.arg/123.2": "Aborted", "htcondorce://condorce.foo.arg/333.3": "Unknown", } self.assertTrue(ret['OK'], ret.get('Message', '')) self.assertEqual(expectedResults, ret['Value'])
def test_parseCondorStatus(self): statusLines = """ 104097.9 2 104098.0 1 104098.1 4 foo bar 104098.2 3 104098.3 5 104098.4 7 """.strip().split('\n') # force there to be an empty line expectedResults = { "104097.9": "Running", "104098.0": "Waiting", "104098.1": "Done", "104098.2": "Aborted", "104098.3": "HELD", "104098.4": "Unknown" } for jobID, expected in expectedResults.iteritems(): self.assertEqual(HTCE.parseCondorStatus(statusLines, jobID), expected)
def test_parseCondorStatus(self): statusLines = """ 104097.9 2 104098.0 1 104098.1 4 foo bar 104098.2 3 104098.3 5 104098.4 7 """.strip().split( "\n" ) ## force there to be an empty line expectedResults = { "104097.9": "Running", "104098.0": "Waiting", "104098.1": "Done", "104098.2": "Aborted", "104098.3": "HELD", "104098.4": "Unknown", } for jobID, expected in expectedResults.iteritems(): self.assertEqual(HTCE.parseCondorStatus(statusLines, jobID), expected)
def test_reset_local(self): htce = HTCE.HTCondorCEComputingElement(12345) htce.ceParameters = self.ceParameters htce.useLocalSchedd = True ceName = "condorce.cern.ch" htce.ceName = ceName htce._reset() self.assertEqual(htce.remoteScheddOptions, "")
def test_reset_remote(self): htce = HTCE.HTCondorCEComputingElement(12345) htce.ceParameters = self.ceParameters htce.useLocalSchedd = False ceName = "condorce.cern.ch" htce.ceName = ceName htce._reset() self.assertEqual(htce.remoteScheddOptions, "-pool %s:9619 -name %s " % (ceName, ceName))
def test_reset(setUp, localSchedd, expected): ceParameters = setUp htce = HTCE.HTCondorCEComputingElement(12345) htce.ceParameters = ceParameters htce.useLocalSchedd = True ceName = "condorce.cern.ch" htce.ceName = ceName htce._reset() assert htce.remoteScheddOptions == ""
def test_killJob(self, jobIDList, jobID, ret=0, success=True, local=True): mock = Mock(return_value=(ret, '')) htce = HTCE.HTCondorCEComputingElement(12345) htce.ceName = 'condorce.foo.arg' htce.useLocalSchedd = local htce.ceParameters = self.ceParameters htce._reset() with patch(MODNAME + ".commands.getstatusoutput", new=mock): ret = htce.killJob(jobIDList=jobIDList) assert ret['OK'] == success if jobID: mock.assert_called_with('condor_rm %s %s' % (htce.remoteScheddOptions, jobID))
def test__writeSub_local(self): htce = HTCE.HTCondorCEComputingElement(12345) htce.useLocalSchedd = True subFileMock = Mock() patchFdopen = patch(MODNAME + ".os.fdopen", new=Mock(return_value=subFileMock)) patchMkstemp = patch(MODNAME + ".tempfile.mkstemp", new=Mock(return_value=("os", "pilotName"))) patchMkdir = patch(MODNAME + ".mkDir", new=Mock()) with patchFdopen, patchMkstemp, patchMkdir: htce._HTCondorCEComputingElement__writeSub("dirac-install", 42, '', 1) # pylint: disable=E1101 for option in ["ShouldTransferFiles = YES", "WhenToTransferOutput = ON_EXIT_OR_EVICT", "universe = grid"]: # the three [0] are: call_args_list[firstCall][ArgsArgumentsTuple][FirstArgsArgument] self.assertIn(option, subFileMock.write.call_args_list[0][0][0])
def test_submitJob_remote(self): htce = HTCE.HTCondorCEComputingElement(12345) htce.ceParameters = self.ceParameters htce.useLocalSchedd = False ceName = "condorce.cern.ch" htce.ceName = ceName execMock = Mock(return_value=S_OK((0, "123.0 - 123.0"))) htce._HTCondorCEComputingElement__writeSub = Mock(return_value="dirac-pilot") with patch(MODNAME + ".executeGridCommand", new=execMock), patch(MODNAME + ".os", new=Mock()): result = htce.submitJob("pilot", "proxy", 1) self.assertTrue(result['OK'], result.get('Message')) remotePoolList = " ".join(['-pool', '%s:9619' % ceName, '-remote', ceName]) self.assertIn(remotePoolList, " ".join(execMock.call_args_list[0][0][1]))
def test__writeSub(mocker, localSchedd, optionsNotExpected, optionsExpected): htce = HTCE.HTCondorCEComputingElement(12345) htce.useLocalSchedd = localSchedd subFileMock = mocker.Mock() mocker.patch(MODNAME + ".os.fdopen", return_value=subFileMock) mocker.patch(MODNAME + ".tempfile.mkstemp", return_value=("os", "pilotName")) mocker.patch(MODNAME + ".mkDir") htce._HTCondorCEComputingElement__writeSub("dirac-install", 42, "", 1) # pylint: disable=E1101 for option in optionsNotExpected: # the three [0] are: call_args_list[firstCall][ArgsArgumentsTuple][FirstArgsArgument] assert option not in subFileMock.write.call_args_list[0][0][0] for option in optionsExpected: assert option in subFileMock.write.call_args_list[0][0][0]
def test__writeSub_remote(self): htce = HTCE.HTCondorCEComputingElement(12345) htce.useLocalSchedd = False subFileMock = Mock() patchFdopen = patch(MODNAME + ".os.fdopen", new=Mock(return_value=subFileMock)) patchMkstemp = patch(MODNAME + ".tempfile.mkstemp", new=Mock(return_value=("os", "pilotName"))) patchMkdir = patch(MODNAME + ".mkDir", new=Mock()) with patchFdopen, patchMkstemp, patchMkdir: htce._HTCondorCEComputingElement__writeSub("dirac-install", 42, '', 1) # pylint: disable=E1101 for option in ["ShouldTransferFiles = YES", "WhenToTransferOutput = ON_EXIT_OR_EVICT"]: self.assertNotIn(option, subFileMock.write.call_args_list[0][0][0]) for option in ["universe = vanilla"]: self.assertIn(option, subFileMock.write.call_args_list[0][0][0])
def test_killJob(setUp, mocker, jobIDList, jobID, ret, success, local): ceParameters = setUp htce = HTCE.HTCondorCEComputingElement(12345) htce.ceName = "condorce.foo.arg" htce.useLocalSchedd = local htce.ceParameters = ceParameters htce._reset() execMock = mocker.patch(MODNAME + ".executeGridCommand", return_value=S_OK((ret, "", ""))) with execMock: ret = htce.killJob(jobIDList=jobIDList) assert ret["OK"] == success if jobID: expected = "condor_rm %s %s" % (htce.remoteScheddOptions.strip(), jobID) assert " ".join(execMock.call_args_list[0][0][1]) == expected
def test_getJobStatus(self): htce = HTCE.HTCondorCEComputingElement(12345) ret = htce.getJobStatus(["htcondorce://condorce.foo.arg/123.0:::abc321", "htcondorce://condorce.foo.arg/123.1:::c3b2a1", "htcondorce://condorce.foo.arg/123.2:::c3b2a2", "htcondorce://condorce.foo.arg/333.3:::c3b2a3"]) expectedResults = {"htcondorce://condorce.foo.arg/123.0": "Done", "htcondorce://condorce.foo.arg/123.1": "Aborted", "htcondorce://condorce.foo.arg/123.2": "Aborted", "htcondorce://condorce.foo.arg/333.3": "Unknown"} self.assertTrue(ret['OK'], ret.get('Message', '')) self.assertEqual(expectedResults, ret['Value'])
def test_submitJob(setUp, mocker, localSchedd, expected): ceParameters = setUp htce = HTCE.HTCondorCEComputingElement(12345) htce.ceParameters = ceParameters htce.useLocalSchedd = localSchedd ceName = "condorce.cern.ch" htce.ceName = ceName execMock = mocker.patch(MODNAME + ".executeGridCommand", return_value=S_OK((0, "123.0 - 123.0"))) mocker.patch( MODNAME + ".HTCondorCEComputingElement._HTCondorCEComputingElement__writeSub", return_value="dirac_pilot" ) mocker.patch(MODNAME + ".os") result = htce.submitJob("pilot", "proxy", 1) assert result["OK"] is True assert " ".join(execMock.call_args_list[0][0][1]) == expected