Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions consul/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def deregister(self, service_id):
take care of deregistering the service with the Catalog. If
there is an associated check, that is also deregistered.
"""
return self.agent.http.get(
return self.agent.http.put(
CB.bool(), '/v1/agent/service/deregister/%s' % service_id)

def maintenance(self, service_id, enable, reason=None):
Expand Down Expand Up @@ -999,7 +999,7 @@ def deregister(self, check_id):
"""
Remove a check from the local agent.
"""
return self.agent.http.get(
return self.agent.http.put(
CB.bool(),
'/v1/agent/check/deregister/%s' % check_id)

Expand All @@ -1012,7 +1012,7 @@ def ttl_pass(self, check_id, notes=None):
if notes:
params['note'] = notes

return self.agent.http.get(
return self.agent.http.put(
CB.bool(),
'/v1/agent/check/pass/%s' % check_id,
params=params)
Expand All @@ -1027,7 +1027,7 @@ def ttl_fail(self, check_id, notes=None):
if notes:
params['note'] = notes

return self.agent.http.get(
return self.agent.http.put(
CB.bool(),
'/v1/agent/check/fail/%s' % check_id,
params=params)
Expand All @@ -1042,7 +1042,7 @@ def ttl_warn(self, check_id, notes=None):
if notes:
params['note'] = notes

return self.agent.http.get(
return self.agent.http.put(
CB.bool(),
'/v1/agent/check/warn/%s' % check_id,
params=params)
Expand Down
18 changes: 10 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def start_consul_instance(acl_master_token=None):
instance is listening on
"""
ports = dict(zip(
['http', 'rpc', 'serf_lan', 'serf_wan', 'server', 'dns'],
get_free_ports(5) + [-1]))
['http', 'serf_lan', 'serf_wan', 'server', 'dns'],
get_free_ports(4) + [-1]))

config = {'ports': ports, 'performance': {'raft_multiplier': 1}}
config = {'ports': ports, 'performance': {'raft_multiplier': 1},
'enable_script_checks': True}
if acl_master_token:
config['acl_datacenter'] = 'dc1'
config['acl_master_token'] = acl_master_token
Expand All @@ -73,9 +74,9 @@ def start_consul_instance(acl_master_token=None):
else:
postfix = 'linux64'
bin = os.path.join(os.path.dirname(__file__), 'consul.'+postfix)
command = '{bin} agent -server -bootstrap' \
command = '{bin} agent -dev' \
' -bind=127.0.0.1' \
' -config-dir=. -data-dir=./data'
' -config-dir=.'
command = command.format(bin=bin).strip()
command = shlex.split(command)

Expand All @@ -91,6 +92,7 @@ def start_consul_instance(acl_master_token=None):
response = requests.get(base_uri + 'status/leader')
except requests.ConnectionError:
continue
print(response.text)
if response.text.strip() != '""':
break

Expand All @@ -102,13 +104,13 @@ def start_consul_instance(acl_master_token=None):
break
time.sleep(0.1)

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


@pytest.yield_fixture(scope="session")
@pytest.yield_fixture(scope="module")
def consul_instance():
p, port = start_consul_instance()
yield port
Expand All @@ -123,7 +125,7 @@ def consul_port(consul_instance):
requests.delete(base_uri + 'kv/?recurse=1')


@pytest.yield_fixture(scope="session")
@pytest.yield_fixture(scope="module")
def acl_consul_instance():
acl_master_token = uuid.uuid4().hex
p, port = start_consul_instance(acl_master_token=acl_master_token)
Expand Down
Binary file modified tests/consul.linux64
Binary file not shown.
Binary file modified tests/consul.osx
Binary file not shown.
5 changes: 1 addition & 4 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,10 @@ def test_agent_services(self, loop, consul_port):
def main():
c = consul.aio.Consul(port=consul_port, loop=loop)
services = yield from c.agent.services()
del services['consul']
assert services == {}
response = yield from c.agent.service.register('foo')
assert response is True
services = yield from c.agent.services()
del services['consul']
assert services == {
'foo': {
'Port': 0,
Expand All @@ -183,12 +181,11 @@ def main():
'ModifyIndex': 0,
'EnableTagOverride': False,
'Service': 'foo',
'Tags': None,
'Tags': [],
'Address': ''}, }
response = yield from c.agent.service.deregister('foo')
assert response is True
services = yield from c.agent.services()
del services['consul']
assert services == {}
c.close()

Expand Down
47 changes: 25 additions & 22 deletions tests/test_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ def test_agent_checks_service_id(self, consul_port):
time.sleep(40/1000.0)

index, nodes = c.health.service('foo1')
assert [
assert set([
check['ServiceID'] for node in nodes
for check in node['Checks']] == ['foo1', '']
assert [
for check in node['Checks']]) == set(['foo1', ''])
assert set([
check['CheckID'] for node in nodes
for check in node['Checks']] == ['foo', 'serfHealth']
for check in node['Checks']]) == set(['foo', 'serfHealth'])

# Clean up tasks
assert c.agent.check.deregister('foo') is True
Expand Down Expand Up @@ -395,16 +395,16 @@ def test_agent_members(self, consul_port):

def test_agent_self(self, consul_port):
c = consul.Consul(port=consul_port)
assert set(c.agent.self().keys()) == set(['Member', 'Coord', 'Config',
'Stats'])
assert set(c.agent.self().keys()) == set(['Member', 'Stats', 'Config',
'Coord', 'DebugConfig',
'Meta'])

def test_agent_services(self, consul_port):
c = consul.Consul(port=consul_port)
assert set(c.agent.services().keys()) == set(['consul'])
assert c.agent.service.register('foo') is True
assert set(c.agent.services().keys()) == set(['consul', 'foo'])
assert set(c.agent.services().keys()) == set(['foo'])
assert c.agent.service.deregister('foo') is True
assert set(c.agent.services().keys()) == set(['consul'])
assert set(c.agent.services().keys()) == set()

