Skip to content

Commit 5ce1f59

Browse files
fix connect stacktrace
1 parent efa823e commit 5ce1f59

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

mongodb_consistent_backup/Common/DB.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pymongo.errors import ConnectionFailure, OperationFailure, ServerSelectionTimeoutError
55
from time import sleep
66

7-
from mongodb_consistent_backup.Errors import DBAuthenticationError, DBConnectionError, DBOperationError, Error
7+
from mongodb_consistent_backup.Errors import DBAuthenticationError, DBConnectionError, DBOperationError, Error, OperationError
88

99

1010
class DB:

mongodb_consistent_backup/Main.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ def __init__(self, prog_name="mongodb-consistent-backup"):
4545
self.timer = Timer(self.manager)
4646
self.timer_name = "mongodb_consistent_backup.%s" % self.__class__.__name__
4747

48-
self.setup_config()
49-
self.setup_logger()
50-
self.setup_signal_handlers()
51-
self.get_lock()
52-
self.init()
53-
self.set_backup_dirs()
54-
self.get_db_conn()
55-
self.setup_state()
48+
try:
49+
self.setup_config()
50+
self.setup_logger()
51+
self.setup_signal_handlers()
52+
self.get_lock()
53+
self.init()
54+
self.set_backup_dirs()
55+
self.get_db_conn()
56+
self.setup_state()
57+
except OperationError, e:
58+
self.exception("Error setting up %s: %s" % (self.program_name, e), e)
5659

5760
def setup_config(self):
5861
try:
@@ -91,11 +94,14 @@ def setup_state(self):
9194

9295
def get_db_conn(self):
9396
self.uri = MongoUri(self.config.host, self.config.port)
94-
self.db = DB(self.uri, self.config, True, 'secondaryPreferred')
97+
try:
98+
self.db = DB(self.uri, self.config, True, 'secondaryPreferred')
99+
except OperationError, e:
100+
return self.exception("Cannot connect to seed host(s): %s" % self.uri, e)
95101
self.is_sharded = self.db.is_mongos()
96102
if not self.is_sharded:
97103
self.is_sharded = self.db.is_configsvr()
98-
if not self.is_sharded and not self.db.is_replset():
104+
if not self.is_sharded and not self.db.is_replset() and not self.db.is_configsvr():
99105
raise OperationError("Host %s is not part of a replset and is not a sharding config/mongos server!" % self.uri.get())
100106

101107
def get_lock(self):

0 commit comments

Comments
 (0)