Exemplo n.º 1
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)
Exemplo n.º 2
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 run_once(self, update_url, time_without_network=120):
        self._update_server = urlparse.urlparse(update_url).hostname
        # DUTs in the lab have a service called recover_duts that is used to
        # check that the DUT is online and if it is not it will bring it back
        # online. We will need to stop this service for the length of this test.
        utils.stop_service('recover_duts', ignore_status=True)

        # Disable the network adapters.
        utils.run('ifconfig eth0 down')
        utils.run('ifconfig eth1 down')

        # Check that we are offline.
        result = utils.ping(self._update_server, deadline=5, timeout=5)
        if result != 2:
            raise error.TestFail('Ping succeeded even though we were offline.')

        # Get the update percentage as the network is down
        percent_before = utils.run('update_engine_client --status').stdout
        percent_before = percent_before.splitlines()[1].partition('=')[2]

        seconds = 1
        while seconds < time_without_network:
            logging.info(utils.run('update_engine_client --status').stdout)
            time.sleep(1)
            seconds = seconds + 1

        percent_after = utils.run('update_engine_client --status').stdout
        percent_after = percent_after.splitlines()[1].partition('=')[2]

        if percent_before != percent_after:
            if percent_before < percent_after:
                raise error.TestFail('The update continued while the network '
                                     'was supposedly disabled. Before: '
                                     '%s, After: %s' %
                                     (percent_before, percent_after))
            else:
                raise error.TestFail('The update appears to have restarted. '
                                     'Before: %s, After: %s' %
                                     (percent_before, percent_after))
Exemplo n.º 4
0
def stop(allow_fail=False):
    return utils.stop_service("ui", ignore_status=allow_fail)