def _RunCommand(args):
    gsutil_path = FindGsutil()

    # On cros device, as telemetry is running as root, home will be set to /root/,
    # which is not writable. gsutil will attempt to create a download tracker dir
    # in home dir and fail. To avoid this, override HOME dir to something writable
    # when running on cros device.
    #
    # TODO(tbarzic): Figure out a better way to handle gsutil on cros.
    #     http://crbug.com/386416, http://crbug.com/359293.
    gsutil_env = None
    if cros_interface.IsRunningOnCrosDevice():
        gsutil_env = os.environ.copy()
        gsutil_env['HOME'] = _CROS_GSUTIL_HOME_WAR

    gsutil = subprocess.Popen([sys.executable, gsutil_path] + args,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              env=gsutil_env)
    stdout, stderr = gsutil.communicate()

    if gsutil.returncode:
        if stderr.startswith(
            ('You are attempting to access protected data with no configured',
             'Failure: No handler was ready to authenticate.')):
            raise CredentialsError(gsutil_path)
        if 'status=403' in stderr or 'status 403' in stderr:
            raise PermissionError(gsutil_path)
        if (stderr.startswith('InvalidUriError') or 'No such object' in stderr
                or 'No URLs matched' in stderr):
            raise NotFoundError(stderr)
        raise CloudStorageError(stderr)

    return stdout
Example #2
0
def CreateChromeBrowserOptions(br_options):
    browser_type = br_options.browser_type

    if (cros_interface.IsRunningOnCrosDevice()
            or (browser_type and browser_type.startswith('cros'))):
        return CrosBrowserOptions(br_options)

    return br_options
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))
def CreateChromeBrowserOptions(br_options):
  browser_type = br_options.browser_type

  # Unit tests.
  if not browser_type:
    return br_options

  if (cros_interface.IsRunningOnCrosDevice() or
      browser_type.startswith('cros')):
    return CrosBrowserOptions(br_options)

  return br_options
 def _GetConfigInstructions(gsutil_path):
     if SupportsProdaccess(gsutil_path) and _FindExecutableInPath(
             'prodaccess'):
         return 'Run prodaccess to authenticate.'
     else:
         if cros_interface.IsRunningOnCrosDevice():
             gsutil_path = ('HOME=%s %s' %
                            (_CROS_GSUTIL_HOME_WAR, gsutil_path))
         return (
             'To configure your credentials:\n'
             '  1. Run "%s config" and follow its instructions.\n'
             '  2. If you have a @google.com account, use that account.\n'
             '  3. For the project-id, just enter 0.' % gsutil_path)
Example #6
0
def CanFindAvailableBrowsers():
    return not cros_interface.IsRunningOnCrosDevice()
def CanFindAvailableBrowsers(finder_options):
    return (cros_interface.IsRunningOnCrosDevice()
            or finder_options.cros_remote or cros_interface.HasSSH())
def SelectDefaultBrowser(possible_browsers):
    if cros_interface.IsRunningOnCrosDevice():
        for b in possible_browsers:
            if b.browser_type == 'system':
                return b
    return None