def test_session(self): js = saga.job.Service("fork://localhost") jd = saga.job.Service("fork://localhost") if js.get_session() != jd.get_session(): self.fail("Both objects should return the same (default) session") if js.get_session( ) != saga.Object._Object__shared_state["default_session"]: self.fail("Object should return default session") if jd.get_session( ) != saga.Object._Object__shared_state["default_session"]: self.fail("Object should return default session") js = saga.job.Service("fork://localhost") if js.get_session( ) != saga.Object._Object__shared_state["default_session"]: self.fail("Object should return default session") js = saga.job.Service("fork://localhost", session=saga.Session()) if js.get_session( ) == saga.Object._Object__shared_state["default_session"]: self.fail("Object should not return default session") c1 = saga.Context() s1 = saga.Session() s1.add_context(c1) if len(s1.list_contexts()) != 1: self.fail("Context list length should be 1") s1.remove_context(c1) if len(s1.list_contexts()) != 0: self.fail("Context list length should be 0") s2 = saga.Session() js1 = saga.job.Service("fork://localhost", session=s1) js2 = saga.job.Service("fork://localhost", session=s2) if js1.get_session() == js2.get_session(): self.fail("Sessions shouldn't be identical")
def main(): try: # set up a security context (optional) that describes # our log-in credentials for the bigjob service. # if the bigjob service doesn't have security enabled, # this is not necessary. ctx = saga.Context() ctx.type = saga.Context.BigJob ctx.userid = 'oweidner' ctx.userpass = '******' session = saga.Session() session.contexts.append(ctx) # create a job service that connects to a bigjob # server running. js = saga.job.Service( "bigjob://engage-submit3.renci.org:28082/engage.fork.test", session=session) # describe our job jd = saga.job.Description() # resource requirements jd.wall_time_limit = "0:05:00" jd.number_of_processes = 1 # environment, executable & arguments jd.executable = '/bin/sleep' jd.arguments = ['10'] # output options jd.output = "bigjob_via_saga_api.stdout" jd.error = "bigjob_via_saga_api.stderr" # create the job (state: New) myjob = js.create_job(jd) print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...starting job...\n" # run the job (submit the job to PBS) myjob.run() print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...waiting for job...\n" # wait for the job to either finish or fail myjob.wait() print "Job State : %s" % (myjob.get_state()) print "Exitcode : %s" % (myjob.exitcode) except saga.Exception, ex: print "Oh, snap! An error occured: %s" % (str(ex))
def main(): try: js = saga.job.Service("fork://localhost") jd = saga.job.Description() print repr(js.get_session()) print repr(jd.get_session()) c1 = saga.Context() c1.type = saga.Context.SSH c1.usercert = "/Users/s1063117/id_rsa.pub" c1.userkey = "/Users/s1063117/id_rsa" s1 = saga.Session() s1.add_context(c1) assert (len(s1.list_contexts()) == 1) s1.remove_context(c1) assert (len(s1.list_contexts()) == 0) s2 = saga.Session() js = saga.job.Service("fork://localhost", session=s1) jd = saga.job.Description() print repr(js.get_session()) js = saga.job.Service("fork://localhost", session=s2) jd = saga.job.Description() print repr(js.get_session()) s1.add_context(c1) s1.add_context(c1) js = saga.job.Service("fork://localhost") js_s = js.get_session() js_s.add_context(c1) jk = saga.job.Service("fork://localhost") jk_c = js.get_session().list_contexts()[0] assert (jk_c.userkey == "/Users/s1063117/id_rsa") print jk_c.type except saga.Exception, ex: print str(ex)
class ContextTests(unittest.TestCase): """ Tests for the saga.job.Description API """ def setUp(self): # Fixture: # called immediately before calling the test method FILE1 = open("/tmp/bliss-test.file1", "w", 0) FILE1.close() FILE2 = open("/tmp/bliss-test.file2", "w", 0) FILE2.close() def tearDown(self): # Fixture: # called immediately after the test method has been called if os.path.isfile("/tmp/bliss-test.file1"): os.remove("/tmp/bliss-test.file1") if os.path.isfile("/tmp/bliss-test.file2"): os.remove("/tmp/bliss-test.file2") ########################################################################### # def test_context_type_SSH(self): c1 = saga.Context() c1.type = saga.Context.SSH c1.userkey = ("/tmp/bliss-test.file1") try: c1.userkey = ("non_existing_file_2345435") self.fail("'userkey' shouldn't accept a non-exsisting file'") except saga.Exception, e: pass s1 = saga.Session() s1.add_context(c1) s1.add_context(c1) s1.add_context(c1) js = saga.job.Service("fork://localhost") js_s = js.get_session() js_s.add_context(c1) jk = saga.job.Service("fork://localhost") found = False for ctx in js.get_session().list_contexts(): if ctx.type == saga.Context.SSH: if ctx == c1: found = True assert (ctx.userkey == "/tmp/bliss-test.file1") if not found: self.fail("Coulnd't find context!")
def main(): try: ctx = saga.Context() ctx.type = saga.Context.SSH ctx.userid = 'oweidner' # your identity on the remote machine #ctx.userkey = '/Users/oweidner/.ssh/rsa_work' ses = saga.Session() ses.contexts.append(ctx) # create a job service for lonestar js = saga.job.Service("ssh://localhost") # describe our job jd = saga.job.Description() jd.environment = {'MYOUTPUT': '"Hello from SAGA"'} jd.executable = '/bin/echo' jd.arguments = ['$MYOUTPUT'] jd.output = "myjob.stdout" jd.error = "myjob.stderr" # create the job (state: New) myjob = js.create_job(jd) print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...starting job...\n" # run the job myjob.run() print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...waiting for job...\n" # wait for the job to either finish or fail myjob.wait() print "Job State : %s" % (myjob.get_state()) print "Exitcode : %s" % (myjob.exitcode) outfilesource = 'sftp://localhost/Users/oweidner/myjob.stdout' outfiletarget = 'file://localhost/tmp/' out = saga.filesystem.File(outfilesource, session=ses) out.copy(outfiletarget) print "Staged out %s to %s (size: %s bytes)" % ( outfilesource, outfiletarget, out.get_size()) except saga.Exception, ex: print "An error occured during job execution: %s" % (str(ex)) sys.exit(-1)
def main(): try: ctx = saga.Context() ctx.type = saga.Context.SSH ctx.userid = 'oweidner' # your identity on the remote machine #ctx.userkey = '/Users/oweidner/.ssh/rsa_work' ses = saga.Session() ses.contexts.append(ctx) # create a job service for lonestar js = saga.job.Service("pbs+ssh://india.futuregrid.org") # describe our job jd = saga.job.Description() jd.environment = {'MYOUTPUT':'"Hello from SAGA"'} jd.executable = '/bin/echo' jd.arguments = ['$MYOUTPUT'] jd.output = "my1stjob.stdout" jd.error = "my1stjob.stderr" # create the job (state: New) myjob = js.create_job(jd) print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...starting job...\n" # run the job myjob.run() print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...waiting for job...\n" # wait for the job to either finish or fail myjob.wait() print "Job State : %s" % (myjob.get_state()) print "Exitcode : %s" % (myjob.exitcode) except saga.Exception, ex: print "An error occured during job execution: %s" % (str(ex)) sys.exit(-1)
def run(url, username): """Test if we can lists a (remote) directory """ try: failed = False ctx = saga.Context() ctx.type = saga.Context.SSH ctx.userid = username # like 'ssh username@host ...' session = saga.Session() session.contexts.append(ctx) mydir = saga.filesystem.Directory(url, session=session) for entry in mydir.list(): print entry except saga.Exception, ex: failed = True why = str(ex)
def main(): try: # set up a security context (optional) # if no security context is defined, the PBS # plugin will pick up the default set of ssh # credentials of the user, i.e., ~/.ssh/id_rsa ctx = saga.Context() ctx.type = saga.Context.SSH ctx.userid = 'oweidner' # like 'ssh username@host ...' ctx.usercert = '/Users/s1063117/.ssh/id_rsa' # like ssh -i ...' session = saga.Session() session.contexts.append(ctx) mydir = saga.filesystem.Directory("sftp://india.futuregrid.org/tmp", session=session) for entry in mydir.list(): print entry except saga.Exception, ex: print "Oh, snap! An error occured: %s" % (str(ex))
def main(): try: # set up a security context (optional) # if no security context is defined, the PBS # plugin will pick up the default set of ssh # credentials of the user, i.e., ~/.ssh/id_rsa ctx = saga.Context() ctx.type = saga.Context.SSH ctx.userid = 'oweidner' # like 'ssh username@host ...' ctx.usercert = '/Users/s1063117/.ssh/id_rsa' # like ssh -i ...' session = saga.Session() session.contexts.append(ctx) # open home directory on a remote machine mydir = saga.filesystem.Directory("sftp://queenbee.loni.org/home/oweidner", session=session) # copy .bash_history to /tmp/ on the local machine mydir.copy('.bash_history', 'sftp://localhost/tmp/') except saga.Exception, ex: print "Oh, snap! An error occured: %s" % (str(ex))
except saga.Exception, ex: print "An error occured: %s" % (str(ex)) sys.exit(-1) if __name__ == "__main__": NUMJOBS = 32 execution_host = saga.Url("pbs+ssh://queenbee.loni.org") ctx = saga.Context() ctx.type = saga.Context.SSH ctx.userid = 'oweidner' # like 'ssh username@host ...' ctx.userkey = '/Users/s1063117/.ssh/id_rsa' # like ssh -i ...' session = saga.Session() session.contexts.append(ctx) js = saga.job.Service(execution_host, session) print "\n-------------------------------------" print "Submitting %s jobs sequentially" % NUMJOBS total_time = 0.0 for i in range (0, NUMJOBS): total_time += run_bfast(i, session, js) print "\n-------------------------------------" print "Total elapsed time: %.0fs\n" % total_time
c1.type = saga.Context.EC2 c1.userkey = "/tmp/bliss-test.file1" try: c1.userkey = ("non_existing_file_2345435") self.fail("'userkey' shouldn't accept a non-exsisting file'") except saga.Exception, e: pass c1.usercert = "/tmp/bliss-test.file2" try: c1.usercert = ("non_existing_file_2345435") self.fail("'usercert' shouldn't accept a non-exsisting file'") except saga.Exception, e: pass s1 = saga.Session() s1.add_context(c1) s1.add_context(c1) s1.add_context(c1) js = saga.job.Service("fork://localhost") js_s = js.get_session() js_s.add_context(c1) jk = saga.job.Service("fork://localhost") found = False for ctx in js.get_session().list_contexts(): if ctx.type == saga.Context.EC2: if ctx == c1: found = True
def main(): try: # Optional: # Set up a security context # if no security context is defined, the SFTP # plugin will pick up the default set of ssh # credentials of the user, i.e., ~/.ssh/id_rsa # ctx = saga.Context() ctx.type = saga.Context.SSH ctx.userid = 'oweidner1' # like 'ssh username@host ...' #ctx.userkey = '/Users/oweidner/.ssh/rsa_work' # like ssh -i ...' # Optional: # Append the custom security context to the session session = saga.Session() session.contexts.append(ctx) # create a job service for Futuregrid's 'india' PBS cluster # and attach the SSH security context to it #js = saga.job.Service("pbs+ssh://india.futuregrid.org") # Alternatively: # Use custom session js = saga.job.Service("pbs+ssh://india.futuregrid.org", session=session) # describe our job jd = saga.job.Description() # resource requirements jd.wall_time_limit = 5 #minutes jd.total_cpu_count = 1 # environment, executable & arguments jd.environment = {'HELLO': "\"Hello SAGA\""} jd.executable = '/bin/echo' jd.arguments = ['$HELLO'] # output options jd.output = "bliss_pbssh_job.stdout" jd.error = "bliss_pbssh_job.stderr" # create the job (state: New) myjob = js.create_job(jd) print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...starting job...\n" # run the job (submit the job to PBS) myjob.run() print "Job ID : %s" % (myjob.jobid) print "Job State : %s" % (myjob.get_state()) print "\n...waiting for job...\n" # wait for the job to either finish or fail myjob.wait() print "Job State : %s" % (myjob.get_state()) print "Exitcode : %s" % (myjob.exitcode) except saga.Exception, ex: print "An error occured during job execution: %s" % (str(ex)) sys.exit(-1)