Пример #1
0
    def __init__(self, host, station_api_port, station_info, proxy=None):
        self.host = host
        self.station_api_port = station_api_port

        if not hasattr(self, '_station_info'):
            logging.debug('Creating new Station (%s) at %s:%s',
                          station_info.station_id, host, station_api_port)
            # We're not reusing a shared instance, initialize things we need.
            self._history = history.History()
            self.cached_tests = {}
            self._lock = threading.Lock()

        elif self._station_info != station_info:
            _LOG.warning(
                'Reusing Station (%s) with new StationInfo: %s, clearing History.',
                self._station_info.station_id, station_info)
            self._history = history.History()
            self.cached_tests = {}

        self._station_info = station_info
        # Shared proxy used for synchronous calls we expect to be fast.
        # Long-polling calls should use make_proxy() to create a new ServerProxy
        # object each time, to avoid blocking short requests with long-running ones.
        self._shared_proxy = proxy or self.make_proxy()
        # Lock was acquired at the beginning of __new__().
        self.STATION_LOCK.release()
Пример #2
0
    def reachable(self):
        """Returns True if the station is reachable, also updates StationInfo."""
        try:
            station_info = StationInfo(**self._shared_proxy.get_station_info())
        except socket.error:
            return False

        if self._station_info.station_id and self._station_info != station_info:
            _LOG.warning(
                'Reusing Station (%s) with new StationInfo: %s, clearing History.',
                self._station_info.station_id, station_info)
            self._history = history.History()

        # Update our local StationInfo.
        self._station_info = station_info
        return True