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

Commit 78110a6

Browse files
committed
Adding tests. Fixing up docs a bit.
1 parent e0594af commit 78110a6

2 files changed

Lines changed: 51 additions & 8 deletions

File tree

consul/base.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,13 @@ def members(self, wan=False):
475475
'/v1/agent/members',
476476
params=params)
477477

478-
479478
def maintenance(self, enable, reason=None):
480479
"""
481480
The node maintenance endpoint can place the agent into
482481
"maintenance mode".
483482
484-
*enable* is either True or False. True enables maintenance mode,
485-
False disables maintenance mode.
483+
*enable* is either 'true' or 'false'. True enables maintenance
484+
mode, 'false' disables maintenance mode.
486485
487486
*reason* is an optional string. This is simply to aid human
488487
operators.
@@ -499,7 +498,6 @@ def maintenance(self, enable, reason=None):
499498
'/v1/agent/maintenance',
500499
params=params)
501500

502-
503501
class Service(object):
504502
def __init__(self, agent):
505503
self.agent = agent
@@ -567,11 +565,11 @@ def maintenance(self, service_id, enable, reason=None):
567565
The service maintenance endpoint allows placing a given service
568566
into "maintenance mode".
569567
570-
*service_id* is the id of the service that is to be targeted for
571-
maintenance.
568+
*service_id* is the id of the service that is to be targeted
569+
for maintenance.
572570
573-
*enable* is either True or False. True enables maintenance mode,
574-
False disables maintenance mode.
571+
*enable* is either True or False. 'true' enables maintenance
572+
mode, 'false' disables maintenance mode.
575573
576574
*reason* is an optional string. This is simply to aid human
577575
operators.

tests/test_std.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,51 @@ def test_agent_register_check_no_service_id(self, consul_port):
289289

290290
time.sleep(40/1000.0)
291291

292+
def test_agent_service_maintenance(self, consul_port):
293+
c = consul.Consul(port=consul_port)
294+
295+
c.agent.service.register('foo', ttl='100ms')
296+
297+
time.sleep(40/1000.0)
298+
299+
c.agent.service.maintenance('foo', 'true', "test")
300+
301+
time.sleep(40/1000.0)
302+
303+
checks_pre = c.agent.checks()
304+
assert '_service_maintenance:foo' in checks_pre.keys()
305+
assert 'test' == checks_pre['_service_maintenance:foo']['Notes']
306+
307+
c.agent.service.maintenance('foo', 'false')
308+
309+
time.sleep(40/1000.0)
310+
311+
checks_post = c.agent.checks()
312+
assert '_service_maintenance:foo' not in checks_post.keys()
313+
314+
# Cleanup
315+
c.agent.service.deregister('foo')
316+
317+
time.sleep(40/1000.0)
318+
319+
def test_agent_node_maintenance(self, consul_port):
320+
c = consul.Consul(port=consul_port)
321+
322+
c.agent.maintenance('true', "test")
323+
324+
time.sleep(40/1000.0)
325+
326+
checks_pre = c.agent.checks()
327+
assert '_node_maintenance' in checks_pre.keys()
328+
assert 'test' == checks_pre['_node_maintenance']['Notes']
329+
330+
c.agent.maintenance('false')
331+
332+
time.sleep(40/1000.0)
333+
334+
checks_post = c.agent.checks()
335+
assert '_node_maintenance' not in checks_post.keys()
336+
292337
def test_agent_members(self, consul_port):
293338
c = consul.Consul(port=consul_port)
294339
members = c.agent.members()

0 commit comments

Comments
 (0)