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

@@ -235,6 +235,19 @@ class ApiV1ConfigView(APIView):
# FIX: Log
return Response({"error": "Invalid License"}, status=status.HTTP_400_BAD_REQUEST)
# Sanity check: If this license includes system tracking, make
# sure that we have a valid MongoDB to point to, and complain if
# we do not.
if (license_data['features']['system_tracking'] and
settings.MONGO_HOST == NotImplemented):
return Response({
'error': 'This license supports system tracking, which '
'requires MongoDB to be installed. Since you are '
'running in an HA environment, you will need to '
'provide a MongoDB instance. Please re-run the '
'installer prior to installing this license.'
}, status=status.HTTP_400_BAD_REQUEST)
# If the license is valid, write it to disk.
if license_data['valid_key']:
fh = open(TASK_FILE, "w")

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

View File

@@ -5,8 +5,6 @@ import os
import sys
from datetime import timedelta
MONGO_DB = 'system_tracking'
# Update this module's local settings from the global settings module.
from django.conf import global_settings
this_module = sys.modules[__name__]

View File

@@ -13,6 +13,11 @@ from split_settings.tools import optional, include
# Load default settings.
from defaults import * # NOQA
MONGO_HOST = '127.0.0.1'
MONGO_PORT = 27017
MONGO_USERNAME = None
MONGO_PASSWORD = None
MONGO_DB = 'system_tracking_dev'
# Disable capturing all SQL queries when running celeryd in development.