# test address param
assert c.agent.service.register('foo', address='10.10.10.1') is True
Expand Down Expand Up @@ -764,7 +764,9 @@ def test_acl_explict_token_use(self, acl_consul):
consul.ACLPermissionDenied, c.kv.delete, 'foo', token=token)

assert c.kv.get('private/foo')[1]['Value'] == six.b('bar')
assert c.kv.get('private/foo', token=token)[1] is None
pytest.raises(
consul.ACLPermissionDenied,
c.kv.get, 'private/foo', token=token)
pytest.raises(
consul.ACLPermissionDenied,
c.kv.put, 'private/foo', 'bar2', token=token)
Expand All @@ -773,7 +775,9 @@ def test_acl_explict_token_use(self, acl_consul):
c.kv.delete, 'private/foo', token=token)

# test token pass through for service registration
c.agent.service.register("bar-1", token=token)
pytest.raises(
consul.ACLPermissionDenied,
c.agent.service.register, "bar-1", token=token)
c.agent.service.register("foo-1", token=token)
index, data = c.health.service('foo-1', token=token)
assert data[0]['Service']['ID'] == "foo-1"
Expand All @@ -784,7 +788,6 @@ def test_acl_explict_token_use(self, acl_consul):

# clean up
assert c.agent.service.deregister('foo-1') is True
assert c.agent.service.deregister('bar-1') is True
c.acl.destroy(token, token=master_token)
acls = c.acl.list(token=master_token)
assert set([x['ID'] for x in acls]) == \
Expand Down Expand Up @@ -835,7 +838,9 @@ def test_acl_implicit_token_use(self, acl_consul):
consul.ACLPermissionDenied, c_limited.kv.delete, 'foo')

assert c.kv.get('private/foo')[1]['Value'] == six.b('bar')
assert c_limited.kv.get('private/foo')[1] is None
pytest.raises(
consul.ACLPermissionDenied,
c_limited.kv.get, 'private/foo')
pytest.raises(
consul.ACLPermissionDenied,
c_limited.kv.put, 'private/foo', 'bar2')
Expand All @@ -844,7 +849,10 @@ def test_acl_implicit_token_use(self, acl_consul):
c_limited.kv.delete, 'private/foo')

# check we can override the client's default token
assert c.kv.get('private/foo', token=token)[1] is None
pytest.raises(
consul.ACLPermissionDenied,
c.kv.get, 'private/foo', token=token
)
pytest.raises(
consul.ACLPermissionDenied,
c.kv.put, 'private/foo', 'bar2', token=token)
Expand All @@ -862,11 +870,8 @@ def test_status_leader(self, consul_port):
c = consul.Consul(port=consul_port)

agent_self = c.agent.self()
port = agent_self['Config']['Ports']['Server']
addr = agent_self['Config']['AdvertiseAddr']

addr_port = "{0}:{1}".format(addr, port)
leader = c.status.leader()
addr_port = agent_self['Stats']['consul']['leader_addr']

assert leader == addr_port, \
"Leader value was {0}, expected value " \
Expand All @@ -877,10 +882,8 @@ def test_status_peers(self, consul_port):
c = consul.Consul(port=consul_port)

agent_self = c.agent.self()
port = agent_self['Config']['Ports']['Server']
addr = agent_self['Config']['AdvertiseAddr']

addr_port = "{0}:{1}".format(addr, port)
addr_port = agent_self['Stats']['consul']['leader_addr']
peers = c.status.peers()

assert addr_port in peers, \
Expand Down Expand Up @@ -922,7 +925,7 @@ def test_coordinate(self, consul_port):
c.coordinate.nodes()
c.coordinate.datacenters()
assert set(c.coordinate.datacenters()[0].keys()) == \
set(['Datacenter', 'Coordinates'])
set(['Datacenter', 'Coordinates', 'AreaID'])

def test_operator(self, consul_port):
c = consul.Consul(port=consul_port)
Expand Down
5 changes: 1 addition & 4 deletions tests/test_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,10 @@ def test_agent_services(self, loop, consul_port):
def main():
c = consul.tornado.Consul(port=consul_port)
services = yield c.agent.services()
del services['consul']
assert services == {}
response = yield c.agent.service.register('foo')
assert response is True
services = yield c.agent.services()
del services['consul']
assert services == {
'foo': {
'Port': 0,
Expand All @@ -200,12 +198,11 @@ def main():
'ModifyIndex': 0,
'EnableTagOverride': False,
'Service': 'foo',
'Tags': None,
'Tags': [],
'Address': ''}, }
response = yield c.agent.service.deregister('foo')
assert response is True
services = yield c.agent.services()
del services['consul']
assert services == {}
loop.stop()
loop.run_sync(main)
Expand Down
5 changes: 1 addition & 4 deletions tests/test_twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ def test_transaction(self, consul_port):
def test_agent_services(self, consul_port):
c = consul.twisted.Consul(port=consul_port)
services = yield c.agent.services()
del services['consul']
assert services == {}
response = yield c.agent.service.register('foo')
assert response is True
services = yield c.agent.services()
del services['consul']
assert services == {
'foo': {
'Port': 0,
Expand All @@ -126,13 +124,12 @@ def test_agent_services(self, consul_port):
'ModifyIndex': 0,
'EnableTagOverride': False,
'Service': 'foo',
'Tags': None,
'Tags': [],
'Address': ''}
}
response = yield c.agent.service.deregister('foo')
assert response is True
services = yield c.agent.services()
del services['consul']
assert services == {}

@pytest.inlineCallbacks
Expand Down