forked from p15670423/monkey
Island: Add error messages to Mongo exceptions
This commit is contained in:
parent
8dc2905c71
commit
109a992201
|
@ -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.database_initializer import init_collections # noqa: E402
|
||||||
from monkey_island.cc.setup.mongo.mongo_setup import ( # noqa: E402
|
from monkey_island.cc.setup.mongo.mongo_setup import ( # noqa: E402
|
||||||
MONGO_URL,
|
MONGO_URL,
|
||||||
TIMEOUT,
|
|
||||||
MongoDBTimeOutException,
|
MongoDBTimeOutException,
|
||||||
MongoDBVersionException,
|
MongoDBVersionException,
|
||||||
connect_to_mongodb,
|
connect_to_mongodb,
|
||||||
|
@ -63,15 +62,16 @@ def run_monkey_island():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connect_to_mongodb()
|
connect_to_mongodb()
|
||||||
except MongoDBTimeOutException:
|
except MongoDBTimeOutException as ex:
|
||||||
if config_options.start_mongodb and not mongo_db_process.is_running():
|
if config_options.start_mongodb and not mongo_db_process.is_running():
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Failed to start MongoDB process. Check log at {mongo_db_process.log_file}."
|
f"Failed to start MongoDB process. Check log at {mongo_db_process.log_file}."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.error(f"Failed to connect to MongoDB after {TIMEOUT} seconds. ")
|
logger.error(ex)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except MongoDBVersionException:
|
except MongoDBVersionException as ex:
|
||||||
|
logger.error(ex)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
_configure_gevent_exception_handling(Path(config_options.data_dir))
|
_configure_gevent_exception_handling(Path(config_options.data_dir))
|
||||||
|
|
|
@ -56,7 +56,7 @@ def _wait_for_mongo_db_server(mongo_url):
|
||||||
logger.info("Waiting for MongoDB server on {0}".format(mongo_url))
|
logger.info("Waiting for MongoDB server on {0}".format(mongo_url))
|
||||||
|
|
||||||
if (time.time() - start_time) > TIMEOUT:
|
if (time.time() - start_time) > TIMEOUT:
|
||||||
raise MongoDBTimeOutException
|
raise MongoDBTimeOutException(f"Failed to connect to MongoDB after {TIMEOUT} seconds.")
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -70,12 +70,9 @@ def _assert_mongo_db_version(mongo_url):
|
||||||
required_version = tuple(MINIMUM_MONGO_DB_VERSION_REQUIRED.split("."))
|
required_version = tuple(MINIMUM_MONGO_DB_VERSION_REQUIRED.split("."))
|
||||||
server_version = get_db_version(mongo_url)
|
server_version = get_db_version(mongo_url)
|
||||||
if server_version < required_version:
|
if server_version < required_version:
|
||||||
logger.error(
|
raise MongoDBVersionException(
|
||||||
"Mongo DB version too old. {0} is required, but got {1}".format(
|
f"Mongo DB version too old. {required_version} is required, but got {server_version}."
|
||||||
str(required_version), str(server_version)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
raise MongoDBVersionException
|
|
||||||
else:
|
else:
|
||||||
logger.info("Mongo DB version OK. Got {0}".format(str(server_version)))
|
logger.info("Mongo DB version OK. Got {0}".format(str(server_version)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue