Skip to content
This repository was archived by the owner on Nov 18, 2017. It is now read-only.

Commit 5385850

Browse files
committed
Merge pull request #39 from cakester/master
handle ssl exception; fix #37
2 parents 5c070ed + b0a9c7f commit 5385850

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

governor.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
import sys, os, yaml, time, urllib2, atexit
3+
import sys, os, yaml, time, urllib2, atexit, ssl
44
import logging
55

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

helpers/etcd.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import urllib2, json, os, time, base64
1+
import urllib2, json, os, time, base64, ssl
22
import logging
33
from urllib import urlencode
44
import helpers.errors
@@ -28,7 +28,7 @@ def get_client_path(self, path, max_attempts=1):
2828
request.add_header("Authorization", "Basic %s" % base64string)
2929
response = urllib2.urlopen(request, timeout=self.timeout).read()
3030
break
31-
except (urllib2.HTTPError, urllib2.URLError) as e:
31+
except (urllib2.HTTPError, urllib2.URLError, ssl.SSLError) as e:
3232
attempts += 1
3333
if attempts < max_attempts:
3434
logger.warning("Failed to return %s, trying again. (%s of %s)" % (path, attempts, max_attempts))
@@ -61,7 +61,7 @@ def current_leader(self):
6161
if e.code == 404:
6262
return None
6363
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
64-
except urllib2.URLError:
64+
except (urllib2.URLError, ssl.SSLError):
6565
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
6666

6767
def members(self):
@@ -77,7 +77,7 @@ def members(self):
7777
if e.code == 404:
7878
return None
7979
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
80-
except urllib2.URLError:
80+
except (urllib2.URLError, ssl.SSLError):
8181
raise helpers.errors.CurrentLeaderError("Etcd is not responding properly")
8282

8383

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

100100
def update_leader(self, state_handler):
@@ -112,7 +112,7 @@ def last_leader_operation(self):
112112
if e.code == 404:
113113
logger.error("Error updating TTL on ETCD for primary.")
114114
return None
115-
except urllib2.URLError:
115+
except (urllib2.URLError, ssl.SSLError):
116116
logger.error("Error updating TTL on ETCD for primary.")
117117
return None
118118

@@ -128,19 +128,17 @@ def leader_unlocked(self):
128128
return False
129129
except ValueError:
130130
return False
131+
except ssl.SSLError:
132+
return False
131133

132134
def am_i_leader(self, value):
133135
try:
134136
reponse = self.get_client_path("/leader")
135137
logger.info("Lock owner: %s; I am %s" % (reponse["node"]["value"], value))
136138
return reponse["node"]["value"] == value
137-
except urllib2.HTTPError:
139+
except (urllib2.HTTPError, ssl.SSLError, urllib2.URLError):
138140
logger.error("Couldn't reach etcd")
139141
return False
140-
except urllib2.URLError:
141-
logger.error("Couldn't reach etcd")
142-
return False
143-
144142

145143
def race(self, path, value):
146144
while True:
@@ -152,6 +150,6 @@ def race(self, path, value):
152150
else:
153151
logger.warning("etcd is not ready for connections")
154152
time.sleep(10)
155-
except urllib2.URLError:
153+
except (urllib2.URLError, ssl.SSLError):
156154
logger.warning("Issue connecting to etcd")
157155
time.sleep(10)

0 commit comments

Comments
 (0)