From 02991c70a9878f8ba9a10da13a18532affaa1cb5 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Wed, 14 Dec 2016 13:23:50 -0800 Subject: [PATCH] Allow Lemur "start" to use the global config. (#596) * allowing our runserver to use the config specified by -c * Maintaining config for gunicorn --- lemur/common/managers.py | 3 +++ lemur/factory.py | 4 ++++ lemur/manage.py | 8 +++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lemur/common/managers.py b/lemur/common/managers.py index 6205a019..234432c0 100644 --- a/lemur/common/managers.py +++ b/lemur/common/managers.py @@ -60,11 +60,14 @@ class InstanceManager(object): results.append(cls()) else: results.append(cls) + except InvalidConfiguration as e: current_app.logger.warning("Plugin '{0}' may not work correctly. {1}".format(class_name, e)) + except Exception as e: current_app.logger.exception("Unable to import {0}. Reason: {1}".format(cls_path, e)) continue + self.cache = results return results diff --git a/lemur/factory.py b/lemur/factory.py index ca25b339..3edce17a 100644 --- a/lemur/factory.py +++ b/lemur/factory.py @@ -92,6 +92,7 @@ def configure_app(app, config=None): """ # respect the config first if config and config != 'None': + app.config['CONFIG_PATH'] = config app.config.from_object(from_file(config)) else: try: @@ -103,6 +104,9 @@ def configure_app(app, config=None): else: app.config.from_object(from_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default.conf.py'))) + # we don't use this + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + def configure_extensions(app): """ diff --git a/lemur/manage.py b/lemur/manage.py index 875abd68..ee2f3c11 100755 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -119,7 +119,6 @@ LOG_FILE = "lemur.log" # modify this if you are not using a local database SQLALCHEMY_DATABASE_URI = 'postgresql://lemur:lemur@localhost:5432/lemur' - # AWS #LEMUR_INSTANCE_PROFILE = 'Lemur' @@ -372,11 +371,10 @@ class LemurServer(Command): app = WSGIApplication() - # run startup tasks on an app like object - pre_app = create_app(kwargs.get('config')) - validate_conf(pre_app, REQUIRED_VARIABLES) + # run startup tasks on a app like object + validate_conf(current_app, REQUIRED_VARIABLES) - app.app_uri = 'lemur:create_app(config="{0}")'.format(kwargs.get('config')) + app.app_uri = 'lemur:create_app(config="{0}")'.format(current_app.config.get('CONFIG_PATH')) return app.run()