def FindAllAvailableBrowsers(finder_options):
    """Finds all available chromeos browsers, locally and remotely."""
    if cros_interface.IsRunningOnCrosDevice():
        return [
            PossibleCrOSBrowser('system',
                                finder_options,
                                cros_interface.CrOSInterface(),
                                is_guest=False),
            PossibleCrOSBrowser('system-guest',
                                finder_options,
                                cros_interface.CrOSInterface(),
                                is_guest=True)
        ]

    if finder_options.cros_remote == None:
        logging.debug('No --remote specified, will not probe for CrOS.')
        return []

    if not cros_interface.HasSSH():
        logging.debug('ssh not found. Cannot talk to CrOS devices.')
        return []
    cri = cros_interface.CrOSInterface(finder_options.cros_remote,
                                       finder_options.cros_ssh_identity)

    # Check ssh
    try:
        cri.TryLogin()
    except cros_interface.LoginException, ex:
        if isinstance(ex, cros_interface.KeylessLoginRequiredException):
            logging.warn(
                'Could not ssh into %s. Your device must be configured',
                finder_options.cros_remote)
            logging.warn('to allow passwordless login as root.')
            logging.warn('For a test-build device, pass this to your script:')
            logging.warn('   --identity $(CHROMITE)/ssh_keys/testing_rsa')
            logging.warn('')
            logging.warn('For a developer-mode device, the steps are:')
            logging.warn(
                ' - Ensure you have an id_rsa.pub (etc) on this computer')
            logging.warn(' - On the chromebook:')
            logging.warn('   -  Control-Alt-T; shell; sudo -s')
            logging.warn('   -  openssh-server start')
            logging.warn('   -  scp <this machine>:.ssh/id_rsa.pub /tmp/')
            logging.warn('   -  mkdir /root/.ssh')
            logging.warn('   -  chown go-rx /root/.ssh')
            logging.warn(
                '   -  cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys')
            logging.warn('   -  chown 0600 /root/.ssh/authorized_keys')
            logging.warn('There, that was easy!')
            logging.warn('')
            logging.warn('P.S. Please, tell your manager how INANE this is.')

        from telemetry.core import browser_finder
        raise browser_finder.BrowserFinderException(str(ex))
Ejemplo n.º 2
0
 def testGetFileContents(self):  # pylint: disable=R0201
     remote = options_for_unittests.GetCopy().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.GetCopy().cros_ssh_identity)
     hosts = cri.GetFileContents('/etc/hosts')
     assert hosts.startswith('# /etc/hosts')
 def testGetFileContents(self):  # pylint: disable=R0201
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         hosts = cri.GetFileContents('/etc/lsb-release')
         self.assertTrue('CHROMEOS' in hosts)
Ejemplo n.º 4
0
    def testGetRemotePortAndIsHTTPServerRunningOnPort(self):
        remote = options_for_unittests.GetCopy().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.GetCopy().cros_ssh_identity)

        # Create local server.
        sock = socket.socket()
        sock.bind(('', 0))
        port = sock.getsockname()[1]
        sock.listen(0)

        # Get remote port and ensure that it was unused.
        remote_port = cri.GetRemotePort()
        self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port))

        # Forward local server's port to remote device's remote_port.
        forwarder = cros_browser_backend.SSHForwarder(
            cri, 'R', util.PortPair(port, remote_port))

        # At this point, remote device should be able to connect to local server.
        self.assertTrue(cri.IsHTTPServerRunningOnPort(remote_port))

        # Next remote port shouldn't be the same as remote_port, since remote_port
        # is now in use.
        self.assertTrue(cri.GetRemotePort() != remote_port)

        # Close forwarder and local server ports.
        forwarder.Close()
        sock.close()

        # Device should no longer be able to connect to remote_port since it is no
        # longer in use.
        self.assertFalse(cri.IsHTTPServerRunningOnPort(remote_port))
Ejemplo n.º 5
0
 def testGetFileContentsForSomethingThatDoesntExist(self):
     remote = options_for_unittests.GetCopy().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.GetCopy().cros_ssh_identity)
     self.assertRaises(
         OSError, lambda: cri.GetFileContents('/tmp/209fuslfskjf/dfsfsf'))
