Пример #1
0
    def test_job_multiline_run(self):
        """ Test job.run() with multiline command
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = '/bin/sh'
            jd.arguments = [
                """-c "python -c '
import time
if True:
  if 1:
    time.sleep(3)
' " """
            ]

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()

            assert (j.state in [rs.job.RUNNING, rs.job.PENDING])
            j.wait()
            assert (j.state in [rs.job.DONE])

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #2
0
    def test_job_run_many(self):
        """ Run a bunch of jobs concurrently via the same job service.
        """
        num_jobs = 32
        jobs = list()
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['30']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            for _ in range(0, num_jobs):
                j = self.js.create_job(jd)
                jobs.append(j)

            # start all jobs
            for job in jobs:
                job.run()

            for job in jobs:
                job.cancel()
                assert job.state == rs.job.CANCELED

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(jobs)
Пример #3
0
    def test_job_suspend_resume(self):
        """ Test job.suspend()/resume() - expecting state: SUSPENDED/RUNNING
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = '/bin/sleep'
            jd.arguments = ['20']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()
            j.suspend()

            assert j.state == rs.job.SUSPENDED
            assert j.state == j.get_state()

            j.resume()
            assert j.state == rs.job.RUNNING
            assert j.state == j.get_state()

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #4
0
    def test_get_id(self):
        """ Test job.get_id() / job.id
        """

        j = None
        try:

            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()

            assert j.id is not None
            assert j.id == j.get_id()

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #5
0
def helper_multiple_services(i):

    cfg = config()
    js1 = rs.job.Service(cfg.job_service_url, cfg.session)
    js2 = rs.job.Service(cfg.job_service_url, cfg.session)
    jd = rs.job.Description()

    jd.executable = '/bin/sleep'
    jd.arguments = ['3']
    jd = sutc.configure_jd(cfg=cfg, jd=jd)

    j1 = js1.create_job(jd)
    j2 = js2.create_job(jd)
    j1.run()
    j2.run()

    assert (j1.state in [rs.job.RUNNING, rs.job.PENDING])
    assert (j2.state in [rs.job.RUNNING, rs.job.PENDING])

    j1.wait()
    j2.wait()

    assert (j1.state == rs.job.DONE)
    assert (j2.state == rs.job.DONE)

    _silent_close_js(js1)
Пример #6
0
def test_get_job():
    """ Test to submit a job, and retrieve it by id """
    j = None
    js = None
    try:
        cfg = config()
        js = rs.job.Service(cfg.job_service_url, cfg.session)

        # create job service and job
        jd = rs.job.Description()
        jd.executable = '/bin/sleep'
        jd.arguments = ['10']

        # add options from the test .cfg file if set
        jd = sutc.configure_jd(cfg=cfg, 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 rs.NotImplemented as ni:
        assert cfg.notimpl_warn_only, "%s " % ni
        if cfg.notimpl_warn_only:
            print("%s " % ni)
    except rs.SagaException as se:
        assert False, "Unexpected exception: %s" % se
    finally:
        _silent_cancel(j)
        _silent_close_js(js)
Пример #7
0
def test_list_jobs():
    """ Test if a submitted job shows up in Service.list() """
    j = None
    js = None
    try:
        cfg = config()
        js = rs.job.Service(cfg.job_service_url, cfg.session)

        # create job service and job
        jd = rs.job.Description()
        jd.executable = '/bin/sleep'
        jd.arguments = ['10']

        # add options from the test .cfg file if set
        jd = sutc.configure_jd(cfg=cfg, 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 rs.NotImplemented as ni:
        assert cfg.notimpl_warn_only, "%s " % ni
        if cfg.notimpl_warn_only:
            print("%s " % ni)
    except rs.SagaException as se:
        assert False, "Unexpected exception: %s" % se
    finally:
        _silent_cancel(j)
        _silent_close_js(js)
Пример #8
0
    def test_job_wait(self):
        """
        Test job.wait() - expecting state: DONE
        """

        j = None
        try:
            t_min = time.time()
            time.sleep(0.1)

            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments  = ['2']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()
            j.wait()

            time.sleep(0.5)
            t_max = time.time()

            # assert success
            assert(j.state == rs.job.DONE), "%s != %s" % (j.state, rs.job.DONE)

            print t_min
            print j.created
            print j.started
            print j.finished
            print t_max

            # expect job time information is be reported in seconds since epoch
            assert(int(t_min) <= int(j.created ) <= int(t_max))
            assert(int(t_min) <= int(j.started ) <= int(t_max))
            assert(int(t_min) <= int(j.finished) <= int(t_max))

            assert(int(j.created) <= int(j.started))
            assert(int(j.started) <= int(j.finished))

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #9
0
    def test_get_service_url(self):
        """ Test if job.service_url == Service.url
        """
        j = None
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)

            assert j.service_url == self.js.url

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #10
0
    def test_job_service_create(self):
        """ Test service.create_job() - expecting state 'NEW'
        """
        j = None
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            assert j.state == j.get_state()
            assert j.state == rs.job.NEW

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #11
0
    def test_get_exit_code(self):
        """ Test job.exit_code
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = "/bin/sleep"

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()
            j.wait()

            ec = j.exit_code
            assert ec == 1, "%s != 1" % ec

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #12
0
    def test_job_cancel(self):
        """ Test job.cancel() - expecting state: CANCELED
        """
        j = None
        try:
            jd = rs.job.Description()
            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)

            j.run()
            j.cancel()
            assert j.state == rs.job.CANCELED

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #13
0
    def test_job_run(self):
        """ Test job.run() - expecting state: RUNNING/PENDING
        """
        j = None
        try:
            jd = rs.job.Description()

            jd.executable = '/bin/sleep'
            jd.arguments = ['10']

            # add options from the test .cfg file if set
            sutc.configure_jd(self.cfg, jd)

            j = self.js.create_job(jd)
            j.run()

            assert (j.state in [rs.job.RUNNING, rs.job.PENDING])

        except rs.SagaException as e:
            sutc.assert_exception(self.cfg, e)

        finally:
            sutc.silent_cancel(j)
Пример #14
0
    def test_get_stdio(self):
        """ Test job.get_stdin/get_stdout/get_log
        """

        j = None
        try:
            cfg = config()
            jd = rs.job.Description()

            jd.pre_exec = ['echo pre']
            jd.executable = 'sh'
            jd.arguments = ['-c', '"echo out; echo err 1>&2"']
            jd.post_exec = ['echo post']

            # add options from the test .cfg file if set
            jd = sutc.configure_jd(cfg=cfg, jd=jd)
            j = self.js.create_job(jd)

            j.run()
            j.wait()

            assert 0 == j.exit_code

            assert 'pre' in j.get_log()
            assert 'post' in j.get_log()
            assert 'out' in j.get_stdout()
            assert 'err' in j.get_stderr()

            assert 'pre' in j.log
            assert 'post' in j.log
            assert 'out' in j.stdout
            assert 'err' in j.stderr

        except rs.NotImplemented as ni:
            assert cfg.notimpl_warn_only, "%s " % ni
            if cfg.notimpl_warn_only:
                print("%s " % ni)

        except rs.SagaException as se:
            assert False, "Unexpected exception: %s" % se

        finally:
            _silent_cancel(j)