예제 #1
0
    def starting(self):
        """Starting the rpyc service on remote host"""

        cmd = self.cfg.ssh_cmd(
            self.ssh_cfg,
            " ".join([
                self.python_binary,
                "-uB",
                self.cfg.rpyc_bin,
                "--host",
                "0.0.0.0",
                "-p",
                "0",
            ]),
        )

        self.proc = subprocess_popen(
            cmd,
            stdin=subprocess.PIPE,
            stdout=self.std.out,
            stderr=self.std.err,
            cwd=self.runpath,
        )

        self.logger.debug(f"{self} executes cmd: {cmd}\n"
                          f"\tRunpath: {self.runpath}\n"
                          f"\tPid: {self.proc.pid}\n"
                          f"\tOut file: {self.std.out_path}\n"
                          f"\tErr file: {self.std.err_path}\n")
예제 #2
0
파일: base.py 프로젝트: cpages/testplan
    def get_test_context(self):
        """
        Run the shell command generated by `list_command` in a subprocess,
        parse and return the stdout generated via `parse_test_context`.

        :return: Result returned by `parse_test_context`.
        :rtype: ``list`` of ``list``
        """
        cmd = self.list_command()  # pylint: disable=assignment-from-none
        if cmd is None:
            return [(self._DEFAULT_SUITE_NAME, ())]

        proc = subprocess_popen(
            cmd,
            cwd=self.cfg.proc_cwd,
            env=self.cfg.proc_env,
            stdout=subprocess.PIPE,
        )

        test_list_output = proc.communicate()[0]

        # with python3, stdout is bytes so need to decode.
        if not isinstance(test_list_output, str):
            test_list_output = test_list_output.decode(sys.stdout.encoding)

        return self.parse_test_context(test_list_output)
예제 #3
0
파일: base.py 프로젝트: kelliott55/testplan
    def get_test_context(self, list_cmd=None):
        """
        Run the shell command generated by `list_command` in a subprocess,
        parse and return the stdout generated via `parse_test_context`.

        :param list_cmd: Command to list all test suites and testcases
        :type list_cmd: ``str``
        :return: Result returned by `parse_test_context`.
        :rtype: ``list`` of ``list``
        """
        cmd = list_cmd or self.list_command()
        if not cmd:
            return [(self._DEFAULT_SUITE_NAME, ())]

        proc = subprocess_popen(
            cmd,
            cwd=self.cfg.proc_cwd,
            env=self.cfg.proc_env,
            stdout=subprocess.PIPE,
        )
        test_list_output = proc.communicate()[0]

        # with python3, stdout is bytes so need to decode.
        if not isinstance(test_list_output, str):
            test_list_output = test_list_output.decode(sys.stdout.encoding)

        return self.parse_test_context(test_list_output)
예제 #4
0
    def run_tests(self):
        """
        Run the tests in a subprocess, record stdout & stderr on runpath.
        Optionally enforce a timeout and log timeout related messages in
        the given timeout log path.
        """

        with self.result.report.logged_exceptions(), open(
            self.stderr, "w"
        ) as stderr, open(self.stdout, "w") as stdout:

            if not os.path.exists(self.cfg.binary):
                raise IOError(
                    "No runnable found at {} for {}".format(
                        self.cfg.binary, self
                    )
                )

            # Need to use the binary's absolute path if proc_cwd is specified,
            # otherwise won't be able to find the binary.
            if self.cfg.proc_cwd:
                self.cfg._options["binary"] = os.path.abspath(self.cfg.binary)

            test_cmd = self.test_command()

            self.result.report.logger.debug(
                "Running {} - Command: {}".format(self, test_cmd)
            )

            if not test_cmd:
                raise ValueError(
                    "Invalid test command generated for: {}".format(self)
                )

            self._test_process = subprocess_popen(
                test_cmd,
                stderr=stderr,
                stdout=stdout,
                cwd=self.cfg.proc_cwd,
                env=self.get_proc_env(),
            )

            if self.cfg.timeout:
                with open(self.timeout_log, "w") as timeout_log:
                    timeout_checker = enforce_timeout(
                        process=self._test_process,
                        timeout=self.cfg.timeout,
                        output=timeout_log,
                        callback=self.timeout_callback,
                    )
                    self._test_process_retcode = self._test_process.wait()
                    timeout_checker.join()
            else:
                self._test_process_retcode = self._test_process.wait()

            self._test_has_run = True
예제 #5
0
파일: base.py 프로젝트: bh-ms/testplan
    def get_test_context(self):
        """
        Run the shell command generated by `list_command` in a subprocess,
        parse and return the stdout generated via `parse_test_context`.

        :return: Result returned by `parse_test_context`.
        :rtype: ``list`` of ``list``
        """
        proc = subprocess_popen(self.list_command(),
                                cwd=self.cfg.proc_cwd,
                                env=self.cfg.proc_env,
                                stdout=subprocess.PIPE)

        return self.parse_test_context(test_list_output=proc.communicate()[0])
