Beispiel #1
0
    def test_20_do_task__ignore_permission_denied_error(self):
        if os.getuid() == 0:
            print("Skip this test because you're root.")
            return

        task = SH.Task("touch /root/.bashrc", workdir="/root", timeout=10)
        self.assertNotEquals(SH.do_task(task, stop_on_error=False), 0)
Beispiel #2
0
    def test_01___init__remote_host(self):
        (cmd, user, host, workdir, timeout) = \
            ("true", "foo", "www.example.com", "/tmp", 1)
        task = SH.Task(cmd, user, host, workdir, timeout)

        U.typecheck(task, SH.Task)

        self.assertNotEquals(task.cmd, cmd)
        self.assertEquals(task.user, user)
        self.assertEquals(task.host, host)
        self.assertNotEquals(task.workdir, workdir)
        self.assertEquals(task.timeout, timeout)
Beispiel #3
0
    def test_00___init__(self):
        (cmd, user, host, workdir, timeout) = \
            ("true", "foo", "localhost", "/tmp", 1)
        task = SH.Task(cmd, user, host, workdir, timeout)

        U.typecheck(task, SH.Task)

        self.assertEquals(task.cmd, cmd)
        self.assertEquals(task.user, user)
        self.assertEquals(task.host, host)
        self.assertEquals(task.workdir, workdir)
        self.assertEquals(task.timeout, timeout)
Beispiel #4
0
    def test_02___init__homedir(self):
        (cmd, user, host, workdir, timeout) = \
            ("true", E.get_username(), "localhost", "~/", 1)
        task = SH.Task(cmd, user, host, workdir, timeout)

        U.typecheck(task, SH.Task)

        self.assertEquals(task.cmd, cmd)
        self.assertEquals(task.user, user)
        self.assertEquals(task.host, host)
        self.assertNotEquals(task.workdir, workdir)
        self.assertEquals(task.workdir, os.path.expanduser(workdir))
        self.assertEquals(task.timeout, timeout)
Beispiel #5
0
    def test_10_do_task__w_permission_denied_error(self):
        if os.getuid() == 0:
            print("Skip this test because you're root.")
            return

        # It seems that neighther 'subprocess.Popen("true",
        # cwd="/root").wait()' nor 'subprocess.Popen("cd /root && true",
        # shell=True).wait()' does not raise any exceptions these days:
        # task = SH.Task("true", workdir="/root", timeout=10)
        # task = SH.Task("cd /root && true", workdir="/root", timeout=10)

        task = SH.Task("touch /root/.bashrc", timeout=10)

        with self.assertRaises(SH.TaskError):
            SH.do_task(task, stop_on_error=True)
Beispiel #6
0
 def test_00_prun(self):
     tasks = [SH.Task("true", timeout=10) for _ in range(PRUN_JOBS)]
     self.assertTrue(all(rc == 0 for rc in SH.prun(tasks)))
Beispiel #7
0
    def test_31_do_task__timeout__w_rc(self):
        task = SH.Task("sleep 10", timeout=1)

        self.assertNotEquals(SH.do_task(task, stop_on_error=False), 0)
Beispiel #8
0
    def test_30_do_task__timeout(self):
        task = SH.Task("sleep 10", timeout=1)

        with self.assertRaises(SH.TaskError):
            SH.do_task(task)
Beispiel #9
0
 def test_02_do_task__no_errors_but_not_return_0(self):
     task = SH.Task("false", timeout=10)
     self.assertNotEquals(SH.do_task(task, stop_on_error=False), 0)
Beispiel #10
0
    def test_01_do_task__no_errors_but_not_return_0_and_exception_raised(self):
        task = SH.Task("false", timeout=10)

        with self.assertRaises(SH.TaskError):
            SH.do_task(task)
Beispiel #11
0
 def test_00_do_task__no_errors(self):
     task = SH.Task("true", timeout=10)
     self.assertEquals(SH.do_task(task), 0)