Island: Add error messages to Mongo exceptions

This commit is contained in:
Mike Salvatore 2021-08-03 09:40:51 -04:00
parent 8dc2905c71
commit 109a992201
2 changed files with 7 additions and 10 deletions

View File

@ -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))

View File

@ -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)))