def RunNavigateSteps(self, action_runner):
        """Opening tabs and waiting for them to load."""
        if not self._cros_remote and not py_utils.IsRunningOnCrosDevice():
            raise ValueError('Must specify --remote=DUT_IP to run this test, '
                             'or run it on CrOS locally.')

        # As this story may run for a long time, adjusting screen off time to
        # avoid screen off.
        cros_utils.NoScreenOff(self._cros_remote)

        tabs = action_runner.tab.browser.tabs

        # No need to create the first tab as there is already one
        # when the browser is ready.
        url_list = self.URL_LIST * self._tabset_repeat
        if url_list:
            action_runner.Navigate(url_list[0])
        for i, url in enumerate(url_list[1:]):
            new_tab = tabs.New()
            try:
                new_tab.action_runner.Navigate(url)
            except exceptions.DevtoolsTargetCrashException:
                logging.info('Navigate: devtools context lost')
            if i % 10 == 0:
                print('opening tab:', i)

        # Waiting for every tabs to be stable.
        for i, url in enumerate(url_list):
            try:
                tabs[i].action_runner.WaitForNetworkQuiescence()
            except py_utils.TimeoutException:
                logging.info('WaitForNetworkQuiescence() timeout, url[%d]: %s',
                             i, url)
            except exceptions.DevtoolsTargetCrashException:
                logging.info('WaitForNetworkQuiescence: devtools context lost')
Exemple #2
0
 def _GetConfigInstructions():
     command = _GSUTIL_PATH
     if py_utils.IsRunningOnCrosDevice():
         command = '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.' % command)
Exemple #3
0
def GetOSNameForCurrentDesktopPlatform():
    if py_utils.IsRunningOnCrosDevice():
        return 'chromeos'
    if sys.platform.startswith('linux'):
        return 'linux'
    if sys.platform == 'darwin':
        return 'mac'
    if sys.platform == 'win32':
        return 'win'
    return sys.platform
def _RunCommand(args):
    # 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 py_utils.IsRunningOnCrosDevice():
        gsutil_env = os.environ.copy()
        gsutil_env['HOME'] = _CROS_GSUTIL_HOME_WAR

    if os.name == 'nt':
        # If Windows, prepend python. Python scripts aren't directly executable.
        args = [sys.executable, _GSUTIL_PATH] + args
    else:
        # Don't do it on POSIX, in case someone is using a shell script to redirect.
        args = [_GSUTIL_PATH] + args
        _EnsureExecutable(_GSUTIL_PATH)

    if args[0] not in ('help', 'hash', 'version') and not IsNetworkIOEnabled():
        raise CloudStorageIODisabled(
            "Environment variable DISABLE_CLOUD_STORAGE_IO is set to 1. "
            'Command %s is not allowed to run' % args)

    gsutil = subprocess.Popen(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.')) or re.match(
                 '.*users does not have .* access to object.*', stderr)):
            raise CredentialsError()
        if ('status=403' in stderr or 'status 403' in stderr
                or '403 Forbidden' in stderr):
            raise PermissionError()
        if (stderr.startswith('InvalidUriError') or 'No such object' in stderr
                or 'No URLs matched' in stderr
                or 'One or more URLs matched no' in stderr):
            raise NotFoundError(stderr)
        if '500 Internal Server Error' in stderr:
            raise ServerError(stderr)
        raise CloudStorageError(stderr)

    return stdout
Exemple #5
0
def _RunCommand(args):
    # 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 py_utils.IsRunningOnCrosDevice():
        gsutil_env = os.environ.copy()
        gsutil_env['HOME'] = _CROS_GSUTIL_HOME_WAR
    elif _IsRunningOnSwarming():
        gsutil_env = os.environ.copy()

    if os.name == 'nt':
        # If Windows, prepend python. Python scripts aren't directly executable.
        args = [sys.executable, _GSUTIL_PATH] + args
    else:
        # Don't do it on POSIX, in case someone is using a shell script to redirect.
        args = [_GSUTIL_PATH] + args
        _EnsureExecutable(_GSUTIL_PATH)

    if args[0] not in ('help', 'hash', 'version') and not IsNetworkIOEnabled():
        raise CloudStorageIODisabled(
            "Environment variable DISABLE_CLOUD_STORAGE_IO is set to 1. "
            'Command %s is not allowed to run' % args)

    gsutil = subprocess.Popen(args,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE,
                              env=gsutil_env)
    stdout, stderr = gsutil.communicate()

    if gsutil.returncode:
        raise GetErrorObjectForCloudStorageStderr(stderr)

    return stdout