diff --git a/awx/api/views.py b/awx/api/views.py index c5ec4e6c74..5351af1659 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -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") diff --git a/awx/fact/__init__.py b/awx/fact/__init__.py index 5e6a23a90d..6910d7229f 100644 --- a/awx/fact/__init__.py +++ b/awx/fact/__init__.py @@ -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)) diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 52a86ed95c..88bd0fe7b4 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -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__] diff --git a/awx/settings/development.py b/awx/settings/development.py index 71ddb9c078..9375d68182 100644 --- a/awx/settings/development.py +++ b/awx/settings/development.py @@ -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.