diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index 304ec9788..ef44ca6fa 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -35,7 +35,6 @@ from monkey_island.cc.setup.island_config_options import IslandConfigOptions # from monkey_island.cc.setup.mongo.database_initializer import init_collections # noqa: E402 from monkey_island.cc.setup.mongo.mongo_setup import ( # noqa: E402 MONGO_URL, - TIMEOUT, MongoDBTimeOutException, MongoDBVersionException, connect_to_mongodb, @@ -63,15 +62,16 @@ def run_monkey_island(): try: connect_to_mongodb() - except MongoDBTimeOutException: + except MongoDBTimeOutException as ex: if config_options.start_mongodb and not mongo_db_process.is_running(): logger.error( f"Failed to start MongoDB process. Check log at {mongo_db_process.log_file}." ) else: - logger.error(f"Failed to connect to MongoDB after {TIMEOUT} seconds. ") + logger.error(ex) sys.exit(1) - except MongoDBVersionException: + except MongoDBVersionException as ex: + logger.error(ex) sys.exit(1) _configure_gevent_exception_handling(Path(config_options.data_dir)) diff --git a/monkey/monkey_island/cc/setup/mongo/mongo_setup.py b/monkey/monkey_island/cc/setup/mongo/mongo_setup.py index df0470f3b..6ebd6e89b 100644 --- a/monkey/monkey_island/cc/setup/mongo/mongo_setup.py +++ b/monkey/monkey_island/cc/setup/mongo/mongo_setup.py @@ -56,7 +56,7 @@ def _wait_for_mongo_db_server(mongo_url): logger.info("Waiting for MongoDB server on {0}".format(mongo_url)) if (time.time() - start_time) > TIMEOUT: - raise MongoDBTimeOutException + raise MongoDBTimeOutException(f"Failed to connect to MongoDB after {TIMEOUT} seconds.") time.sleep(1) @@ -70,12 +70,9 @@ def _assert_mongo_db_version(mongo_url): required_version = tuple(MINIMUM_MONGO_DB_VERSION_REQUIRED.split(".")) server_version = get_db_version(mongo_url) if server_version < required_version: - logger.error( - "Mongo DB version too old. {0} is required, but got {1}".format( - str(required_version), str(server_version) - ) + raise MongoDBVersionException( + f"Mongo DB version too old. {required_version} is required, but got {server_version}." ) - raise MongoDBVersionException else: logger.info("Mongo DB version OK. Got {0}".format(str(server_version)))