def start(self, tmpdir, debugdir):
        """
        Start the local DM testserver.

        @param tmpdir: location of the Autotest tmp dir.
        @param debugdir: location of the Autotest debug directory.

        """
        policy_server_runner = policy_testserver.PolicyServerRunner()
        self._policy_location = os.path.join(tmpdir, 'policy.json')
        port = utils.get_unused_port()
        # The first argument is always ignored since it is expected to be the
        # path to the executable. Hence passing an empty string for first
        # argument.
        sys.argv = ['',
                    '--config-file=%s' % self._policy_location,
                    '--host=127.0.0.1',
                    '--log-file=%s/dm_server.log' % debugdir,
                    '--log-level=DEBUG',
                    '--port=%d' % port

                   ]
        self.process = Process(target=policy_server_runner.main)
        self.process.start()
        self.server_url = 'http://127.0.0.1:%d/' % port
    def __init__(self, archive_path):
        """
        Creates a WPR server using archive_path and pre-set arguments.

        @param archive_path: path to the .wpr archive to be used.

        """

        port = utils.get_unused_port()
        self._http_port = port if port else 8080

        port = utils.get_unused_port()
        self._https_port = port if port else 8713

        self._server = webpagereplay.ReplayServer(
            archive_path=archive_path,
            replay_host=WebPageReplayWrapper._REPLAY_HOST,
            http_port=self._http_port,
            https_port=self._https_port,
            dns_port=None,
            replay_options=[])
示例#3
0
    def _setup_port(self, port, command_name, remote_pid=None):
        """Sets up a tunnel process and register it to rpc_server_tracker.

        Chrome OS on the target closes down most external ports for security.
        We could open the port, but doing that would conflict with security
        tests that check that only expected ports are open.  So, to get to
        the port on the target we use an ssh tunnel.

        This method assumes that xmlrpc and jsonrpc never conflict, since
        we can only either have an xmlrpc or a jsonrpc server listening on
        a remote port. As such, it enforces a single proxy->remote port
        policy, i.e if one starts a jsonrpc proxy/server from port A->B,
        and then tries to start an xmlrpc proxy forwarded to the same port,
        the xmlrpc proxy will override the jsonrpc tunnel process, however:

        1. None of the methods on the xmlrpc proxy will work because
        the server listening on B is jsonrpc.

        2. The xmlrpc client cannot initiate a termination of the JsonRPC
        server, as the only use case currently is goofy, which is tied to
        the factory image. It is much easier to handle a failed xmlrpc
        call on the client than it is to terminate goofy in this scenario,
        as doing the latter might leave the DUT in a hard to recover state.

        With the current implementation newer rpc proxy connections will
        terminate the tunnel processes of older rpc connections tunneling
        to the same remote port. If methods are invoked on the client
        after this has happened they will fail with connection closed errors.

        @param port: The remote forwarding port.
        @param command_name: The name of the remote process, to terminate
                                using pkill.
        @param remote_pid: The PID of the remote background process
                            as a string.

        @return the local port which is used for port forwarding on the ssh
                    client.
        """
        self.disconnect(port)
        local_port = utils.get_unused_port()
        tunnel_proc = self._host.create_ssh_tunnel(port, local_port)
        self._rpc_proxy_map[port] = (command_name, tunnel_proc, remote_pid)
        return local_port
示例#4
0
    def _create_connection_through_tunnel(self):
        """Creates Chameleon connection through SSH tunnel.

        For developers to run server side test on corp device against
        testing device on Google Test Network, it is required to use
        SSH tunneling to access ports other than SSH port.

        """
        try:
            self._local_port = utils.get_unused_port()
            self._tunneling_process = self._create_ssh_tunnel(
                self._chameleon_port, self._local_port)

            self._wait_for_connection_established()

        # Always close tunnel when fail to create connection.
        except:
            logging.exception('Error in creating connection through tunnel.')
            self._disconnect_tunneling()
            raise
示例#5
0
    def __init__(self,
                 exe_path,
                 port=None,
                 skip_cleanup=False,
                 url_base=None,
                 extra_args=None):
        """Starts the ChromeDriver server and waits for it to be ready.

        Args:
            exe_path: path to the ChromeDriver executable
            port: server port. If None, an available port is chosen at random.
            skip_cleanup: If True, leave the server running so that remote
                          tests can run after this script ends. Default is
                          False.
            url_base: Optional base url for chromedriver.
            extra_args: List of extra arguments to forward to the chromedriver
                        binary, if any.
        Raises:
            RuntimeError if ChromeDriver fails to start
        """
        if not os.path.exists(exe_path):
            raise RuntimeError('ChromeDriver exe not found at: ' + exe_path)

        chromedriver_args = [exe_path]
        if port:
            # Allow remote connections if a port was specified
            chromedriver_args.append('--whitelisted-ips')
        else:
            port = utils.get_unused_port()
        chromedriver_args.append('--port=%d' % port)

        self.url = 'http://localhost:%d' % port
        if url_base:
            chromedriver_args.append('--url-base=%s' % url_base)
            self.url = urlparse.urljoin(self.url, url_base)

        if extra_args:
            chromedriver_args.extend(extra_args)

        # TODO(ihf): Remove references to X after M45.
        # Chromedriver will look for an X server running on the display
        # specified through the DISPLAY environment variable.
        os.environ['DISPLAY'] = X_SERVER_DISPLAY
        os.environ['XAUTHORITY'] = X_AUTHORITY

        self.bg_job = utils.BgJob(chromedriver_args,
                                  stderr_level=logging.DEBUG)
        if self.bg_job is None:
            raise RuntimeError('ChromeDriver server cannot be started')

        try:
            timeout_msg = 'Timeout on waiting for ChromeDriver to start.'
            utils.poll_for_condition(self.is_running,
                                     exception=utils.TimeoutError(timeout_msg),
                                     timeout=10,
                                     sleep_interval=.1)
        except utils.TimeoutError:
            self.close_bgjob()
            raise RuntimeError('ChromeDriver server did not start')

        logging.debug('Chrome Driver server is up and listening at port %d.',
                      port)
        if not skip_cleanup:
            atexit.register(self.close)