Skip to content

Commit

Permalink
Fix watch util issue 18 and 78 (#82)
Browse files Browse the repository at this point in the history
* fix issue #78
add header to watch-event

Signed-off-by: Renjie Cai <crj93106@gmail.com>

* fix #61 handle watch cancel

* add unit test for compaction related

* pytest version

* fix test

* fix test

* cov
  • Loading branch information
Revolution1 committed Apr 17, 2019
1 parent 56adfea commit 2262636
Show file tree
Hide file tree
Showing 16 changed files with 310 additions and 2,444 deletions.
68 changes: 68 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Byte-compiled / optimized / DLL files
__pycache__
*.py[cod]
*$py.class
.pytest_cache

# C extensions
*.so

# Distribution / packaging
.Python
env
build
develop-eggs
dist
downloads
eggs
.eggs
lib
lib64
parts
sdist
var
*.egg-info
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build

# PyBuilder
target

# pyenv python configuration file
.python-version

etcd3/apis_generated
coverage_html_report
prof/
README.rst
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ python:

sudo: required

services:
- docker

services:
- docker

Expand All @@ -25,8 +22,9 @@ env:
# - ETCD_VER=v3.3.4
# - ETCD_VER=v3.3.7
# - ETCD_VER=v3.3.9
- ETCD_VER=v3.3.10

# - ETCD_VER=v3.3.10
- ETCD_VER=v3.3.12


before_install:
- sudo docker pull quay.io/coreos/etcd:$ETCD_VER
Expand Down
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG PYTHON_VER=3.6
ARG ETCD_VER=v3.3.12

FROM python:${PYTHON_VER}

ENV DOCKER_CHANNEL stable
ENV DOCKER_VERSION 18.09.5
ENV dockerArch x86_64
ENV ETCD_VER ${ETCD_VER:-v3.3.12}

RUN wget -O docker.tgz "https://download.docker.com/linux/static/${DOCKER_CHANNEL}/${dockerArch}/docker-${DOCKER_VERSION}.tgz" && \
tar xvzf docker.tgz && \
cp docker/docker /usr/bin/

RUN wget -O etcd.tgz https://github.com/etcd-io/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz && \
tar xvzf etcd.tgz && \
cp etcd-${ETCD_VER}-linux-amd64/etcdctl /usr/bin/


WORKDIR /etcd3

COPY requirements*.txt /etcd3/
RUN pip install -r requirements_dev_py3.txt

COPY . /etcd3/

RUN python ./setup.py install

CMD pytest -s -v
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Notice: The authentication header through gRPC-JSON-Gateway only supported in [e

## Features

* [x] Support python2.7 and python3.5+
* [x] Support python2.7 and python3.5+ (aiohttp requires python3.5.2+)
* [x] Sync client based on requests
* [x] Async client based on aiohttp
* [x] TLS Connection
Expand Down
11 changes: 9 additions & 2 deletions etcd3/aio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def __init__(self, client, method, resp, decode=True):
self.decode = decode
self.method = method

@property
def connection(self):
return self.resp.connection

@property
def resp_iter(self):
return ResponseIter(self.resp)
Expand All @@ -67,13 +71,16 @@ def __enter__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()

# def __del__(self):
# self.close()

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
self.close()

async def __aiter__(self):
def __aiter__(self):
return self

async def __anext__(self):
Expand Down Expand Up @@ -111,7 +118,7 @@ def __init__(self, resp):
self.left_chunk = b''
self.i = 0

async def __aiter__(self):
def __aiter__(self):
return self

async def next(self):
Expand Down
7 changes: 7 additions & 0 deletions etcd3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def __init__(self, client, method, resp, decode=True):
self.resp = resp
self.decode = decode

@property
def raw(self):
return self.resp.raw

def close(self):
"""
close the stream
Expand All @@ -41,6 +45,9 @@ def __enter__(self):

def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
#
# def __del__(self):
# self.close()

def __iter__(self):
for data in iter_response(self.resp):
Expand Down
5 changes: 3 additions & 2 deletions etcd3/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# flake8: noqa
from .errors import Etcd3StreamError
from .errors import get_client_error
from .errors import Etcd3WatchCanceled
from .errors import UnsupportedServerVersion
from .errors import get_client_error
from .go_etcd_rpctypes_error import ErrAuthFailed
from .go_etcd_rpctypes_error import ErrAuthNotEnabled
from .go_etcd_rpctypes_error import ErrCompacted
Expand Down Expand Up @@ -46,7 +47,7 @@
from .go_etcd_rpctypes_error import ErrValueProvided
from .go_etcd_rpctypes_error import Etcd3Exception

__all__ = ['Etcd3Exception', 'get_client_error', 'Etcd3StreamError', 'UnsupportedServerVersion']
__all__ = ['Etcd3Exception', 'get_client_error', 'Etcd3StreamError', 'Etcd3WatchCanceled', 'UnsupportedServerVersion']

__all__ += [
'ErrEmptyKey',
Expand Down
6 changes: 6 additions & 0 deletions etcd3/errors/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def __init__(self, error, buf, resp):
self.resp = resp


class Etcd3WatchCanceled(Etcd3Exception): # pragma: no cover
def __init__(self, error, resp):
self.error = error
self.resp = resp


def get_client_error(error, code, status, response=None):
if six.PY3 and not isinstance(error, six.string_types):
error = six.text_type(error, encoding='utf-8')
Expand Down

0 comments on commit 2262636

Please sign in to comment.