Ejemplo n.º 1
0
    def run_systemd_tests(self):
        """
        Check if cupsd is running and responsive.
        """
        sys_utils.stop_service('cups', ignore_status=False)
        sys_utils.start_service('cups.socket', ignore_status=False)

        if not self.wait_for_path_exists(self._CUPS_SOCK_PATH):
            raise error.TestFail('Missing CUPS socket: %s',
                                 self._CUPS_SOCK_PATH)

        # Test that cupsd is automatically launched through socket activation.
        self.check_cups_is_responding()

        sys_utils.stop_service('cups', ignore_status=False)
        sys_utils.stop_service('cups.socket', ignore_status=False)

        # Dummy file to test that cups.socket handles lingering file properly.
        utils.system('touch %s' % self._CUPS_SOCK_PATH)

        sys_utils.start_service('cups.socket', ignore_status=False)

        if not os.path.exists(self._CUPS_SOCK_PATH):
            raise error.TestFail('Missing CUPS socket: %s',
                                 self._CUPS_SOCK_PATH)

        self.check_cups_is_responding()
    def cleanup(self):
        shutil.copy('/var/log/update_engine.log', self.resultsdir)

        # Turn adapters back on
        utils.run('ifconfig eth0 up', ignore_status=True)
        utils.run('ifconfig eth1 up', ignore_status=True)
        utils.start_service('recover_duts', ignore_status=True)

        # We can't return right after reconnecting the network or the server
        # test may not receive the message. So we wait a bit longer for the
        # DUT to be reconnected.
        utils.poll_for_condition(lambda: utils.ping(
            self._update_server, deadline=5, timeout=5) == 0,
                                 timeout=60,
                                 sleep_interval=1)
        logging.info('Online ready to return to server test')
def has_cups_systemd():
    """Returns True if cups is running under systemd.

  Attempts to start cups if it is not already running.
  """
    return sys_utils.has_systemd() and (
        (sys_utils.get_service_pid('cups') != 0) or
        (sys_utils.start_service('cups', ignore_status=True) == 0))
Ejemplo n.º 4
0
def start(allow_fail=False, wait_for_login_prompt=True):
    """Start the login manager and wait for the prompt to show up."""
    session = get_chrome_session_ident()
    result = utils.start_service("ui", ignore_status=allow_fail)
    # If allow_fail is set, the caller might be calling us when the UI job
    # is already running. In that case, the above command fails.
    if result == 0 and wait_for_login_prompt:
        wait_for_chrome_ready(session)
    return result
Ejemplo n.º 5
0
def stopped_shill():
    """A context for executing code which requires shill to be stopped.

    This context stops shill on entry to the context, and starts shill
    before exit from the context. This context further guarantees that
    shill will be not restarted by recover_duts, while this context is
    active.

    Note that the no-restart guarantee applies only if the user of
    this context completes with a 'reasonable' amount of time. In
    particular: if networking is unavailable for 15 minutes or more,
    recover_duts will reboot the DUT.

    """
    def get_lock_holder(lock_path):
        lock_holder = os.readlink(lock_path)
        try:
            os.stat(lock_holder)
            return lock_holder  # stat() success -> valid link -> locker alive
        except OSError as e:
            if e.errno == errno.ENOENT:  # dangling link -> locker is gone
                return None
            else:
                raise

    our_proc_dir = '/proc/%d/' % os.getpid()
    try:
        os.symlink(our_proc_dir, SHILL_START_LOCK_PATH)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise
        lock_holder = get_lock_holder(SHILL_START_LOCK_PATH)
        if lock_holder is not None:
            raise error.TestError('Shill start lock held by %s' % lock_holder)
        os.remove(SHILL_START_LOCK_PATH)
        os.symlink(our_proc_dir, SHILL_START_LOCK_PATH)

    utils.stop_service('shill')
    yield
    utils.start_service('shill')
    os.remove(SHILL_START_LOCK_PATH)