示例#1
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)
             self.assertEqual(p.returncode, returncode)
示例#2
0
文件: v2v_test.py 项目: EdDev/vdsm
 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)
             self.assertEqual(p.returncode, returncode)
示例#3
0
 def testWait(self, cmd1, cmd2, waitRet):
     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)
             p.kill()
             self.assertEqual(ret, waitRet)
示例#4
0
文件: v2v_test.py 项目: EdDev/vdsm
 def testWait(self, cmd1, cmd2, waitRet):
     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)
             p.kill()
             self.assertEqual(ret, waitRet)
示例#5
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)
示例#6
0
    def check_failure(self):
        with self.assertRaises(utils.TerminatingFailure) as e:
            with utils.terminating(self.proc):
                self.assertIsNone(self.proc_poll())

        self.assertEqual(e.exception.pid, self.proc.pid)
        self.assertEqual(type(e.exception.error), ExpectedFailure)
示例#7
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)
                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)
示例#8
0
文件: utilsTests.py 项目: rexhsu/vdsm
 def test_terminating_with_infected_kill(self):
     with MonkeyPatchScope([(zombiereaper, 'autoReapPID', self.reaped.add)
                            ]):
         self.proc.kill = lambda: None
         with utils.terminating(self.proc):
             self.assertTrue(os.path.exists(self.proc_path))
         self.assertTrue(self.proc.pid in self.reaped)
示例#9
0
文件: utils_test.py 项目: EdDev/vdsm
    def check_failure(self):
        with self.assertRaises(utils.TerminatingFailure) as e:
            with utils.terminating(self.proc):
                self.assertIsNone(self.proc_poll())

        self.assertEqual(e.exception.pid, self.proc.pid)
        self.assertEqual(type(e.exception.error), ExpectedFailure)
示例#10
0
文件: v2v_test.py 项目: EdDev/vdsm
    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)
                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)
示例#11
0
 def test_terminating_with_infected_kill(self):
     with MonkeyPatchScope([(zombiereaper,
                             'autoReapPID',
                             self.reaped.add
                             )]):
         self.proc.kill = lambda: None
         with utils.terminating(self.proc):
             self.assertTrue(os.path.exists(self.proc_path))
         self.assertTrue(self.proc.pid in self.reaped)
示例#12
0
文件: utils_test.py 项目: EdDev/vdsm
    def test_process_terminated(self):
        self.proc.terminate()
        self.proc.wait()

        def fail():
            raise RuntimeError("Attempt to kill a terminated process")

        self.proc.kill = fail
        with utils.terminating(self.proc):
            pass
        self.assertEqual(self.proc.returncode, -signal.SIGTERM)
示例#13
0
    def test_process_zombie(self):
        self.proc.terminate()
        wait_for_zombie(self.proc, 1)

        def fail():
            raise RuntimeError("Attempt to kill a zombie process")

        self.proc.kill = fail
        with utils.terminating(self.proc):
            pass
        self.assertEqual(self.proc.returncode, -signal.SIGTERM)
示例#14
0
    def test_process_terminated(self):
        self.proc.terminate()
        self.proc.wait()

        def fail():
            raise RuntimeError("Attempt to kill a terminated process")

        self.proc.kill = fail
        with utils.terminating(self.proc):
            pass
        self.assertEqual(self.proc.returncode, -signal.SIGTERM)
示例#15
0
文件: utils_test.py 项目: EdDev/vdsm
    def test_process_zombie(self):
        self.proc.terminate()
        wait_for_zombie(self.proc, 1)

        def fail():
            raise RuntimeError("Attempt to kill a zombie process")

        self.proc.kill = fail
        with utils.terminating(self.proc):
            pass
        self.assertEqual(self.proc.returncode, -signal.SIGTERM)
示例#16
0
    def test_terminating_with_kill_exception(self):
        class FakeKillError(Exception):
            pass

        def fake_kill():
            raise FakeKillError("fake kill exception")

        self.proc.kill = fake_kill
        with utils.terminating(self.proc):
            self.assertIsNone(self.proc.poll())

        self.assertIsNone(self.proc.returncode)
示例#17
0
文件: utilsTests.py 项目: rexhsu/vdsm
    def test_terminating_with_kill_exception(self):
        class FakeKillError(Exception):
            pass

        def fake_kill():
            raise FakeKillError("fake kill exception")

        with MonkeyPatchScope([(zombiereaper, 'autoReapPID', self.reaped.add)
                               ]):
            self.proc.kill = fake_kill
            with utils.terminating(self.proc):
                self.assertTrue(os.path.exists(self.proc_path))
            self.assertTrue(self.proc.pid not in self.reaped)
