Skip to content

Commit

Permalink
add etcd version hint
Browse files Browse the repository at this point in the history
  • Loading branch information
revol.cai committed Mar 21, 2018
1 parent 688ef47 commit e0b6985
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ services:
services:
- docker

env:
matrix:
- ETCD_VER=v3.3

before_install:
- docker pull quay.io/coreos/etcd:v3.3
- docker run -d -p 2379:2379 -p 2380:2380 --name etcd3 quay.io/coreos/etcd:v3.3 etcd --name node1 --initial-advertise-peer-urls http://0.0.0.0:2380 --listen-peer-urls http://0.0.0.0:2380 --advertise-client-urls http://0.0.0.0:2379 --listen-client-urls http://0.0.0.0:2379 --initial-cluster node1=http://0.0.0.0:2380
- docker pull quay.io/coreos/etcd:$ETCD_VER
- docker run -d -p 2379:2379 -p 2380:2380 --name etcd3 quay.io/coreos/etcd:$ETCD_VER etcd --name node1 --initial-advertise-peer-urls http://0.0.0.0:2380 --listen-peer-urls http://0.0.0.0:2380 --advertise-client-urls http://0.0.0.0:2379 --listen-client-urls http://0.0.0.0:2379 --initial-cluster node1=http://0.0.0.0:2380
- docker ps
- sudo docker cp etcd3:/usr/local/bin/etcdctl /usr/bin/etcdctl
- which etcdctl
Expand All @@ -39,6 +43,6 @@ deploy:
secure: b/Ft9tCIAPddI7vkGCMZlkKWRi7Ahn73UMuXA+ZFhmTNQqM1SLjzUihfkrOJM5IzJC/42xCAxN6dgn2RpdqhJq5KhjlApFcPZawN1+S154jbjS/ss2Jn5ckryLFeITq8Fvud368r3i3EpqkEix0UK3QqMc5llnE/JtDPOS53azlKCetg6LAeMn4WrPwu74BC1lOSPG6fbW3OJ2o1Gu+/ToQrIoZUvy9yD7CyIto5OMIHI+hVV9TCJ8o6jQhAnWj5RxVJMmuONCpQ41cPVjIpvldakuxpFqH3mmGdPD7Nc4h7cmXbwthZLlBcI2oyFTxL9R5r4Sey8aFO/H5WaaBJMBauaAurLYkCVU4FIDxiTb/KwP09DnVWKlaXKB9Buv+LdO+IvG70VkkVFpeDxZ74VpvADoT+fx4gCSmPJiMDZGS2pxn7jcwH3qatWZ2aJZBg8DAMGNP+9AX+MNLFrPsipZQvl8Hq4DyztjLxjG//jwUwCzA5YrvXgBQmVQ40T64OZxTs//HS8GGE0zeb5FHwTXjomqp8bCOfIfpVwgmrkOY8d/fCz94JUtiUnU53EWqFQtfXiUIV5wAZzu5hVGGhghfw5yrgE4D/vp5ZwTH2/hY8n+VAOh4pimX0X+ob/LLMl4mnX64EPbwDKvx+beRPYxFBsOOZfAHoG6QszinVlao=
on:
tags: true
branch: master
python:
- 3.6
# branch: master
# python:
# - 3.6
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Python client for etcd v3 (Using gRPC-JSON-Gateway)
* Free software: Apache Software License 2.0
* Source Code: https://github.com/Revolution1/etcd3-py
* Documentation: https://etcd3-py.readthedocs.io.
* etcd version required: v3.3.0+

Notice: The authentication header through gRPC-JSON-Gateway only supported in [etcd v3.3+](https://github.com/coreos/etcd/pull/7999)
Notice: The authentication header through gRPC-JSON-Gateway only supported in [etcd v3.3.0+](https://github.com/coreos/etcd/pull/7999)

## Features

Expand Down Expand Up @@ -136,6 +137,22 @@ user2 got the lock
user2 releasing the lock
```

**Start a single-node etcd using docker**
```bash
export NODE1=0.0.0.0
export ETCD_VER=v3.3
docker run -d \
-p 2379:2379 \
-p 2380:2380 \
--volume=/tmp/etcd3-data:/etcd-data \
--name etcd3 quay.io/coreos/etcd:$ETCD_VER \
/usr/local/bin/etcd \
--data-dir=/etcd-data --name node1 \
--initial-advertise-peer-urls http://${NODE1}:2380 --listen-peer-urls http://${NODE1}:2380 \
--advertise-client-urls http://${NODE1}:2379 --listen-client-urls http://${NODE1}:2379 \
--initial-cluster node1=http://${NODE1}:2380
```

## TODO

- [ ] benchmark
Expand Down
9 changes: 5 additions & 4 deletions etcd3/baseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import warnings

import requests
import semantic_version as sem
from six.moves import urllib_parse

Expand Down Expand Up @@ -78,17 +77,19 @@ def __init__(self, host='localhost', port=2379, protocol='http',

def _retrieve_version(self): # pragma: no cover
try:
r = requests.get(self._url('/version'), timeout=0.3)
import requests

r = requests.get(self._url('/version'), timeout=0.3) # 300ms will do
r.raise_for_status()
v = r.json()
self.cluster_version = v["etcdcluster"]
if sem.compare(self.cluster_version, '3.3.0') == -1:
warnings.warn(Etcd3Warning("detected etcd cluster version(%s) is lower than 3.3.0, "
"auth method may not work" % self.cluster_version))
"the gRPC-JSON-Gateway may not work" % self.cluster_version))
except Exception:
warnings.warn(Etcd3Warning("cannot detect etcd server version\n"
"1. maybe is a network problem, please check your network connection\n"
"2. maybe your etcd server version is too low, recommended: 3.3.0+"))
"2. maybe your etcd server version is too low, required: 3.3.0+"))

@property
def baseurl(self):
Expand Down

0 comments on commit e0b6985

Please sign in to comment.