def test_execute(self, _patch1, _patch2): jw = JobWrapper() jw.jobArgs = {'Executable':'/bin/ls'} res = jw.execute('') self.assertTrue( res['OK'] ) shutil.copy('WorkloadManagementSystem/JobWrapper/test/script-OK.sh', 'script-OK.sh') jw = JobWrapper() jw.jobArgs = {'Executable':'script-OK.sh'} res = jw.execute('') self.assertTrue( res['OK'] ) os.remove('script-OK.sh') shutil.copy('WorkloadManagementSystem/JobWrapper/test/script.sh', 'script.sh') jw = JobWrapper() jw.jobArgs = {'Executable':'script.sh', 'Arguments':'111'} res = jw.execute('') self.assertTrue( res['OK'] ) # In this case the application finished with errors, # but the JobWrapper executed successfully os.remove('script.sh') shutil.copy('WorkloadManagementSystem/JobWrapper/test/script-RESC.sh', 'script-RESC.sh') #this will reschedule jw = JobWrapper() jw.jobArgs = {'Executable':'script-RESC.sh'} res = jw.execute('') if res['OK']: # FIXME: This may happen depending on the shell - not the best test admittedly! print "We should not be here, unless the 'Execution thread status' is equal to 1" self.assertTrue( res['OK'] ) else: self.assertFalse( res['OK'] ) # In this case the application finished with an error code # that the JobWrapper interpreted as "to reschedule" # so in this case the "execute" is considered an error os.remove('script-RESC.sh')
def test_execute(self, _patch1, _patch2): jw = JobWrapper() jw.jobArgs = {'Executable':'/bin/ls'} res = jw.execute('') print 'jw.execute() returns',str(res) self.assertTrue( res['OK'] ) shutil.copy('WorkloadManagementSystem/JobWrapper/test/script-OK.sh', 'script-OK.sh') jw = JobWrapper() jw.jobArgs = {'Executable':'script-OK.sh'} res = jw.execute('') self.assertTrue( res['OK'] ) os.remove('script-OK.sh') shutil.copy('WorkloadManagementSystem/JobWrapper/test/script.sh', 'script.sh') jw = JobWrapper() jw.jobArgs = {'Executable':'script.sh', 'Arguments':'111'} res = jw.execute('') self.assertTrue( res['OK'] ) # In this case the application finished with errors, # but the JobWrapper executed successfully os.remove('script.sh') shutil.copy('WorkloadManagementSystem/JobWrapper/test/script-RESC.sh', 'script-RESC.sh') #this will reschedule jw = JobWrapper() jw.jobArgs = {'Executable':'script-RESC.sh'} res = jw.execute('') if res['OK']: # FIXME: This may happen depending on the shell - not the best test admittedly! print "We should not be here, unless the 'Execution thread status' is equal to 1" self.assertTrue( res['OK'] ) else: self.assertFalse( res['OK'] ) # In this case the application finished with an error code # that the JobWrapper interpreted as "to reschedule" # so in this case the "execute" is considered an error os.remove('script-RESC.sh')
def test_execute(mocker): mocker.patch( "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.getSystemSection", side_effect=getSystemSectionMock) mocker.patch( "DIRAC.WorkloadManagementSystem.JobWrapper.Watchdog.getSystemInstance", side_effect=getSystemSectionMock) jw = JobWrapper() jw.jobArgs = {"Executable": "/bin/ls"} res = jw.execute() print("jw.execute() returns", str(res)) assert res["OK"] shutil.copy( "src/DIRAC/WorkloadManagementSystem/JobWrapper/test/script-OK.sh", "script-OK.sh") jw = JobWrapper() jw.jobArgs = {"Executable": "script-OK.sh"} res = jw.execute() assert res["OK"] os.remove("script-OK.sh") shutil.copy("src/DIRAC/WorkloadManagementSystem/JobWrapper/test/script.sh", "script.sh") jw = JobWrapper() jw.jobArgs = {"Executable": "script.sh", "Arguments": "111"} res = jw.execute() assert res["OK"] # In this case the application finished with errors, # but the JobWrapper executed successfully os.remove("script.sh") # this will reschedule shutil.copy( "src/DIRAC/WorkloadManagementSystem/JobWrapper/test/script-RESC.sh", "script-RESC.sh") jw = JobWrapper() jw.jobArgs = {"Executable": "script-RESC.sh"} res = jw.execute() if res["OK"]: # FIXME: This may happen depending on the shell - not the best test admittedly! print( "We should not be here, unless the 'Execution thread status' is equal to 1" ) assert res["OK"] else: assert res[ "OK"] is False # In this case the application finished with an error code # that the JobWrapper interpreted as "to reschedule" # so in this case the "execute" is considered an error os.remove("script-RESC.sh") os.remove("std.out")
def test_finalize(mocker, failedFlag, expectedRes, finalStates): mocker.patch( "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.getSystemSection", side_effect=getSystemSectionMock) mocker.patch( "DIRAC.WorkloadManagementSystem.JobWrapper.JobWrapper.ModuleFactory", side_effect=MagicMock()) jw = JobWrapper() jw.jobArgs = {"Executable": "/bin/ls"} jw.failedFlag = failedFlag res = jw.finalize() assert res == expectedRes assert jw.jobReport.jobStatusInfo[0][0] == finalStates[0] assert jw.jobReport.jobStatusInfo[0][1] == finalStates[1]
def test_finalize(self): jw = JobWrapper() jw.jobArgs = {'Executable': '/bin/ls'} res = jw.finalize() self.assertTrue(res == 1) # by default failed flag is True