etcd: fix acquire(blocking=True) on request exception

If requests raises an exception and blocking is True, then there's no watch and
nothing is returned. The problem is that then the reply variable is checked but
it is actually not assigned, so a NameError is raised.

This makes sure False is returned if an error occurs and blocking is True.

Change-Id: I078826a894ee2cb8754259c8db9ea5ae19114910
This commit is contained in:
Julien Danjou 2017-05-19 10:50:06 +02:00
parent 9eb820bfde
commit 1a57bbcc24
1 changed files with 2 additions and 2 deletions

View File

@ -131,7 +131,7 @@ class EtcdLock(locking.Lock):
data={"ttl": self.ttl,
"prevExist": "false"})
except requests.exceptions.RequestException:
if watch and watch.leftover() == 0:
if not watch or watch.leftover() == 0:
return False
# We got the lock!
@ -156,7 +156,7 @@ class EtcdLock(locking.Lock):
make_url=False,
timeout=watch.leftover() if watch else None)
except requests.exceptions.RequestException:
if watch and watch.expired():
if not watch or watch.expired():
return False
@_translate_failures