Ejemplo n.º 1
0
 def testGetFileContents(self):  # pylint: disable=R0201
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().cros_ssh_identity)
     hosts = cri.GetFileContents('/etc/hosts')
     assert hosts.startswith('# /etc/hosts')
Ejemplo n.º 2
0
    def testIsServiceRunning(self):
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().cros_ssh_identity)

        self.assertTrue(cri.IsServiceRunning('openssh-server'))
Ejemplo n.º 3
0
 def testGetFileContentsForSomethingThatDoesntExist(self):
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().cros_ssh_identity)
     self.assertRaises(
         OSError, lambda: cri.GetFileContents('/tmp/209fuslfskjf/dfsfsf'))
Ejemplo n.º 4
0
 def testExists(self):
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().cros_ssh_identity)
     self.assertTrue(cri.FileExistsOnDevice('/proc/cpuinfo'))
     self.assertTrue(cri.FileExistsOnDevice('/etc/passwd'))
     self.assertFalse(cri.FileExistsOnDevice('/etc/sdlfsdjflskfjsflj'))
Ejemplo n.º 5
0
 def testPushContents(self):
     remote = options_for_unittests.Get().cros_remote
     cri = cros_interface.CrOSInterface(
         remote,
         options_for_unittests.Get().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')
Ejemplo n.º 6
0
    def testListProcesses(self):  # pylint: disable=R0201
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().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
Ejemplo n.º 7
0
    def testDeviceSideProcessFailureToLaunch(self):
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().cros_ssh_identity)

        def WillFail():
            dsp = cros_interface.DeviceSideProcess(cri,
                                                   ['sfsdfskjflwejfweoij'])
            dsp.Close()

        self.assertRaises(OSError, WillFail)
Ejemplo n.º 8
0
    def testDeviceSideProcessCloseDoesClose(self):
        remote = options_for_unittests.Get().cros_remote
        cri = cros_interface.CrOSInterface(
            remote,
            options_for_unittests.Get().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)
Ejemplo n.º 9
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/id_testing:')
      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 []