diff --git a/consul/base.py b/consul/base.py index 09203b6d..8760a35b 100755 --- a/consul/base.py +++ b/consul/base.py @@ -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): @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index 66f70ca5..16d89629 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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) @@ -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 @@ -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 @@ -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) diff --git a/tests/consul.linux64 b/tests/consul.linux64 index c92f9421..2d4e23a0 100755 Binary files a/tests/consul.linux64 and b/tests/consul.linux64 differ diff --git a/tests/consul.osx b/tests/consul.osx index 0c79f438..c04427b6 100755 Binary files a/tests/consul.osx and b/tests/consul.osx differ diff --git a/tests/test_aio.py b/tests/test_aio.py index b6e0c943..cca60b73 100644 --- a/tests/test_aio.py +++ b/tests/test_aio.py @@ -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, @@ -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() diff --git a/tests/test_std.py b/tests/test_std.py index ad6e45be..6aef1e72 100644 --- a/tests/test_std.py +++ b/tests/test_std.py @@ -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 @@ -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 @@ -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) @@ -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" @@ -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]) == \ @@ -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') @@ -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) @@ -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 " \ @@ -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, \ @@ -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) diff --git a/tests/test_tornado.py b/tests/test_tornado.py index dbe859be..fd7aba7b 100644 --- a/tests/test_tornado.py +++ b/tests/test_tornado.py @@ -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, @@ -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) diff --git a/tests/test_twisted.py b/tests/test_twisted.py index ce380005..e07c7837 100644 --- a/tests/test_twisted.py +++ b/tests/test_twisted.py @@ -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, @@ -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