Fix issues with zookeeper (#1792)

1. The `ttl` was incorrectly returned 1000 times higher then it should
2. The `watch()` method must return True if the parent method returned True. Not doing so resulted in the incorrect calculation of sleep time.
3. Move mock of exhibitor api to the features/environment.py. It simplifies testing with behave.
This commit is contained in:
Alexander Kukushkin
2020-12-14 15:12:57 +01:00
committed by GitHub
parent 1530ed0b9c
commit e3ef9ac306
4 changed files with 27 additions and 15 deletions
+20 -1
View File
@@ -13,6 +13,8 @@ import threading
import time
import yaml
from six.moves.BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
@six.add_metaclass(abc.ABCMeta)
class AbstractController(object):
@@ -559,11 +561,28 @@ class ZooKeeperController(AbstractDcsController):
return False
class MockExhibitor(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'{"servers":["127.0.0.1"],"port":2181}')
def log_message(self, fmt, *args):
pass
class ExhibitorController(ZooKeeperController):
def __init__(self, context):
super(ExhibitorController, self).__init__(context, False)
os.environ.update({'PATRONI_EXHIBITOR_HOSTS': 'localhost', 'PATRONI_EXHIBITOR_PORT': '8181'})
port = 8181
exhibitor = HTTPServer(('', port), MockExhibitor)
exhibitor.daemon_thread = True
exhibitor_thread = threading.Thread(target=exhibitor.serve_forever)
exhibitor_thread.daemon = True
exhibitor_thread.start()
os.environ.update({'PATRONI_EXHIBITOR_HOSTS': 'localhost', 'PATRONI_EXHIBITOR_PORT': str(port)})
class RaftController(AbstractDcsController):