Ejemplo n.º 6
0
    def testIsServiceRunning(self):
        remote = options_for_unittests.GetCopy().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.GetCopy().cros_ssh_identity)

        self.assertTrue(cri.IsServiceRunning('openssh-server'))
Ejemplo n.º 7
0
 def setUp(self):
   options = options_for_unittests.GetCopy()
   self._cri = cros_interface.CrOSInterface(options.cros_remote,
                                            options.cros_ssh_identity)
   self._is_guest = options.browser_type == 'cros-chrome-guest'
   self._username = '' if self._is_guest else options.browser_options.username
   self._password = options.browser_options.password
Ejemplo n.º 8
0
    def testExistsLocal(self):
        if not sys.platform.startswith('linux'):
            return

        cri = cros_interface.CrOSInterface()
        self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
        self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
        self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
 def testExists(self):
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
         self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
         self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
 def testGetFileNonExistent(self):
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         f = tempfile.NamedTemporaryFile()
         cri.PushContents('testGetFileNonExistent', f.name)
         cri.RmRF(f.name)
         self.assertRaises(OSError, lambda: cri.GetFile(f.name))
 def testPushContents(self):
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         cri.RunCmdOnDevice(['rm', '-rf', '/tmp/testPushContents'])
         cri.PushContents('hello world', '/tmp/testPushContents')
         contents = cri.GetFileContents('/tmp/testPushContents')
         self.assertEquals(contents, 'hello world')
 def testGetFile(self):  # pylint: disable=R0201
     remote = options_for_unittests.GetCopy().cros_remote
     with cros_interface.CrOSInterface(
             remote,
             options_for_unittests.GetCopy().cros_ssh_identity) as cri:
         f = tempfile.NamedTemporaryFile()
         cri.GetFile('/etc/lsb-release', f.name)
         with open(f.name, 'r') as f2:
             res = f2.read()
             self.assertTrue('CHROMEOS' in res)
    def testGetRemotePortReservedPorts(self):
        remote = options_for_unittests.GetCopy().cros_remote
        with cros_interface.CrOSInterface(
                remote,
                options_for_unittests.GetCopy().cros_ssh_identity) as cri:

            # Should return 2 separate ports even though the first one isn't
            # technically being used yet.
            remote_port_1 = cri.GetRemotePort()
            remote_port_2 = cri.GetRemotePort()

            self.assertTrue(remote_port_1 != remote_port_2)
Ejemplo n.º 14
0
    def testEscapeCmdArguments(self):
        ''' Commands and their arguments that are executed through the cros
    interface should follow bash syntax. This test needs to run on remotely
    and locally on the device to check for consistency.
    '''
        cri = cros_interface.CrOSInterface(
            options_for_unittests.GetCopy().cros_remote,
            options_for_unittests.GetCopy().cros_ssh_identity)

        # Check arguments with no special characters
        stdout, _ = cri.RunCmdOnDevice(
            ['echo', '--arg1=value1', '--arg2=value2', '--arg3="value3"'])
        assert (stdout.strip() == '--arg1=value1 --arg2=value2 --arg3=value3')

        # Check argument with special characters escaped
        stdout, _ = cri.RunCmdOnDevice(['echo', '--arg=A\\; echo \\"B\\"'])
        assert (stdout.strip() == '--arg=A; echo "B"')

        # Check argument with special characters in quotes
        stdout, _ = cri.RunCmdOnDevice(['echo', "--arg='$HOME;;$PATH'"])
        assert (stdout.strip() == "--arg=$HOME;;$PATH")
Ejemplo n.º 15
0
 def testIsServiceRunningLocal(self):
     if not sys.platform.startswith('linux'):
         return
     cri = cros_interface.CrOSInterface()
     self.assertTrue(cri.IsServiceRunning('dbus'))
Ejemplo n.º 16
0
 def setUp(self):
     options = options_for_unittests.GetCopy()
     self._cri = cros_interface.CrOSInterface(options.cros_remote,
                                              options.cros_ssh_identity)
     self._is_guest = options.browser_type == 'cros-chrome-guest'
     self._email = '' if self._is_guest else '*****@*****.**'
 def testExistsLocal(self):
     with cros_interface.CrOSInterface() as cri:
         self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
         self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
         self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
 def testIsServiceRunningLocal(self):
     with cros_interface.CrOSInterface() as cri:
         self.assertTrue(cri.IsServiceRunning('dbus'))