예제 #6
0
파일: base.py 프로젝트: bh-ms/testplan
    def run_tests(self):
        """
        Run the tests in a subprocess, record stdout & stderr on runpath.
        Optionally enforce a timeout and log timeout related messages in
        the given timeout log path.

        :return:
        """

        with self.result.report.logged_exceptions(), \
                open(self.stderr, 'w') as stderr, \
                open(self.stdout, 'w') as stdout:

            test_cmd = self.test_command()

            self.result.report.logger.debug('Running {} - Command: {}'.format(
                self, test_cmd))

            if not test_cmd:
                raise ValueError(
                    'Invalid test command generated for: {}'.format(self))

            if not os.path.exists(self.cfg.driver):
                raise IOError('No runnable found at {} for {}'.format(
                    self.cfg.driver, self))

            self._test_process = subprocess_popen(
                self.test_command(),
                stderr=stderr,
                stdout=stdout,
                cwd=self.cfg.proc_cwd,
                env=self.cfg.proc_env,
            )

            if self.cfg.timeout:
                with open(self.timeout_log, 'w') as timeout_log:
                    enforce_timeout(process=self._test_process,
                                    timeout=self.cfg.timeout,
                                    output=timeout_log,
                                    callback=self.timeout_callback)
                    self._test_process_retcode = self._test_process.wait()
            else:
                self._test_process_retcode = self._test_process.wait()
            self._test_has_run = True
예제 #7
0
    def starting(self):
        """Starts the application binary."""
        super(App, self).starting()

        cmd = " ".join(self.cmd) if self.cfg.shell else self.cmd
        cwd = self.cfg.working_dir or self.runpath
        try:
            self.logger.debug(
                "%(driver)s driver command: %(cmd)s\n"
                "\tRunpath: %(runpath)s\n"
                "\tOut file: %(out)s\n"
                "\tErr file: %(err)s\n",
                {
                    "driver": self.uid(),
                    "cmd": cmd,
                    "runpath": self.runpath,
                    "out": self.std.out_path,
                    "err": self.std.err_path,
                },
            )
            self.proc = subprocess_popen(
                cmd,
                shell=self.cfg.shell,
                stdin=subprocess.PIPE,
                stdout=self.std.out,
                stderr=self.std.err,
                cwd=cwd,
                env=self.env,
            )
        except Exception:
            self.logger.error(
                "Error while App[%s] driver executed command: %s",
                self.cfg.name,
                cmd if self.cfg.shell else " ".join(cmd),
            )
            if self.proc is not None:
                if self.proc.poll() is None:
                    kill_process(self.proc)
                assert self.proc.returncode is not None
                self._proc = None
            raise
예제 #8
0
파일: base.py 프로젝트: kelliott55/testplan
    def run_tests(self):
        """
        Run the tests in a subprocess, record stdout & stderr on runpath.
        Optionally enforce a timeout and log timeout related messages in
        the given timeout log path.
        """
        with self.report.timer.record("run"):
            with self.report.logged_exceptions(), open(self.stderr,
                                                       "w") as stderr, open(
                                                           self.stdout,
                                                           "w") as stdout:

                test_cmd = self.test_command()
                if not test_cmd:
                    raise ValueError(
                        "Invalid test command generated for: {}".format(self))

                self.report.logger.debug("Running {} - Command: {}".format(
                    self, test_cmd))
                self._test_process = subprocess_popen(
                    test_cmd,
                    stderr=stderr,
                    stdout=stdout,
                    cwd=self.cfg.proc_cwd,
                    env=self.get_proc_env(),
                )

                if self.cfg.timeout:
                    with open(self.timeout_log, "w") as timeout_log:
                        timeout_checker = enforce_timeout(
                            process=self._test_process,
                            timeout=self.cfg.timeout,
                            output=timeout_log,
                            callback=self.timeout_callback,
                        )
                        self._test_process_retcode = self._test_process.wait()
                        timeout_checker.join()
                else:
                    self._test_process_retcode = self._test_process.wait()

                self._test_has_run = True
예제 #9
0
    def starting(self) -> None:
        """
        Starting the rpyc service on remote host.
        """
        cmd = self.cfg.ssh_cmd(
            self.ssh_cfg,
            " ".join([
                self.python_binary,
                "-uB",
                self.cfg.rpyc_bin,
                "--host",
                "0.0.0.0",
                "-p",
                str(self.cfg.rpyc_port),
            ]),
        )

        self.proc = subprocess_popen(
            cmd,
            stdin=subprocess.PIPE,
            stdout=self.std.out,
            stderr=self.std.err,
            cwd=self.runpath,
        )

        self.logger.debug(
            "%s executes cmd: %s\n"
            "\tRunpath: %s\n"
            "\tPID: %s\n"
            "\tOut file: %s\n"
            "\tErr file: %s",
            self,
            " ".join(cmd),
            self.runpath,
            self.proc.pid,
            self.std.out_path,
            self.std.err_path,
        )
예제 #10
0
    def get_test_context(self):
        """
        Run the shell command generated by `list_command` in a subprocess,
        parse and return the stdout generated via `parse_test_context`.

        :return: Result returned by `parse_test_context`.
        :rtype: ``list`` of ``list``
        """
        cmd = self.list_command()
        if cmd is None:
            return []

        proc = subprocess_popen(cmd,
                                cwd=self.cfg.proc_cwd,
                                env=self.cfg.proc_env,
                                stdout=subprocess.PIPE)

        test_list_output = proc.communicate()[0]

        # with python3, stdout is bytes so need to decode.
        if not isinstance(test_list_output, six.string_types):
            test_list_output = test_list_output.decode(sys.stdout.encoding)

        return self.parse_test_context(test_list_output)