Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit 1b5aa6e

Browse files
authored
Merge branch 'master' into add-node-meta-parameter
2 parents 881a2d6 + b91a692 commit 1b5aa6e

17 files changed

+126
-95
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[bumpversion]
22
commit = True
33
tag = True
4-
current_version = 0.7.3-dev
4+
current_version = 1.0.1
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
66
serialize =
77
{major}.{minor}.{patch}-{release}

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ python:
44
- 2.6
55
- 2.7
66
- pypy-5.3.1
7-
- 3.4
87
- 3.5
98
- 3.6
109

CHANGELOG.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Change log
22
==========
33

4-
0.7.3-dev
5-
---------
4+
1.0.1
5+
-----
66

7-
* TBD
7+
* Support for Python 3.4 dropped (sorry)
8+
* Add support for Consul 1.0.0 (thanks @matusvalo!)
9+
* Expose all 400 errors and add tests for common callback handler (thanks @bagerard)
810

911
0.7.2
1012
-----

README.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Documentation
99
Status
1010
------
1111

12-
|Build Status|\ |Coverage Status|
12+
|Build Status|
1313

1414
Example
1515
-------
@@ -51,6 +51,11 @@ There's a few API endpoints still to go to expose all features available in
5151
Consul v0.6.0. If you need an endpoint that's not in the documentation, just
5252
open an issue and I'll try and add it straight away.
5353

54+
Mailing List
55+
------------
56+
57+
- https://groups.google.com/forum/#!forum/python-consul
58+
5459
Contributing
5560
------------
5661

consul/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.7.3-dev'
1+
__version__ = '1.0.1'
22

33
from consul.std import Consul
44

consul/base.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class BadRequest(ConsulException):
3636
pass
3737

3838

39+
class ClientError(ConsulException):
40+
"""Encapsulates 4xx Http error code"""
41+
pass
42+
43+
3944
#
4045
# Convenience to define checks
4146

