Пример #1
0
    def _test_process(self, run_as_root):
        test_pid = str(os.getppid())
        cmd = ['bash', '-c', '(sleep 10)']
        proc = async_process.AsyncProcess(cmd, run_as_root=run_as_root)
        proc.start()
        self.addCleanup(self._stop_process, proc)
        common_utils.wait_until_true(lambda: proc._process.pid,
                                     sleep=0.5,
                                     timeout=10)

        bash_pid = utils.find_parent_pid(proc._process.pid)
        testcase_pid = utils.find_parent_pid(bash_pid)
        self.assertEqual(test_pid, testcase_pid)
Пример #2
0
 def test_raises_unknown_exception(self):
     with testtools.ExpectedException(RuntimeError):
         self.m_execute.side_effect = RuntimeError()
         utils.find_parent_pid(-1)
Пример #3
0
 def test_raises_exception_returncode_0(self):
     with testtools.ExpectedException(exceptions.ProcessExecutionError):
         self.m_execute.side_effect = \
             exceptions.ProcessExecutionError('', returncode=0)
         utils.find_parent_pid(-1)
Пример #4
0
 def test_returns_parent_id_for_good_ouput(self):
     self.m_execute.return_value = '123 \n'
     self.assertEqual(utils.find_parent_pid(-1), '123')
Пример #5
0
 def test_returns_none_for_no_valid_pid(self):
     self.m_execute.side_effect = exceptions.ProcessExecutionError(
         '', returncode=1)
     self.assertIsNone(utils.find_parent_pid(-1))