def test_job_service_create(): """ Test service.create_job() - expecting state 'NEW' """ js = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) assert j.state == j.get_state() assert j.state == saga.job.NEW except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_close_js(js)
def test_get_job(): """ Test to submit a job, and retrieve it by id """ j = None js = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) # create job service and job jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) # run job - now it has an id, and js must be able to retrieve it by id j.run() j_clone = js.get_job(j.id) assert j.id in j_clone.id except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_job_wait(): """ Test job.wait() - expecting state: DONE (this test might take a while) """ js = None j = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() j.wait() assert j.state == saga.job.DONE, "%s != %s" % (j.state, saga.job.DONE) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_job_suspend_resume(): """ Test job.suspend()/resume() - expecting state: SUSPENDED/RUNNING """ js = None j = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['20'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() j.suspend() assert j.state == saga.job.SUSPENDED assert j.state == j.get_state() j.resume() assert j.state == saga.job.RUNNING assert j.state == j.get_state() except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_job_wait(): """ Test job.wait() - expecting state: DONE (this test might take a while) """ js = None j = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() j.wait() assert j.state == saga.job.DONE, "%s != %s" % (j.state, saga.job.DONE) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_job_suspend_resume(): """ Test job.suspend()/resume() - expecting state: SUSPENDED/RUNNING """ js = None j = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['20'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() j.suspend() assert j.state == saga.job.SUSPENDED assert j.state == j.get_state() j.resume() assert j.state == saga.job.RUNNING assert j.state == j.get_state() except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_get_job(): """ Test to submit a job, and retrieve it by id """ j = None js = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) # create job service and job jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) # run job - now it has an id, and js must be able to retrieve it by id j.run() j_clone = js.get_job(j.id) assert j.id in j_clone.id except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_list_jobs(): """ Test if a submitted job shows up in Service.list() """ j = None js = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) # create job service and job jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) # run job - now it has an id, and js must know it j.run() all_jobs = js.list() assert j.id in all_jobs, \ "%s not in %s" % (j.id, all_jobs) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_get_exit_code(): """ Test job.exit_code """ js = None j = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = "/bin/sleep" # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() j.wait() ec = j.exit_code assert ec == 1, "%s != 1" % ec except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_job_service_invalid_url(): """ Test if a non-resolvable hostname results in a proper exception """ try: tc = testing.get_test_config() invalid_url = deepcopy(saga.Url(tc.job_service_url)) invalid_url.host = "does.not.exist" tmp_js = saga.job.Service(invalid_url, tc.session) _silent_close_js(tmp_js) assert False, "Expected XYZ exception but got none." except saga.BadParameter: assert True # we don't check DNS anymore, as that can take *ages* -- so we now also # see Timeout and NoSuccess exceptions... except saga.Timeout: assert True except saga.NoSuccess: assert True # other exceptions sould never occur except saga.SagaException as ex: assert False, "Expected BadParameter, Timeout or NoSuccess exception, but got %s (%s)" % ( type(ex), ex)
def test_replica_remove(): """ Test logical file remove, which should remove the file from the remote resource """ try: tc = testing.get_test_config() the_url = tc.job_service_url # from test config file the_session = tc.session # from test config file replica_url = tc.replica_url replica_directory = saga.replica.LogicalDirectory(replica_url) home_dir = os.path.expanduser("~" + "/") print "Creating temporary file of size %dM : %s" % \ (FILE_SIZE, home_dir+TEMP_FILENAME) # create a file for us to use with open(home_dir + TEMP_FILENAME, "wb") as f: f.write("x" * (FILE_SIZE * pow(2, 20))) print "Creating logical directory object" mydir = saga.replica.LogicalDirectory(replica_url) print "Uploading temporary" myfile = saga.replica.LogicalFile(replica_url + TEMP_FILENAME) myfile.upload(home_dir + TEMP_FILENAME, \ "irods:///this/path/is/ignored/?resource="+IRODS_RESOURCE, saga.replica.OVERWRITE) print "Removing temporary file." myfile.remove() assert True except saga.SagaException as ex: # print ex.traceback assert False, "unexpected exception %s\n%s" % (ex.traceback, ex)
def test_jobid_viability (): """ Test if jobid represents job """ # The job id for the fork shell adaptor should return a pid which represents # the actual job instance. We test by killing that pid and checking state. try: import os tc = testing.get_test_config () js_url = saga.Url (tc.job_service_url) if js_url.schema.lower() not in ['fork', 'local', 'ssh'] : # test not supported for other backends return if js_url.host.lower() not in [None, '', 'localhost'] : # test not supported for other backends return js = saga.job.Service ('fork:///') j = js.run_job ("/bin/sleep 100") jid = j.id js_part, j_part = jid.split ('-', 1) pid = j_part[1:-3] # kill the children (i.e. the only child) of the pid, which is the # actual job os.system ('ps -ef | cut -c 8-21 | grep " %s " | cut -c 1-8 | grep -v " %s " | xargs -r kill' % (pid, pid)) assert (j.state == saga.job.FAILED), 'job.state: %s' % j.state except saga.SagaException as se: assert False, "Unexpected exception: %s" % se
def test_derive_overlay(): """ test overlay derivation """ tc = rut.get_test_config() wl_dict = tc.workload_dict wl = troy.Workload() planner = troy.Planner() # pprint.pprint(wl_dict) if not 'tasks' in wl_dict: assert False, "no tasks in workload dict" if not len(wl_dict['tasks']): assert False, "zero tasks in workload dict" for task_dict in wl_dict['tasks']: task_description = troy.TaskDescription(task_dict) wl.add_task(task_description) for relation_dict in wl_dict['relations']: relation_description = troy.RelationDescription(relation_dict) wl.add_relation(relation_description) overlay_id = planner.derive_overlay(wl.id) overlay = troy.OverlayManager.get_overlay(overlay_id) if not overlay.description.cores : assert False, "No cores requested" if not overlay.description.wall_time : assert False, "Walltime is zero"
def test_expand_workload(): """ test workload planning """ tc = rut.get_test_config() wl_dict = tc.workload_dict wl = troy.Workload() planner = troy.Planner() # pprint.pprint(wl_dict) if not 'tasks' in wl_dict: assert False, "no tasks in workload dict" if not len(wl_dict['tasks']): assert False, "zero tasks in workload dict" for task_dict in wl_dict['tasks']: task_description = troy.TaskDescription(task_dict) wl.add_task(task_description) for relation_dict in wl_dict['relations']: relation_description = troy.RelationDescription(relation_dict) wl.add_relation(relation_description) if not wl.state is troy.DESCRIBED: assert False, "Workload state != DESCRIBED" planner.expand_workload(wl.id) if not wl.state is troy.PLANNED: assert False, "Workload state != PLANNED"
def test_replica_remove(): """ Test logical file remove, which should remove the file from the remote resource """ try: tc = testing.get_test_config () the_url = tc.job_service_url # from test config file the_session = tc.session # from test config file replica_url = tc.replica_url replica_directory = saga.replica.LogicalDirectory(replica_url) home_dir = os.path.expanduser("~"+"/") print "Creating temporary file of size %dM : %s" % \ (FILE_SIZE, home_dir+TEMP_FILENAME) # create a file for us to use with open(home_dir+TEMP_FILENAME, "wb") as f: f.write ("x" * (FILE_SIZE * pow(2,20)) ) print "Creating logical directory object" mydir = saga.replica.LogicalDirectory(replica_url) print "Uploading temporary" myfile = saga.replica.LogicalFile(replica_url+TEMP_FILENAME) myfile.upload(home_dir + TEMP_FILENAME, \ "irods:///this/path/is/ignored/?resource="+IRODS_RESOURCE, saga.replica.OVERWRITE) print "Removing temporary file." myfile.remove() assert True except saga.SagaException as ex: # print ex.traceback assert False, "unexpected exception %s\n%s" % (ex.traceback, ex)
def test_get_exit_code(): """ Test job.exit_code """ js = None j = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = "/bin/sleep" # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() j.wait() ec = j.exit_code assert ec == 1, "%s != 1" % ec except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def test_job_service_create(): """ Test service.create_job() - expecting state 'NEW' """ js = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) assert j.state == j.get_state() assert j.state == saga.job.NEW except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_close_js(js)
def test_job_service_invalid_url(): """ Test if a non-resolvable hostname results in a proper exception """ try: tc = testing.get_test_config () invalid_url = deepcopy(saga.Url(tc.job_service_url)) invalid_url.host = "does.not.exist" tmp_js = saga.job.Service(invalid_url, tc.session) _silent_close_js(tmp_js) assert False, "Expected XYZ exception but got none." except saga.BadParameter : assert True # we don't check DNS anymore, as that can take *ages* -- so we now also # see Timeout and NoSuccess exceptions... except saga.Timeout : assert True except saga.NoSuccess : assert True # other exceptions sould never occur except saga.SagaException as ex: assert False, "Expected BadParameter, Timeout or NoSuccess exception, but got %s (%s)" % (type(ex), ex)
def test_list_jobs(): """ Test if a submitted job shows up in Service.list() """ j = None js = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) # create job service and job jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) # run job - now it has an id, and js must know it j.run() all_jobs = js.list() assert j.id in all_jobs, \ "%s not in %s" % (j.id, all_jobs) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_cancel(j) _silent_close_js(js)
def tearDown(self): """Teardown called once per class instance""" try: # do the cleanup tc = testing.get_test_config() d = saga.filesystem.Directory(tc.filesystem_url) d.remove(self.uniquefilename1) d.remove(self.uniquefilename2) except saga.SagaException as ex: pass
def tearDown(self): """Teardown called once per class instance""" try: # do the cleanup tc = testing.get_test_config () d = saga.filesystem.Directory(tc.filesystem_url) d.remove(self.uniquefilename1) d.remove(self.uniquefilename2) except saga.SagaException as ex: pass
def test_nonexisting_file_create_open(self): """ Testing if opening a non-existing file with the 'create' flag set works. """ try: pass tc = testing.get_test_config() nonex_file = deepcopy(saga.Url(tc.filesystem_url)) nonex_file.path += "/%s" % self.uniquefilename1 f = saga.filesystem.File(nonex_file, saga.filesystem.CREATE) assert f.size == 0 # this should fail if the file doesn't exist! except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_nonexisting_file_create_open(self): """ Testing if opening a non-existing file with the 'create' flag set works. """ try: pass tc = testing.get_test_config () nonex_file = deepcopy(saga.Url(tc.filesystem_url)) nonex_file.path += "/%s" % self.uniquefilename1 f = saga.filesystem.File(nonex_file, saga.filesystem.CREATE) assert f.size == 0 # this should fail if the file doesn't exist! except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def helper_multiple_services(i): tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() assert (j.state in [saga.job.RUNNING, saga.job.PENDING]), "job submission failed" _silent_cancel(j) _silent_close_js(js)
def helper_multiple_services(i): tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['10'] jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) j = js.create_job(jd) j.run() assert (j.state in [saga.job.RUNNING, saga.job.PENDING]), "job submission failed" _silent_cancel(j) _silent_close_js(js)
def test_ptyshell_nok () : """ Test pty_shell which runs command unsuccessfully """ conf = rut.get_test_config () shell = sups.PTYShell (saga.Url(conf.job_service_url), conf.session) txt = "______1______2_____3_____" ret, out, _ = shell.run_sync ("printf \"%s\" ; false" % txt) assert (ret == 1) , "%s" % (repr(ret)) assert (out == txt) , "%s == %s" % (repr(out), repr(txt)) assert (shell.alive ()) shell.finalize (True) assert (not shell.alive ())
def test_ptyshell_nok(): """ Test pty_shell which runs command unsuccessfully """ conf = rut.get_test_config() shell = sups.PTYShell(saga.Url(conf.job_service_url), conf.session) txt = "______1______2_____3_____" ret, out, _ = shell.run_sync("printf \"%s\" ; false" % txt) assert (ret == 1), "%s" % (repr(ret)) assert (out == txt), "%s == %s" % (repr(out), repr(txt)) assert (shell.alive()) shell.finalize(True) assert (not shell.alive())
def test_nonexisting_host_file_open(self): """ Testing if opening a file on a non-existing host causes an exception. """ try: tc = testing.get_test_config () invalid_url = deepcopy(saga.Url(tc.filesystem_url)) invalid_url.host = "does.not.exist" f = saga.filesystem.File(invalid_url) assert False, "Expected BadParameter exception but got none." except saga.BadParameter: assert True except saga.SagaException as ex: assert False, "Expected BadParameter exception, but got %s" % ex
def test_directory_get_session(self): """ Testing if the correct session is being used """ try: tc = testing.get_test_config() session = tc.session or saga.Session() d = saga.filesystem.Directory(tc.filesystem_url, session=session) assert d.get_session() == session, 'Failed setting the session' except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_nonexisting_host_file_open(self): """ Testing if opening a file on a non-existing host causes an exception. """ try: tc = testing.get_test_config() invalid_url = deepcopy(saga.Url(tc.filesystem_url)) invalid_url.host = "does.not.exist" f = saga.filesystem.File(invalid_url) assert False, "Expected BadParameter exception but got none." except saga.BadParameter: assert True except saga.SagaException as ex: assert False, "Expected BadParameter exception, but got %s" % ex
def test_replica_directory(): """ Test logical file directory """ try: tc = testing.get_test_config () the_url = tc.job_service_url # from test config file the_session = tc.session # from test config file replica_url = tc.replica_url replica_directory = saga.replica.LogicalDirectory(replica_url) assert True except saga.SagaException as ex: assert False, "unexpected exception %s" % ex
def test_replica_directory(): """ Test logical file directory """ try: tc = testing.get_test_config() the_url = tc.job_service_url # from test config file the_session = tc.session # from test config file replica_url = tc.replica_url replica_directory = saga.replica.LogicalDirectory(replica_url) assert True except saga.SagaException as ex: assert False, "unexpected exception %s" % ex
def test_job_service_get_url(): """ Test if the job service URL is returned correctly """ js = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) assert js, "job service creation failed?" assert (tc.job_service_url == str(js.url)), "%s == %s" % (tc.job_service_url, str(js.url)) except saga.SagaException as ex: assert False, "unexpected exception %s" % ex finally: _silent_close_js(js)
def test_multiple_services(): """ Test to create multiple job service instances (this test might take a while) """ try: tc = testing.get_test_config() for i in range(0, NUM_SERVICES): helper_multiple_services(i) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se
def test_existing_file_open(self): """ Testing if we can open an existing file. """ try: tc = testing.get_test_config () filename = deepcopy(saga.Url(tc.filesystem_url)) filename.path += "/%s" % self.uniquefilename1 f = saga.filesystem.File(filename, saga.filesystem.CREATE) f2 = saga.filesystem.File(f.url) assert f2.size == 0 # this should fail if the file doesn't exist! except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_nonexisting_file_open(self): """ Testing if opening a non-existing file causes an exception. """ try: pass tc = testing.get_test_config () nonex_file = deepcopy(saga.Url(tc.filesystem_url)) nonex_file.path += "/file.does.not.exist" f = saga.filesystem.File(nonex_file) assert False, "Expected DoesNotExist exception but got none." except saga.DoesNotExist: assert True except saga.SagaException as ex: assert False, "Expected DoesNotExist exception, but got %s" % ex
def test_existing_file_open(self): """ Testing if we can open an existing file. """ try: tc = testing.get_test_config() filename = deepcopy(saga.Url(tc.filesystem_url)) filename.path += "/%s" % self.uniquefilename1 f = saga.filesystem.File(filename, saga.filesystem.CREATE) f2 = saga.filesystem.File(f.url) assert f2.size == 0 # this should fail if the file doesn't exist! except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_nonexisting_file_open(self): """ Testing if opening a non-existing file causes an exception. """ try: pass tc = testing.get_test_config() nonex_file = deepcopy(saga.Url(tc.filesystem_url)) nonex_file.path += "/file.does.not.exist" f = saga.filesystem.File(nonex_file) assert False, "Expected DoesNotExist exception but got none." except saga.DoesNotExist: assert True except saga.SagaException as ex: assert False, "Expected DoesNotExist exception, but got %s" % ex
def test_ptyshell_file_stage () : """ Test pty_shell file staging """ conf = rut.get_test_config () shell = sups.PTYShell (saga.Url(conf.job_service_url), conf.session) txt = "______1______2_____3_____" shell.write_to_remote (txt, "/tmp/saga-test-staging") out = shell.read_from_remote ("/tmp/saga-test-staging") assert (txt == out) , "%s == %s" % (repr(out), repr(txt)) ret, out, _ = shell.run_sync ("rm /tmp/saga-test-staging") assert (ret == 0) , "%s" % (repr(ret)) assert (out == "") , "%s == ''" % (repr(out))
def test_ptyshell_file_stage(): """ Test pty_shell file staging """ conf = rut.get_test_config() shell = sups.PTYShell(saga.Url(conf.job_service_url), conf.session) txt = "______1______2_____3_____" shell.write_to_remote(txt, "/tmp/saga-test-staging") out = shell.read_from_remote("/tmp/saga-test-staging") assert (txt == out), "%s == %s" % (repr(out), repr(txt)) ret, out, _ = shell.run_sync("rm /tmp/saga-test-staging") assert (ret == 0), "%s" % (repr(ret)) assert (out == ""), "%s == ''" % (repr(out))
def test_multiple_services(): """ Test to create multiple job service instances (this test might take a while) """ try: tc = testing.get_test_config () for i in range(0, NUM_SERVICES): helper_multiple_services(i) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se
def test_job_service_get_url(): """ Test if the job service URL is returned correctly """ js = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) assert js, "job service creation failed?" assert (tc.job_service_url == str( js.url)), "%s == %s" % (tc.job_service_url, str(js.url)) except saga.SagaException as ex: assert False, "unexpected exception %s" % ex finally: _silent_close_js(js)
def test_close(): """ Test job service close() """ try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) js.close() js.get_url() assert False, "Subsequent calls should fail after close()" except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException: assert True
def test_close(): """ Test job service close() """ try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) js.close() js.get_url() assert False, "Subsequent calls should fail after close()" except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException: assert True
def test_workload_create(): """ test workload creation """ tc = rut.get_test_config() wl_dict = tc.workload_dict wl = troy.Workload() if not "tasks" in wl_dict: assert False, "no tasks in workload dict" if not len(wl_dict["tasks"]): assert False, "zero tasks in workload dict" for task_dict in wl_dict["tasks"]: task_description = troy.TaskDescription(task_dict) wl.add_task(task_description)
def test_overlay_create () : """ test overlay creation """ tc = rut.get_test_config () ol_dict = tc.overlay_dict ol = troy.Overlay ({'cores' : 1}) if not 'pilots' in ol_dict : assert False, "no pilots in overlay dict" if not len(ol_dict['pilots']) : assert False, "zero pilots in overlay dict" for pilot_dict in ol_dict['pilots'] : pilot_description = troy.PilotDescription (pilot_dict) ol._add_pilot (pilot_description)
def test_file_copy_remote_local(self): """ Testing if we can copy a file from remote -> local """ try: pass tc = testing.get_test_config () filename1 = deepcopy(saga.Url(tc.filesystem_url)) filename1.path = "/etc/passwd" f1 = saga.filesystem.File(filename1) filename2 = "file://localhost/tmp/%s" % self.uniquefilename2 f1.copy(filename2) f2 = saga.filesystem.File(filename2) assert f2.size != 0 # this should fail if the file doesn't exist! except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_file_copy_remote_local(self): """ Testing if we can copy a file from remote -> local """ try: pass tc = testing.get_test_config() filename1 = deepcopy(saga.Url(tc.filesystem_url)) filename1.path = "/etc/passwd" f1 = saga.filesystem.File(filename1) filename2 = "file://localhost/tmp/%s" % self.uniquefilename2 f1.copy(filename2) f2 = saga.filesystem.File(filename2) assert f2.size != 0 # this should fail if the file doesn't exist! except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_get_url(): """ Test job service url/get_url() """ js = None try: tc = testing.get_test_config () js = saga.job.Service(tc.job_service_url, tc.session) assert str(js.get_url()) == str(tc.job_service_url) assert str(js.url) == str(tc.job_service_url) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_close_js(js)
def test_file_get_session(self): """ Testing if the correct session is being used """ try: tc = testing.get_test_config () session = tc.session or saga.Session() filename = deepcopy(saga.Url(tc.filesystem_url)) filename.path += "/%s" % self.uniquefilename1 f = saga.filesystem.File(filename, saga.filesystem.CREATE, session=session) assert f.get_session() == session, 'Failed setting the session' f2 = saga.filesystem.File(f.url, session=session) assert f2.get_session() == session, 'Failed setting the session' except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_get_url(): """ Test job service url/get_url() """ js = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) assert str(js.get_url()) == str(tc.job_service_url) assert str(js.url) == str(tc.job_service_url) except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_close_js(js)
def test_upload_and_download(): """ Test file upload and download" """ try: tc = testing.get_test_config() home_dir = os.path.expanduser("~" + "/") replica_url = tc.replica_url print "Creating temporary file of size %dM : %s" % \ (FILE_SIZE, home_dir+TEMP_FILENAME) # create a file for us to use with iRODS with open(home_dir + TEMP_FILENAME, "wb") as f: f.write("x" * (FILE_SIZE * pow(2, 20))) print "Creating logical directory object" mydir = saga.replica.LogicalDirectory(replica_url) print "Making sure there is no file existing remotely" import subprocess subprocess.call(["irm", TEMP_FILENAME]) print "Uploading file to remote host: %s" % home_dir + TEMP_FILENAME myfile = saga.replica.LogicalFile(replica_url + TEMP_FILENAME) myfile.upload(home_dir + TEMP_FILENAME, \ "irods:///this/path/is/ignored/?resource="+IRODS_RESOURCE) #myfile.upload(home_dir + TEMP_FILENAME, \ # "irods:///this/path/is/ignored") print "Deleting file locally : %s" % (home_dir + TEMP_FILENAME) os.remove(home_dir + TEMP_FILENAME) print "Downloading logical file %s to current/default directory" % \ (replica_url + TEMP_FILENAME) myfile.download(TEMP_FILENAME) print "Deleting downloaded file locally : %s" % (home_dir + TEMP_FILENAME) os.remove(home_dir + TEMP_FILENAME) assert True except saga.SagaException as ex: assert False, "unexpected exception %s" % ex
def test_job_run_many(): """ Run a bunch of jobs concurrently via the same job service. """ NUM_JOBS = 32 js = None jobs = [] try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) jd = saga.job.Description() jd.executable = '/bin/sleep' jd.arguments = ['60'] # add options from the test .cfg file if set jd = sutc.add_tc_params_to_jd(tc=tc, jd=jd) for i in range(0, NUM_JOBS): j = js.create_job(jd) jobs.append(j) # start all jobs for job in jobs: job.run() # wait a bit time.sleep(10) for job in jobs: job.cancel() assert job.state == saga.job.CANCELED except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: for j in jobs: _silent_cancel(j) _silent_close_js(js)
def test_run_job(): """ Test to submit a job via run_job, and retrieve id""" js = None try: tc = testing.get_test_config() js = saga.job.Service(tc.job_service_url, tc.session) # create job service and job j = js.run_job("/bin/sleep 10") assert j.id except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_close_js(js)
def test_file_get_session(self): """ Testing if the correct session is being used """ try: tc = testing.get_test_config() session = tc.session or saga.Session() filename = deepcopy(saga.Url(tc.filesystem_url)) filename.path += "/%s" % self.uniquefilename1 f = saga.filesystem.File(filename, saga.filesystem.CREATE, session=session) assert f.get_session() == session, 'Failed setting the session' f2 = saga.filesystem.File(f.url, session=session) assert f2.get_session() == session, 'Failed setting the session' except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_ptyshell_async () : """ Test pty_shell which runs command successfully """ conf = rut.get_test_config () shell = sups.PTYShell (saga.Url(conf.job_service_url), conf.session) txt = "______1______2_____3_____\n" shell.run_async ("cat <<EOT") shell.send (txt) shell.send ('EOT\n') ret, out = shell.find_prompt () assert (ret == 0) , "%s" % (repr(ret)) assert (out == txt) , "%s == %s" % (repr(out), repr(txt)) assert (shell.alive ()) shell.finalize (True) assert (not shell.alive ())
def test_open_close(): """ Test job service create / close() in a big loop """ js = None try: tc = testing.get_test_config() for i in range(0, 10): js = saga.job.Service(tc.job_service_url, tc.session) js.close() except saga.NotImplemented as ni: assert tc.notimpl_warn_only, "%s " % ni if tc.notimpl_warn_only: print "%s " % ni except saga.SagaException as se: assert False, "Unexpected exception: %s" % se finally: _silent_close_js(js)
def test_file_copy_1(self): """ Testing if we can copy an existing file. """ try: pass tc = testing.get_test_config () filename1 = deepcopy(saga.Url(tc.filesystem_url)) filename1.path += "/%s" % self.uniquefilename1 f1 = saga.filesystem.File(filename1, saga.filesystem.CREATE) filename2 = deepcopy(saga.Url(tc.filesystem_url)) filename2.path += "/%s" % self.uniquefilename2 f1.copy(filename2) f2 = saga.filesystem.File(filename2) assert f2.size == 0 # this should fail if the file doesn't exist! except saga.SagaException as ex: assert False, "Unexpected exception: %s" % ex
def test_ptyshell_async(): """ Test pty_shell which runs command successfully """ conf = rut.get_test_config() shell = sups.PTYShell(saga.Url(conf.job_service_url), conf.session) txt = "______1______2_____3_____\n" shell.run_async("cat <<EOT") shell.send(txt) shell.send('EOT\n') ret, out = shell.find_prompt() assert (ret == 0), "%s" % (repr(ret)) assert (out == txt), "%s == %s" % (repr(out), repr(txt)) assert (shell.alive()) shell.finalize(True) assert (not shell.alive())