Skip to content

Commit

Permalink
Wait for ready to serve client after elect leader
Browse files Browse the repository at this point in the history
- etcdctl use etcd v3 API (ETCDCTL_API=3)
- travis to use etcd v3.4.13
  • Loading branch information
ainoniwa committed Oct 17, 2020
1 parent 517aaab commit 7496e5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ before_install:
- wget https://archive.apache.org/dist/kafka/2.6.0/kafka_2.12-2.6.0.tgz -O /opt/kafka.tar.gz
- tar -xzf /opt/kafka.tar.gz -C /opt
- ln -s /opt/kafka_2.12-2.6.0 /opt/kafka
- wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz -O /opt/etcd.tar.gz
- tar -zxf /opt/etcd.tar.gz -C /opt
- ln -s /opt/etcd-v3.4.13-linux-amd64/etcd /opt/etcd
- ln -s /opt/etcd-v3.4.13-linux-amd64/etcdctl /opt/etcdctl
install:
# The install requirements in travis virtualenv that will be cached
- pip install tox-travis .[test,ceph]
Expand Down
6 changes: 4 additions & 2 deletions pifpaf/drivers/etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _setUp(self):
for i, (peer_url, client_url)
in enumerate(http_urls)),
"--initial-cluster-state", "new",
], wait_for_line="listening for client requests on")
], wait_for_line="listening for peers on")

endpoints = ",".join(client_url
for peer_url, client_url in http_urls)
Expand All @@ -81,11 +81,13 @@ def _setUp(self):
"--listen-peer-urls", peer_url,
"--listen-client-urls", client_url,
"--advertise-client-urls", client_url],
wait_for_line="listening for client requests on")
wait_for_line="ready to serve client requests")
endpoints = client_url

self.putenv("ETCD_PORT", str(self.port))
self.putenv("ETCD_PEER_PORT", str(self.peer_port))
self.putenv("HTTP_URL", "http://localhost:%d" % self.port)
self.putenv("URL", "etcd://localhost:%d" % self.port)
self.putenv("ETCDCTL_ENDPOINTS", endpoints, True)
self.putenv("ETCDCTL_API", "3", True)
self._exec(["etcdctl", "endpoint", "health"])
8 changes: 6 additions & 2 deletions pifpaf/tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def test_elasticsearch(self):

@testtools.skipUnless(spawn.find_executable("etcd"),
"etcd not found")
@testtools.skipUnless(spawn.find_executable("etcdctl"),
"etcdctl not found")
def test_etcd(self):
port = 4005
peer_port = 4006
Expand All @@ -129,10 +131,12 @@ def test_etcd(self):
self.assertEqual(str(port), os.getenv("PIFPAF_ETCD_PORT"))
r = requests.get("http://localhost:%d/version" % port)
self.assertEqual(200, r.status_code)
self._run("etcdctl cluster-health")
self._run("etcdctl endpoint health")

@testtools.skipUnless(spawn.find_executable("etcd"),
"etcd not found")
@testtools.skipUnless(spawn.find_executable("etcdctl"),
"etcdctl not found")
def test_etcd_cluster(self):
port = 4007
peer_port = 4008
Expand All @@ -143,7 +147,7 @@ def test_etcd_cluster(self):
self.assertEqual(str(port), os.getenv("PIFPAF_ETCD_PORT"))
r = requests.get("http://localhost:%d/version" % port)
self.assertEqual(200, r.status_code)
self._run("etcdctl cluster-health")
self._run("etcdctl endpoint health")

@testtools.skipUnless(spawn.find_executable("consul"),
"consul not found")
Expand Down

0 comments on commit 7496e5e

Please sign in to comment.