Merge "Avoid log warning when closing is underway (on purpose)"

This commit is contained in:
Zuul 2017-12-12 22:33:40 +00:00 committed by Gerrit Code Review
commit 4caeea11cc

View File

@ -317,6 +317,7 @@ class ZookeeperJobBoard(base.NotifyingJobBoard):
self._emit_notifications = bool(emit_notifications) self._emit_notifications = bool(emit_notifications)
self._connected = False self._connected = False
self._suspended = False self._suspended = False
self._closing = False
self._last_states = collections.deque(maxlen=self.STATE_HISTORY_LENGTH) self._last_states = collections.deque(maxlen=self.STATE_HISTORY_LENGTH)
def _try_emit(self, state, details): def _try_emit(self, state, details):
@ -748,6 +749,10 @@ class ZookeeperJobBoard(base.NotifyingJobBoard):
self._last_states.appendleft(state) self._last_states.appendleft(state)
if state == k_states.KazooState.LOST: if state == k_states.KazooState.LOST:
self._connected = False self._connected = False
# When the client is itself closing itself down this will be
# triggered, but in that case we expect it, so we don't need
# to emit a warning message.
if not self._closing:
LOG.warning("Connection to zookeeper has been lost") LOG.warning("Connection to zookeeper has been lost")
elif state == k_states.KazooState.SUSPENDED: elif state == k_states.KazooState.SUSPENDED:
LOG.warning("Connection to zookeeper has been suspended") LOG.warning("Connection to zookeeper has been suspended")
@ -790,6 +795,7 @@ class ZookeeperJobBoard(base.NotifyingJobBoard):
def close(self): def close(self):
if self._owned: if self._owned:
LOG.debug("Stopping client") LOG.debug("Stopping client")
self._closing = True
kazoo_utils.finalize_client(self._client) kazoo_utils.finalize_client(self._client)
if self._worker is not None: if self._worker is not None:
LOG.debug("Shutting down the notifier") LOG.debug("Shutting down the notifier")
@ -818,6 +824,7 @@ class ZookeeperJobBoard(base.NotifyingJobBoard):
if timeout is not None: if timeout is not None:
timeout = float(timeout) timeout = float(timeout)
self._client.start(timeout=timeout) self._client.start(timeout=timeout)
self._closing = False
except (self._client.handler.timeout_exception, except (self._client.handler.timeout_exception,
k_exceptions.KazooException): k_exceptions.KazooException):
excp.raise_with_cause(excp.JobFailure, excp.raise_with_cause(excp.JobFailure,