Do not accept enterprise licenses in some cases.

This commit makes it so that enterprise licenses are rejected in HA
environments if there is no active MongoDB server.

Additionally, it suppresses trying to connect to MongoDB in cases where
it is not present or meaningful.
This commit is contained in:
Luke Sneeringer
2015-06-04 14:42:09 -05:00
parent b41546a20e
commit b0b5e3a726
4 changed files with 31 additions and 3 deletions

View File

@@ -14,7 +14,19 @@ logger = logging.getLogger('awx.fact')
# Connect to Mongo
try:
connect(settings.MONGO_DB, tz_aware=settings.USE_TZ)
# Sanity check: If we have intentionally invalid settings, then we
# know we cannot connect.
if settings.MONGO_HOST == NotImplemented:
raise ConnectionError
# Attempt to connect to the MongoDB database.
connect(settings.MONGO_DB,
host=settings.MONGO_HOST,
port=int(settings.MONGO_PORT),
username=settings.MONGO_USERNAME,
password=settings.MONGO_PASSWORD,
tz_aware=settings.USE_TZ,
)
register_key_transform(get_db())
except ConnectionError:
logger.warn('Failed to establish connect to MongoDB "%s"' % (settings.MONGO_DB))