346
346
def do_connect():
347
"""Connect and authenticate.
347
"""Connect and authenticate."""
349
348
client_creator = ClientCreator(reactor, MemCacheProtocol)
350
349
client = yield client_creator.connectTCP(host=host, port=port,
357
356
sequential_check(subchecks))
359
def make_mongodb_check(host, port=27017, username=None, password=None,
360
database='test', timeout=10, **kwargs):
361
"""Return a check for MongoDB connectivity."""
365
subchecks.append(make_tcp_check(host, port, timeout=timeout))
371
"""Try to establish a mongodb connection."""
372
conn = txmongo.MongoConnection(host, port)
374
conn.uri['options']['connectTimeoutMS'] = int(timeout*1000)
376
conn.uri['username'] = username
378
conn.uri['password'] = password
380
# We don't start our timeout callback until now, otherwise we might
381
# elapse part of our timeout period during the earlier TCP check
382
reactor.callLater(timeout, timeout_handler)
385
names = yield mongo[database].collection_names()
387
def timeout_handler():
388
"""Manual timeout handler as txmongo timeout args above don't work in
390
if 'deferred' in do_connect.func_dict:
391
err = ValueError("timeout connecting to mongodb")
392
do_connect.func_dict['deferred'].errback(err)
394
connect_info = "connect with auth" if any((username, password)) else "connect"
395
subchecks.append(make_check(connect_info, do_connect))
396
return add_check_prefix('mongodb:{}:{}'.format(host, port),
397
sequential_check(subchecks))
362
402
'fn': make_tcp_check,
398
438
'fn': make_memcache_check,
399
439
'args': ['host', 'port'],
442
'fn': make_mongodb_check,
446
'fn': make_mongodb_check,