示例#18
0
def copyFromImage(dstImgPath, methodArgs):
    fileObj = methodArgs['fileObj']
    bytes_left = total_size = methodArgs['length']
    cmd = [
        constants.EXT_DD,
        "if=%s" % dstImgPath,
        "bs=%s" % constants.MEGAB,
        "count=%s" % (total_size / constants.MEGAB + 1)
    ]

    p = commands.execCmd(cmd, sync=False)
    p.blocking = True
    with utils.terminating(p):
        _copyData(p.stdout, fileObj, bytes_left)
示例#19
0
    def test_terminating_with_kill_exception(self):
        class FakeKillError(Exception):
            pass

        def fake_kill():
            raise FakeKillError("fake kill exception")

        self.proc.kill = fake_kill
        with self.assertRaises(utils.TerminatingFailure) as e:
            with utils.terminating(self.proc):
                self.assertIsNone(self.proc.poll())

        self.assertEqual(e.exception.pid, self.proc.pid)
        self.assertEqual(type(e.exception.error), FakeKillError)
        self.assertIsNone(self.proc.returncode)
示例#20
0
    def test_terminating_with_kill_exception(self):
        class FakeKillError(Exception):
            pass

        def fake_kill():
            raise FakeKillError("fake kill exception")

        with MonkeyPatchScope([(zombiereaper,
                                'autoReapPID',
                                self.reaped.add
                                )]):
            self.proc.kill = fake_kill
            with utils.terminating(self.proc):
                self.assertTrue(os.path.exists(self.proc_path))
            self.assertTrue(self.proc.pid not in self.reaped)
示例#21
0
def copyToImage(dstImgPath, methodArgs):
    totalSize = getLengthFromArgs(methodArgs)
    fileObj = methodArgs['fileObj']
    cmd = [constants.EXT_DD, "of=%s" % dstImgPath, "bs=%s" % constants.MEGAB]
    p = commands.execCmd(cmd, sync=False)
    with utils.terminating(p):
        _copyData(fileObj, p.stdin, totalSize)
        p.stdin.close()
        if not p.wait(WAIT_TIMEOUT):
            log.error("timeout waiting for dd process")
            raise se.StorageException()

        if p.returncode != 0:
            log.error("dd error - code %s, stderr %s", p.returncode,
                      p.stderr.read(1000))
            raise se.MiscFileWriteException()
示例#22
0
文件: v2v.py 项目: gobindadas/vdsm
    def _query_v2v_caps(self):
        self._v2v_caps = frozenset()
        p = _simple_exec_cmd([_VIRT_V2V.cmd, '--machine-readable'],
                             env=os.environ.copy(),
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        with terminating(p):
            try:
                out, err = p.communicate()
            except Exception:
                logging.exception('Terminating virt-v2v process after error')
                raise
        if p.returncode != 0:
            raise V2VProcessError('virt-v2v exited with code: %d, stderr: %r' %
                                  (p.returncode, err))

        self._v2v_caps = frozenset(out.splitlines())
        logging.debug("Detected virt-v2v capabilities: %r", self._v2v_caps)
示例#23
0
文件: v2v.py 项目: EdDev/vdsm
    def _query_v2v_caps(self):
        self._v2v_caps = frozenset()
        p = _simple_exec_cmd([_VIRT_V2V.cmd, '--machine-readable'],
                             env=os.environ.copy(),
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        with terminating(p):
            try:
                out, err = p.communicate()
            except Exception:
                logging.exception('Terminating virt-v2v process after error')
                raise
        if p.returncode != 0:
            raise V2VProcessError(
                'virt-v2v exited with code: %d, stderr: %r' %
                (p.returncode, err))

        self._v2v_caps = frozenset(out.splitlines())
        logging.debug("Detected virt-v2v capabilities: %r", self._v2v_caps)
示例#24
0
 def test_terminating(self):
     with utils.terminating(self.proc):
         self.assertIsNone(self.proc.poll())
     proc_path = "/proc/%d" % self.proc.pid
     self.assertTrue(wait_for_removal(proc_path, timeout=1))
示例#25
0
 def test_terminating(self):
     with utils.terminating(self.proc):
         self.assertIsNone(self.proc.poll())
     self.assertEqual(self.proc.returncode, -signal.SIGKILL)
示例#26
0
 def test_terminating(self):
     with utils.terminating(self.proc):
         self.assertTrue(os.path.exists(self.proc_path))
     self.assertTrue(wait_for_removal(self.proc_path, timeout=1))
示例#27
0
文件: utilsTests.py 项目: rexhsu/vdsm
 def test_terminating(self):
     with utils.terminating(self.proc):
         self.assertTrue(os.path.exists(self.proc_path))
     self.assertTrue(wait_for_removal(self.proc_path, timeout=1))
示例#28
0
文件: utils_test.py 项目: EdDev/vdsm
 def test_process_running(self):
     with utils.terminating(self.proc):
         self.assertIsNone(self.proc_poll())
     self.assertEqual(self.proc.returncode, -signal.SIGKILL)