diff options
author | drebs <drebs@riseup.net> | 2017-11-21 19:34:34 -0200 |
---|---|---|
committer | drebs <drebs@riseup.net> | 2017-11-22 08:23:59 -0200 |
commit | 787f5360b801eecbebb4d28128c343832b29df57 (patch) | |
tree | 2623382dbcd704839986ae8b7050d52fdcbb79c3 /src/leap/soledad/common | |
parent | 5956b8e095966f91ea8d83956d0d7d46a447ddba (diff) |
[bug] fix logging while checking CouchDB schema versions on server startup
Diffstat (limited to 'src/leap/soledad/common')
-rw-r--r-- | src/leap/soledad/common/couch/check.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/leap/soledad/common/couch/check.py b/src/leap/soledad/common/couch/check.py index f55dd6f6..93fc1d66 100644 --- a/src/leap/soledad/common/couch/check.py +++ b/src/leap/soledad/common/couch/check.py @@ -18,7 +18,6 @@ Database schema version verification """ -import os import treq from six.moves.urllib.parse import urljoin @@ -84,13 +83,6 @@ def _check_db_schema_version(url, db, auth, agent=None): raise WrongCouchSchemaVersionError(db) -def _stop(failure, reactor): - logger.error("Failure while checking schema versions: %r - %s" - % (failure, failure.message)) - reactor.addSystemEventTrigger('after', 'shutdown', os._exit, 1) - reactor.stop() - - @defer.inlineCallbacks def check_schema_versions(couch_url, agent=None, reactor=reactor): """ @@ -107,17 +99,26 @@ def check_schema_versions(couch_url, agent=None, reactor=reactor): url = urlsplit(couch_url) auth = (url.username, url.password) if url.username else None url = "%s://%s:%d" % (url.scheme, url.hostname, url.port) - res = yield treq.get(urljoin(url, '_all_dbs'), auth=auth, agent=agent) - dbs = yield res.json() + try: + res = yield treq.get(urljoin(url, '_all_dbs'), auth=auth, agent=agent) + dbs = yield res.json() + except Exception as e: + logger.error('Error trying to get list of dbs from %s: %r' + % (url, e)) + raise e deferreds = [] semaphore = defer.DeferredSemaphore(20) - logger.info('Starting schema versions check...') + logger.info('Starting CouchDB schema versions check...') for db in dbs: if not db.startswith('user-'): continue d = semaphore.run(_check_db_schema_version, url, db, auth, agent=agent) - d.addErrback(_stop, reactor=reactor) deferreds.append(d) d = defer.gatherResults(deferreds, consumeErrors=True) - d.addCallback(lambda _: logger.info('Finished schema versions check.')) - yield d + try: + yield d + logger.info('Finished CouchDB schema versions check.') + except Exception as e: + msg = 'Error checking CouchDB schema versions: %r' % e + logger.error(msg) + raise Exception(msg) |