diff options
author | Alex Shatov <alexs@att.com> | 2018-09-18 15:48:07 -0400 |
---|---|---|
committer | Alex Shatov <alexs@att.com> | 2018-09-18 15:48:07 -0400 |
commit | 2d0b15c1bfc707e37447d4b64686285c1e23c533 (patch) | |
tree | e7fa997c4538b1ecc65de78af84bc7f47bac3ebb /policyhandler | |
parent | 6556fd79eb177d8ed7c390d56410b42afb4a0c70 (diff) |
4.3.1 policy-handler - tls on web-socket
- if tls on web-socket to policy-engine fails,
retry connecting after a prolonged delay (60secs) under expectation
that the config might change in consul-kv for the policy-handler
that will fix the tls problem - relying on the periodic reconfigure
feature of the policy-handler
Change-Id: Id89f5346a99d572bace551e20a583f4c08374fc4
Signed-off-by: Alex Shatov <alexs@att.com>
Issue-ID: DCAEGEN2-611
Diffstat (limited to 'policyhandler')
-rw-r--r-- | policyhandler/policy_receiver.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/policyhandler/policy_receiver.py b/policyhandler/policy_receiver.py index 96afd59..3ae25fc 100644 --- a/policyhandler/policy_receiver.py +++ b/policyhandler/policy_receiver.py @@ -57,6 +57,7 @@ class _PolicyReceiver(Thread): self._keep_running = True self._settings = Settings(Config.FIELD_POLICY_ENGINE) + self._sleep_before_restarting = 5 self._web_socket_url = None self._web_socket_sslopt = None self._tls_wss_ca_mode = None @@ -69,6 +70,7 @@ class _PolicyReceiver(Thread): def reconfigure(self): """configure and reconfigure the web-socket""" with self._lock: + self._sleep_before_restarting = 5 self._settings.set_config(Config.discovered_config) changed, config = self._settings.get_by_key(Config.FIELD_POLICY_ENGINE) @@ -126,7 +128,13 @@ class _PolicyReceiver(Thread): self._stop_notifications() if restarting: - time.sleep(5) + with self._lock: + sleep_before_restarting = self._sleep_before_restarting + _PolicyReceiver._logger.info( + "going to sleep for %s secs before restarting policy-notifications", + sleep_before_restarting) + + time.sleep(sleep_before_restarting) if not self._get_keep_running(): break @@ -205,7 +213,8 @@ class _PolicyReceiver(Thread): def _on_ws_error(self, error): """report an error""" - _PolicyReceiver._logger.exception("policy-notification error: %s", str(error)) + _PolicyReceiver._logger.exception("policy-notification error %s", str(error)) + self._sleep_before_restarting = 60 if isinstance(error, ssl.SSLError) else 5 def _on_ws_close(self, code, reason): """restart web-socket on close""" |