Пример #1
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')
Пример #2
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', (remote_port, 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))
Пример #3
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'))
Пример #4
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'))
Пример #5
0
 def testExists(self):
   remote = options_for_unittests.GetCopy().cros_remote
   cri = cros_interface.CrOSInterface(
     remote,
     options_for_unittests.GetCopy().cros_ssh_identity)
   self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
   self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
   self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
Пример #6
0
 def testPushContents(self):
   remote = options_for_unittests.GetCopy().cros_remote
   cri = cros_interface.CrOSInterface(
     remote,
     options_for_unittests.GetCopy().cros_ssh_identity)
   cri.GetCmdOutput(['rm', '-rf', '/tmp/testPushContents'])
   cri.PushContents('hello world', '/tmp/testPushContents')
   contents = cri.GetFileContents('/tmp/testPushContents')
   self.assertEquals(contents, 'hello world')
Пример #7
0
  def testDeviceSideProcessFailureToLaunch(self):
    remote = options_for_unittests.GetCopy().cros_remote
    cri = cros_interface.CrOSInterface(
      remote,
      options_for_unittests.GetCopy().cros_ssh_identity)

    def WillFail():
      dsp = cros_interface.DeviceSideProcess(
        cri,
        ['sfsdfskjflwejfweoij'])
      dsp.Close()
    self.assertRaises(OSError, WillFail)
Пример #8
0
  def testListProcesses(self): # pylint: disable=R0201
    remote = options_for_unittests.GetCopy().cros_remote
    cri = cros_interface.CrOSInterface(
      remote,
      options_for_unittests.GetCopy().cros_ssh_identity)
    with cros_interface.DeviceSideProcess(
        cri,
        ['sleep', '11']):
      procs = cri.ListProcesses()
      sleeps = [x for x in procs
                if x[1] == 'sleep 11']

      assert len(sleeps) == 1
Пример #9
0
  def testDeviceSideProcessCloseDoesClose(self):
    remote = options_for_unittests.GetCopy().cros_remote
    cri = cros_interface.CrOSInterface(
      remote,
      options_for_unittests.GetCopy().cros_ssh_identity)

    with cros_interface.DeviceSideProcess(
        cri,
        ['sleep', '111']) as dsp:
      procs = cri.ListProcesses()
      sleeps = [x for x in procs
                if x[1] == 'sleep 111']
      assert dsp.IsAlive()
    procs = cri.ListProcesses()
    sleeps = [x for x in procs
              if x[1] == 'sleep 111']
    self.assertEquals(len(sleeps), 0)
Пример #10
0
def FindAllAvailableBrowsers(options):
  """Finds all the desktop browsers available on this machine."""
  if 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(options.cros_remote,
                                     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',
                      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.')
    else:
      logging.warn(str(ex))
    return []