@@ -158,24 +163,28 @@ def _compat(
158163

159164
class CB(object):
160165
@classmethod
161-
def __status(klass, response, allow_404=True):
166+
def _status(klass, response, allow_404=True):
162167
# status checking
163-
if response.code >= 500 and response.code < 600:
168+
if 400 <= response.code < 500:
169+
if response.code == 400:
170+
raise BadRequest('%d %s' % (response.code, response.body))
171+
elif response.code == 401:
172+
raise ACLDisabled(response.body)
173+
elif response.code == 403:
174+
raise ACLPermissionDenied(response.body)
175+
elif response.code == 404:
176+
if not allow_404:
177+
raise NotFound(response.body)
178+
else:
179+
raise ClientError("%d %s" % (response.code, response.body))
180+
elif 500 <= response.code < 600:
164181
raise ConsulException("%d %s" % (response.code, response.body))
165-
if response.code == 400:
166-
raise BadRequest('%d %s' % (response.code, response.body))
167-
if response.code == 401:
168-
raise ACLDisabled(response.body)
169-
if response.code == 403:
170-
raise ACLPermissionDenied(response.body)
171-
if response.code == 404 and not allow_404:
172-
raise NotFound(response.body)
173182

174183
@classmethod
175184
def bool(klass):
176185
# returns True on successful response
177186
def cb(response):
178-
CB.__status(response)
187+
CB._status(response)
179188
return response.code == 200
180189
return cb
181190

@@ -204,7 +213,7 @@ def json(
204213
*is_id* only the 'ID' field of the json object will be returned.
205214
"""
206215
def cb(response):
207-
CB.__status(response, allow_404=allow_404)
216+
CB._status(response, allow_404=allow_404)
208217
if response.code == 404:
209218
return response.headers['X-Consul-Index'], None
210219

@@ -886,7 +895,7 @@ def deregister(self, service_id):
886895
take care of deregistering the service with the Catalog. If
887896
there is an associated check, that is also deregistered.
888897
"""
889-
return self.agent.http.get(
898+
return self.agent.http.put(
890899
CB.bool(), '/v1/agent/service/deregister/%s' % service_id)
891900

892901
def maintenance(self, service_id, enable, reason=None):
@@ -999,7 +1008,7 @@ def deregister(self, check_id):
9991008
"""
10001009
Remove a check from the local agent.
10011010
"""
1002-
return self.agent.http.get(
1011+
return self.agent.http.put(
10031012
CB.bool(),
10041013
'/v1/agent/check/deregister/%s' % check_id)
10051014

@@ -1012,7 +1021,7 @@ def ttl_pass(self, check_id, notes=None):
10121021
if notes:
10131022
params['note'] = notes
10141023

1015-
return self.agent.http.get(
1024+
return self.agent.http.put(
10161025
CB.bool(),
10171026
'/v1/agent/check/pass/%s' % check_id,
10181027
params=params)
@@ -1027,7 +1036,7 @@ def ttl_fail(self, check_id, notes=None):
10271036
if notes:
10281037
params['note'] = notes
10291038

1030-
return self.agent.http.get(
1039+
return self.agent.http.put(
10311040
CB.bool(),
10321041
'/v1/agent/check/fail/%s' % check_id,
10331042
params=params)
@@ -1042,7 +1051,7 @@ def ttl_warn(self, check_id, notes=None):
10421051
if notes:
10431052
params['note'] = notes
10441053

1045-
return self.agent.http.get(
1054+
return self.agent.http.put(
10461055
CB.bool(),
10471056
'/v1/agent/check/warn/%s' % check_id,
10481057
params=params)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def run_tests(self):
7272
'Programming Language :: Python :: 2',
7373
'Programming Language :: Python :: 2.7',
7474
'Programming Language :: Python :: 3',
75-
'Programming Language :: Python :: 3.4',
75+
'Programming Language :: Python :: 3.5',
76+
'Programming Language :: Python :: 3.6',
7677
],
7778
)

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Required metadata
22
sonar.projectKey=com.github:cablehead:python-consul
33
sonar.projectName=Python Consul
4-
sonar.projectVersion=0.7.3-dev
4+
sonar.projectVersion=1.0.1
55

66
# Comma-separated paths to directories with sources (required)
77
sonar.sources=consul

tests/conftest.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
collect_ignore.append(p)
2727
p = os.path.join(os.path.dirname(__file__), 'test_tornado.py')
2828
collect_ignore.append(p)
29-
else:
30-
pytest_plugins = "pytest_twisted"
3129

3230

3331
def get_free_ports(num, host=None):
@@ -55,10 +53,11 @@ def start_consul_instance(acl_master_token=None):
5553
instance is listening on
5654
"""
5755
ports = dict(zip(
58-
['http', 'rpc', 'serf_lan', 'serf_wan', 'server', 'dns'],
59-
get_free_ports(5) + [-1]))
56+
['http', 'serf_lan', 'serf_wan', 'server', 'dns'],
57+
get_free_ports(4) + [-1]))
6058

61-
config = {'ports': ports, 'performance': {'raft_multiplier': 1}}
59+
config = {'ports': ports, 'performance': {'raft_multiplier': 1},
60+
'enable_script_checks': True}
6261
if acl_master_token:
6362
config['acl_datacenter'] = 'dc1'
6463
config['acl_master_token'] = acl_master_token
@@ -73,9 +72,9 @@ def start_consul_instance(acl_master_token=None):
7372
else:
7473
postfix = 'linux64'
7574
bin = os.path.join(os.path.dirname(__file__), 'consul.'+postfix)
76-
command = '{bin} agent -server -bootstrap' \
75+
command = '{bin} agent -dev' \
7776
' -bind=127.0.0.1' \
78-
' -config-dir=. -data-dir=./data'
77+
' -config-dir=.'
7978
command = command.format(bin=bin).strip()
8079
command = shlex.split(command)
8180

@@ -91,6 +90,7 @@ def start_consul_instance(acl_master_token=None):
9190
response = requests.get(base_uri + 'status/leader')
9291
except requests.ConnectionError:
9392
continue
93+
print(response.text)
9494
if response.text.strip() != '""':
9595
break
9696

@@ -102,13 +102,13 @@ def start_consul_instance(acl_master_token=None):
102102
break
103103
time.sleep(0.1)
104104

105-
requests.get(base_uri + 'agent/service/deregister/foo')
105+
requests.put(base_uri + 'agent/service/deregister/foo')
106106
# phew
107107
time.sleep(2)
108108
return p, ports['http']
109109

110110

111-
@pytest.yield_fixture(scope="session")
111+
@pytest.yield_fixture(scope="module")
112112
def consul_instance():
113113
p, port = start_consul_instance()
114114
yield port
@@ -123,7 +123,7 @@ def consul_port(consul_instance):
123123
requests.delete(base_uri + 'kv/?recurse=1')
124124

125125

126-
@pytest.yield_fixture(scope="session")
126+
@pytest.yield_fixture(scope="module")
127127
def acl_consul_instance():
128128
acl_master_token = uuid.uuid4().hex
129129
p, port = start_consul_instance(acl_master_token=acl_master_token)

tests/consul.linux64

18 MB
Binary file not shown.

0 commit comments

Comments
 (0)