Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request compose#39 from cakester/master
Browse files Browse the repository at this point in the history
handle ssl exception; fix compose#37
  • Loading branch information
Winslett committed May 31, 2016
2 parents 5c070ed + b0a9c7f commit 5385850
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
5 changes: 3 additions & 2 deletions governor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import sys, os, yaml, time, urllib2, atexit
import sys, os, yaml, time, urllib2, atexit, ssl
import logging

from helpers.etcd import Etcd
Expand All @@ -23,7 +23,8 @@ def wait_for_etcd(message, etcd, postgresql):
try:
etcd.touch_member(postgresql.name, postgresql.connection_string)
etcd_ready = True
except urllib2.URLError:
except (urllib2.URLError, ssl.SSLError) as e:
logging.info(e)
logging.info("waiting on etcd: %s" % message)
time.sleep(5)

Expand Down
22 changes: 10 additions & 12 deletions helpers/etcd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib2, json, os, time, base64
import urllib2, json, os, time, base64, ssl
import logging
from urllib import urlencode
import helpers.errors
Expand Down Expand Up @@ -28,7 +28,7 @@ def get_client_path(self, path, max_attempts=1):
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request, timeout=self.timeout).read()
break
except (urllib2.HTTPError, urllib2.URLError) as e:
except (urllib2.HTTPError, urllib2.URLError, ssl.SSLError) as e:
attempts += 1
if attempts < max_attempts:
logger.warning("Failed to return %s, trying again. (%s of %s)" % (path, attempts, max_attempts))
Expand Down Expand Up @@ -61,7 +61,7 @@ def current_leader(self):
if e.code == 404:
return None
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
except urllib2.URLError:
except (urllib2.URLError, ssl.SSLError):
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")

def members(self):
Expand All @@ -77,7 +77,7 @@ def members(self):
if e.code == 404:
return None
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
except urllib2.URLError:
except (urllib2.URLError, ssl.SSLError):
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")


Expand All @@ -94,7 +94,7 @@ def attempt_to_acquire_leader(self, value):
if e.code == 412:
logger.info("Could not take out TTL lock: %s" % e)
return False
except urllib2.URLError:
except (urllib2.URLError, ssl.SSLError):
return False

def update_leader(self, state_handler):
Expand All @@ -112,7 +112,7 @@ def last_leader_operation(self):
if e.code == 404:
logger.error("Error updating TTL on ETCD for primary.")
return None
except urllib2.URLError:
except (urllib2.URLError, ssl.SSLError):
logger.error("Error updating TTL on ETCD for primary.")
return None

Expand All @@ -128,19 +128,17 @@ def leader_unlocked(self):
return False
except ValueError:
return False
except ssl.SSLError:
return False

def am_i_leader(self, value):
try:
reponse = self.get_client_path("/leader")
logger.info("Lock owner: %s; I am %s" % (reponse["node"]["value"], value))
return reponse["node"]["value"] == value
except urllib2.HTTPError:
except (urllib2.HTTPError, ssl.SSLError, urllib2.URLError):
logger.error("Couldn't reach etcd")
return False
except urllib2.URLError:
logger.error("Couldn't reach etcd")
return False


def race(self, path, value):
while True:
Expand All @@ -152,6 +150,6 @@ def race(self, path, value):
else:
logger.warning("etcd is not ready for connections")
time.sleep(10)
except urllib2.URLError:
except (urllib2.URLError, ssl.SSLError):
logger.warning("Issue connecting to etcd")
time.sleep(10)

0 comments on commit 5385850

Please sign in to comment.