示例#1
0
 def testReturncode(self, cmd1, cmd2, returncode):
     p1 = v2v._simple_exec_cmd([cmd1], stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd([cmd2],
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     p.wait(self.PROC_WAIT_TIMEOUT)
     self.assertEqual(p.returncode, returncode)
示例#2
0
 def testReturncode(self, cmd1, cmd2, returncode):
     p1 = v2v._simple_exec_cmd([cmd1],
                               stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd([cmd2],
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     p.wait(self.PROC_WAIT_TIMEOUT)
     self.assertEqual(p.returncode, returncode)
示例#3
0
 def testWait(self, cmd1, cmd2, waitRet):
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd(cmd2,
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     ret = p.wait(2)
     p.kill()
     self.assertEqual(ret, waitRet)
示例#4
0
 def testWait(self, cmd1, cmd2, waitRet):
     p1 = v2v._simple_exec_cmd(cmd1,
                               stdout=subprocess.PIPE)
     p2 = v2v._simple_exec_cmd(cmd2,
                               stdin=p1.stdout,
                               stdout=subprocess.PIPE)
     p = v2v.PipelineProc(p1, p2)
     ret = p.wait(2)
     p.kill()
     self.assertEqual(ret, waitRet)
示例#5
0
 def testReturncode(self, cmd1, cmd2, returncode):
     p1 = v2v._simple_exec_cmd([cmd1], stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd([cmd2],
                                   stdin=p1.stdout,
                                   stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             p.wait(self.PROC_WAIT_TIMEOUT)
             assert p.returncode == returncode
示例#6
0
 def testWait(self, cmd1, cmd2):
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(cmd2,
                                   stdin=p1.stdout,
                                   stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             assert ret is False
示例#7
0
文件: v2v_test.py 项目: nirs/vdsm
 def testWait(self, cmd1, cmd2):
     p1 = v2v._simple_exec_cmd(cmd1,
                               stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(cmd2,
                                   stdin=p1.stdout,
                                   stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, False)
示例#8
0
文件: v2v_test.py 项目: vjuranek/vdsm
 def test_wait_on_two_processes_that_finished(self):
     cmd = ['sleep', str(SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             # Wait for the processes to finish.
             time.sleep(2 * SHORT_SLEEP)
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
示例#9
0
文件: v2v_test.py 项目: nirs/vdsm
 def test_wait_on_two_processes_that_finish_before_timeout(self):
     cmd1 = ['sleep', str(SHORT_SLEEP)]
     cmd2 = ['sleep', str(1.5 * SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd2, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             # Processes finish at different times but before the timeout.
             ret = p.wait(3 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
示例#10
0
文件: v2v_test.py 项目: nirs/vdsm
 def test_wait_on_two_processes_that_finished(self):
     cmd = ['sleep', str(SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             # Wait for the processes to finish.
             time.sleep(2 * SHORT_SLEEP)
             p = v2v.PipelineProc(p1, p2)
             ret = p.wait(2 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
示例#11
0
文件: v2v_test.py 项目: vjuranek/vdsm
 def test_wait_on_two_processes_that_finish_before_timeout(self):
     cmd1 = ['sleep', str(SHORT_SLEEP)]
     cmd2 = ['sleep', str(1.5 * SHORT_SLEEP)]
     p1 = v2v._simple_exec_cmd(cmd1, stdout=subprocess.PIPE)
     with terminating(p1):
         p2 = v2v._simple_exec_cmd(
             cmd2, stdin=p1.stdout, stdout=subprocess.PIPE)
         with terminating(p2):
             p = v2v.PipelineProc(p1, p2)
             # Processes finish at different times but before the timeout.
             ret = p.wait(3 * SHORT_SLEEP)
             p.kill()
             self.assertEqual(ret, True)
示例#12
0
    def testRun(self):
        msg = 'foo\nbar'
        p1 = v2v._simple_exec_cmd(['echo', '-n', msg], stdout=subprocess.PIPE)
        p2 = v2v._simple_exec_cmd(['cat'],
                                  stdin=p1.stdout,
                                  stdout=subprocess.PIPE)

        p = v2v.PipelineProc(p1, p2)
        self.assertEqual(p.pids, [p1.pid, p2.pid])

        ret = p.wait(self.PROC_WAIT_TIMEOUT)
        self.assertEqual(ret, True)

        out = p.stdout.read()
        self.assertEqual(out, msg)
示例#13
0
    def testWait(self, cmd1, cmd2, waitRet):
        if six.PY3 and waitRet:
            raise SkipTest('broken on Python 3')

        p1 = v2v._simple_exec_cmd(cmd1,
                                  stdout=subprocess.PIPE)
        with terminating(p1):
            p2 = v2v._simple_exec_cmd(cmd2,
                                      stdin=p1.stdout,
                                      stdout=subprocess.PIPE)
            with terminating(p2):
                p = v2v.PipelineProc(p1, p2)
                ret = p.wait(2 * SHORT_SLEEP)
                p.kill()
                self.assertEqual(ret, waitRet)
示例#14
0
    def testRun(self):
        msg = 'foo\nbar'
        p1 = v2v._simple_exec_cmd(['echo', '-n', msg],
                                  stdout=subprocess.PIPE)
        p2 = v2v._simple_exec_cmd(['cat'],
                                  stdin=p1.stdout,
                                  stdout=subprocess.PIPE)

        p = v2v.PipelineProc(p1, p2)
        self.assertEqual(p.pids, [p1.pid, p2.pid])

        ret = p.wait(self.PROC_WAIT_TIMEOUT)
        self.assertEqual(ret, True)

        out = p.stdout.read()
        self.assertEqual(out, msg)
示例#15
0
    def testRun(self):
        msg = 'foo\nbar'
        p1 = v2v._simple_exec_cmd(['echo', '-n', msg], stdout=subprocess.PIPE)
        with terminating(p1):
            p2 = v2v._simple_exec_cmd(['cat'],
                                      stdin=p1.stdout,
                                      stdout=subprocess.PIPE)
            with terminating(p2):
                p = v2v.PipelineProc(p1, p2)
                assert p.pids == [p1.pid, p2.pid]

                ret = p.wait(self.PROC_WAIT_TIMEOUT)
                assert ret is True

                out = p.stdout.read()
                assert out == msg.encode()
示例#16
0
    def testSimpleExecCmd(self):
        p = v2v._simple_exec_cmd(['cat'],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
        msg = "test\ntest"
        p.stdin.write(msg.encode())
        p.stdin.close()
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())

        p = v2v._simple_exec_cmd(['/bin/sh', '-c', 'echo -en "%s" >&2' % msg],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())
示例#17
0
文件: v2v_test.py 项目: nirs/vdsm
    def testSimpleExecCmd(self):
        p = v2v._simple_exec_cmd(['cat'],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
        msg = "test\ntest"
        p.stdin.write(msg.encode())
        p.stdin.close()
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())

        p = v2v._simple_exec_cmd(['/bin/sh', '-c', 'echo -en "%s" >&2' % msg],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
        p.wait()
        out = p.stdout.read()
        self.assertEqual(out, msg.encode())