Handle refreshing of expired lease.

Refreshing of expired lease causes non-obvious error:
Retrying tooz.drivers.etcd3gw.Etcd3Driver.heartbeat
in 1.0 seconds as it raised KeyError: 'TTL'.
The patch handles the error.

Closes-Bug: 1895952
Change-Id: I440cedb711149a5f12eb2311e78181b01666d274
This commit is contained in:
Mitya_Eremeev 2022-05-23 19:45:04 +03:00 committed by mitya-eremeev-2
parent 0ed0945275
commit e35c7aa1f6

View File

@ -57,11 +57,14 @@ class Lease(object):
streaming keep alive responses from the server to the client.
This method makes a synchronous HTTP request by default.
:return:
:return: returns new TTL for lease. If lease was already expired then
TTL field is absent in response and the function returns -1
according to etcd documentation.
https://etcd.io/docs/v3.5/dev-guide/apispec/swagger/rpc.swagger.json
"""
result = self.client.post(self.client.get_url("/lease/keepalive"),
json={"ID": self.id})
return int(result['result']['TTL'])
return int(result['result'].get('TTL', -1))
def keys(self):
"""Get the keys associated with this lease.