def _GetPossibleBrowser(self, finder_options): """Return a possible_browser with the given options.""" possible_browser = browser_finder.FindBrowser(finder_options) if not possible_browser: raise browser_finder_exceptions.BrowserFinderException( 'No browser found.\n\nAvailable browsers:\n%s\n' % '\n'.join( browser_finder.GetAllAvailableBrowserTypes(finder_options)) ) finder_options.browser_options.browser_type = ( possible_browser.browser_type) return possible_browser
def FindAllAvailableBrowsers(finder_options): """Finds all available CrOS browsers, locally and remotely.""" if _IsRunningOnCrOS(): return [ PossibleCrOSBrowser('system', finder_options, platform_module.GetHostPlatform(), is_guest=False), PossibleCrOSBrowser('system-guest', finder_options, platform_module.GetHostPlatform(), 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 [] device = cros_device.CrOSDevice(finder_options.cros_remote, finder_options.cros_ssh_identity) # Check ssh try: platform = platform_module.GetPlatformForDevice(device) 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.') raise browser_finder_exceptions.BrowserFinderException(str(ex))
def _GetPossibleBrowser(self, test, finder_options): """Return a possible_browser with the given options. """ possible_browser = browser_finder.FindBrowser(finder_options) if not possible_browser: raise browser_finder_exceptions.BrowserFinderException( 'No browser found.\n\nAvailable browsers:\n%s\n' % '\n'.join(browser_finder.GetAllAvailableBrowserTypes(finder_options))) finder_options.browser_options.browser_type = ( possible_browser.browser_type) (enabled, msg) = decorators.IsEnabled(test, possible_browser) if (not enabled and not finder_options.run_disabled_tests): logging.warning(msg) logging.warning('You are trying to run a disabled test.') logging.warning('Pass --also-run-disabled-tests to squelch this message.') sys.exit(0) if possible_browser.IsRemote(): possible_browser.RunRemote() sys.exit(0) return possible_browser
def FindBrowser(options): """Finds the best PossibleBrowser object given a BrowserOptions object. Args: A BrowserOptions object. Returns: A PossibleBrowser object. Raises: BrowserFinderException: Options improperly set, or an error occurred. """ if options.browser_type == 'exact' and options.browser_executable == None: raise browser_finder_exceptions.BrowserFinderException( '--browser=exact requires --browser-executable to be set.') if options.browser_type != 'exact' and options.browser_executable != None: raise browser_finder_exceptions.BrowserFinderException( '--browser-executable requires --browser=exact.') if options.browser_type == 'cros-chrome' and options.cros_remote == None: raise browser_finder_exceptions.BrowserFinderException( 'browser_type=cros-chrome requires cros_remote be set.') if (options.browser_type != 'cros-chrome' and options.browser_type != 'cros-chrome-guest' and options.cros_remote != None): raise browser_finder_exceptions.BrowserFinderException( '--remote requires --browser=cros-chrome or cros-chrome-guest.') devices = device_finder.GetDevicesMatchingOptions(options) browsers = [] default_browsers = [] for device in devices: for finder in BROWSER_FINDERS: if(options.browser_type and options.browser_type != 'any' and options.browser_type not in finder.FindAllBrowserTypes(options)): continue curr_browsers = finder.FindAllAvailableBrowsers(options, device) new_default_browser = finder.SelectDefaultBrowser(curr_browsers) if new_default_browser: default_browsers.append(new_default_browser) browsers.extend(curr_browsers) if options.browser_type == None: if default_browsers: default_browser = sorted(default_browsers, key=lambda b: b.last_modification_time())[-1] logging.warning('--browser omitted. Using most recent local build: %s' % default_browser.browser_type) default_browser.UpdateExecutableIfNeeded() return default_browser if len(browsers) == 1: logging.warning('--browser omitted. Using only available browser: %s' % browsers[0].browser_type) browsers[0].UpdateExecutableIfNeeded() return browsers[0] raise browser_finder_exceptions.BrowserTypeRequiredException( '--browser must be specified. Available browsers:\n%s' % '\n'.join(sorted(set([b.browser_type for b in browsers])))) if options.browser_type == 'any': types = FindAllBrowserTypes(options) def CompareBrowsersOnTypePriority(x, y): x_idx = types.index(x.browser_type) y_idx = types.index(y.browser_type) return x_idx - y_idx browsers.sort(CompareBrowsersOnTypePriority) if len(browsers) >= 1: browsers[0].UpdateExecutableIfNeeded() return browsers[0] else: return None matching_browsers = [b for b in browsers if b.browser_type == options.browser_type and b.SupportsOptions(options)] chosen_browser = None if len(matching_browsers) == 1: chosen_browser = matching_browsers[0] elif len(matching_browsers) > 1: logging.warning('Multiple browsers of the same type found: %s' % ( repr(matching_browsers))) chosen_browser = sorted(matching_browsers, key=lambda b: b.last_modification_time())[-1] if chosen_browser: logging.info('Chose browser: %s' % (repr(chosen_browser))) chosen_browser.UpdateExecutableIfNeeded() return chosen_browser