def run_once(self, expect_reboot=False): # Ensure the UI is running. logging.debug('Restarting UI to ensure that it\'s running.') cros_ui.stop(allow_fail=True) cros_ui.start(wait_for_login_prompt=True) # Since there is no 100% reliable way to determine that the # browser process we're interested in is gone, we need to use # a polling interval to continuously send KILL signals. This # puts the test code in an unavoidable race with the UI # respawning logic being tested. If the UI is down at the # instant we check, it could mean that the UI is done # respawning, the UI is about to respawn, or the device could # already be rebooting. In all likelihood, the UI is coming # back and we'll need to kill it all over again. This is why # the code below polls the UI status for a number of seconds: # to be more confident that the UI went down and is staying down. try: while True: utils.poll_for_condition(condition=cros_ui.is_up, timeout=5, exception=UIStopped('As expected')) self._nuke_browser_until_ui_goes_down() except UIStopped: pass except utils.TimeoutError as te: raise error.TestFail(te) if expect_reboot: raise error.TestFail('UI stopped respawning instead of rebooting.')
def run_once(self): # Ensure the UI is running. logging.debug('Restarting UI to ensure that it\'s running.') cros_ui.stop(allow_fail=True) cros_ui.start(wait_for_login_prompt=False) # Nuke the UI continuously until it stops respawning. respawned_at_least_once = False attempt = 0 timeout_seconds = 10 start_time = time.time() try: for attempt in range(self.UNREASONABLY_HIGH_RESPAWN_COUNT): self._nuke_ui_with_prejudice_and_wait(timeout_seconds) respawned_at_least_once = True except utils.TimeoutError as te: start_time += timeout_seconds pass logging.info("Respawned UI %d times in %d seconds", attempt, time.time() - start_time) if cros_ui.is_up(): raise error.TestFail( 'Respawning should have stopped before %d attempts' % self.UNREASONABLY_HIGH_RESPAWN_COUNT) if not respawned_at_least_once: raise error.TestFail('Should have respawned at least once')
def _set_vpd(self, vpd_settings): """Changes VPD cache on disk. @param vpd_settings: Dictionary of VPD key-value pairs. """ cros_ui.stop() vpd = {} with open(self._VPD_FILENAME, 'r+') as vpd_log: # Read the existing VPD info. for line in vpd_log: # Extract "key"="value" pair. key, _, value = line.replace('"', '').partition('=') vpd[key] = value vpd.update(vpd_settings) # Write the new set of settings to disk. vpd_log.seek(0) for key in vpd: vpd_log.write('"%s"="%s"\n' % (key, vpd[key])) vpd_log.truncate() # Remove filtered cache so dump_vpd_log recreates it from the cache we # just updated. utils.run('rm ' + self._FILTERED_VPD_FILENAME, ignore_status=True) utils.run('dump_vpd_log') # Remove cached files to clear initial locale info. utils.run('rm /home/chronos/Local\ State', ignore_status=True) utils.run('rm /home/chronos/.oobe_completed', ignore_status=True) cros_ui.start()
def cleanup(self): if self._tempdir: self._tempdir.clean() # Best effort to bounce the UI, which may be up or down. cros_ui.stop(allow_fail=True) self._cryptohome_proxy.remove(ownership.TESTUSER) cros_ui.start(allow_fail=True, wait_for_login_prompt=False) super(login_OwnershipApi, self).cleanup()
def restart_ui_to_clear_ownership_files(): """Remove on-disk state related to device ownership. The UI must be stopped while we do this, or the session_manager will write the policy and key files out again. """ cros_ui.stop(allow_fail=not cros_ui.is_up()) clear_ownership_files_no_restart() cros_ui.start()
def initialize(self): super(login_OwnershipApi, self).initialize() self._bus_loop = DBusGMainLoop(set_as_default=True) # Clear existing ownership and inject known keys. cros_ui.stop() ownership.clear_ownership_files_no_restart() # Make device already owned by ownership.TESTUSER. cryptohome.mount_vault(ownership.TESTUSER, ownership.TESTPASS, create=True) ownership.use_known_ownerkeys(ownership.TESTUSER) self._tempdir = autotemp.tempdir(unique_id=self.__class__.__name__) cros_ui.start()
def stop(self, test): if not cros_ui.stop_and_wait_for_chrome_to_exit(timeout_secs=40): raise error.TestError('Could not stop Chrome') if os.path.isdir(self._source_dir): tar = tarfile.open(name=os.path.join(test.profdir, 'pgo.tar.bz2'), mode='w:bz2') tar.add(self._source_dir, arcname='chrome', recursive=True) tar.close() versionfile = '/opt/google/chrome/profilelocation' if os.path.isfile(versionfile): shutil.copyfile( versionfile, os.path.join(test.profdir, 'profiledestination')) else: logging.error('PGO dir: %s not found', self._source_dir) cros_ui.start(wait_for_login_prompt=False)
class platform_SessionManagerBlockDevmodeSetting(test.test): """Verifies that session_manager updates the block_devmode flag to be in sync with the corresponding device setting.""" version = 1 def initialize(self): super(platform_SessionManagerBlockDevmodeSetting, self).initialize() ownership.restart_ui_to_clear_ownership_files() self._bus_loop = DBusGMainLoop(set_as_default=True) def run_once(self): try: if utils.system_output('crossystem mainfw_type') == 'nonchrome': raise error.TestNAError( 'State key generation only works on Chrome OS hardware') except error.CmdError, e: raise error.TestError('Failed to run crossystem: %s' % e) # Make sure that the flag sticks when there is no owner. set_block_devmode(True) cros_ui.restart() cros_ui.stop() if not get_block_devmode(): raise error.TestFail("Flag got reset for non-owned device.") # Test whether the flag gets reset when taking ownership. listener = session_manager.OwnershipSignalListener(gobject.MainLoop()) listener.listen_for_new_key_and_policy() with chrome.Chrome() as cr: listener.wait_for_signals(desc='Ownership files written to disk.') if get_block_devmode(): raise error.TestFail( "Flag not clear after ownership got established.") # Put a new owner key and policy blob in place, the latter of which # specifies block_devmode=true. cros_ui.stop(allow_fail=True) shutil.copyfile(os.path.join(self.bindir, 'owner.key'), constants.OWNER_KEY_FILE) shutil.copyfile( os.path.join(self.bindir, 'policy_block_devmode_enabled'), constants.SIGNED_POLICY_FILE) cros_ui.start() if not get_block_devmode(): raise error.TestFail( "Flag not set after starting with policy enabled.") # Send a new policy blob to session_manager that disables block_devmode. listener.listen_for_new_policy() with open(os.path.join(self.bindir, 'policy_block_devmode_disabled')) as f: session_manager_proxy = session_manager.connect(self._bus_loop) session_manager_proxy.StorePolicyEx( session_manager.make_device_policy_descriptor(), f.read()) listener.wait_for_signals(desc='Policy updated.') if get_block_devmode(): raise error.TestFail( "Flag set after updating policy to clear flag.")
def run_once(self): # Create magic file to enable browser liveness checking and # bounce the session manager to pick up the flag file. cros_ui.stop() os.mknod(constants.ENABLE_BROWSER_HANG_DETECTION_FILE) cros_ui.start() browser_pid = self._get_oldest_pid_by_name(constants.BROWSER) sm_pid = self._get_oldest_pid_by_name(constants.SESSION_MANAGER) # Reading the log is the best way to watch for the hang detector. reader = cros_logging.LogReader() reader.set_start_by_current() # To simulate a hang, STOP the browser and wait for it to get # hit by the session manager. It won't actually exit until it gets # a SIGCONT, though. try: os.kill(browser_pid, signal.SIGSTOP) # Simulate hang. except OSError as e: raise error.TestError('Cannot STOP browser: %r' % e) # Watch for hang detection. utils.poll_for_condition( condition=lambda: reader.can_find('Aborting browser process.'), exception=utils.TimeoutError('Waiting for hang detector.'), sleep_interval=5, timeout=60) try: os.kill(browser_pid, signal.SIGCONT) # Allow browser to die. except OSError as e: raise error.TestError('Cannot CONT browser: %r' % e) # Wait for old browser process to be gone. utils.poll_for_condition( condition= lambda: utils.pid_is_alive(browser_pid), exception=utils.TimeoutError( 'Browser does not seem to have restarted!'), timeout=60) # Wait for new browser to come up. login.wait_for_browser() if sm_pid != self._get_oldest_pid_by_name(constants.SESSION_MANAGER): raise error.TestFail('session_manager seems to have restarted')
def initialize(self): """Constructor Sets up the test such that all DBus signals can be received and a fake proxy server can be instantiated. Additionally, the UI is restarted to ensure consistent shared network use. """ super(network_ProxyResolver, self).initialize() cros_ui.stop() cros_ui.start() DBusGMainLoop(set_as_default=True) self._listener = SignalListener(gobject.MainLoop()) self._shill = shill_proxy.ShillProxy.get_proxy() if self._shill is None: raise error.TestFail('Could not connect to shill') # Listen for network property changes self._listener.listen_for_signal('PropertyChanged', 'org.chromium.flimflam.Service', '/') # Listen on the proxy port. self._proxy_server = ProxyListener(('', 3128))
def cleanup(self): """Ensure the UI is up, and that state from testing is cleared out.""" cros_ui.clear_respawn_state() # If the UI is already up, we want to tolerate that. cros_ui.start(allow_fail=True)
def cleanup(self): # Bounce UI, without waiting for the browser to come back. Best effort. cros_ui.stop(allow_fail=True) cros_ui.start(allow_fail=True, wait_for_login_prompt=False)
def initialize(self): super(platform_SessionManagerStateKeyGeneration, self).initialize() cros_ui.stop(allow_fail=True) cros_ui.start() self._bus_loop = DBusGMainLoop(set_as_default=True)
def cleanup(self): # Testing is done, so just stop the UI instead of calling StopSession. # The latter can fail if Chrome is hanging: https://crbug.com/876197 cros_ui.stop(allow_fail=True) cros_ui.start(allow_fail=True, wait_for_login_prompt=False)
def cleanup(self): # If the UI is already up, we want to tolerate that. cros_ui.start(allow_fail=True)
def cleanup(self): # Best effort to bounce the UI, which may be up or down. cros_ui.stop(allow_fail=True) self._cryptohome_proxy.remove(self.username) cros_ui.start(allow_fail=True, wait_for_login_prompt=False) super(login_RemoteOwnership, self).cleanup()
def cleanup(self): self._session_manager.StopSession('') cros_ui.start(allow_fail=True, wait_for_login_prompt=False)
def enable_ui(self): """@return True iff the UI was successfully started.""" return cros_ui.start(allow_fail=True, wait_for_login_prompt=False) == 0