Config params substitution handled in managers
Loading from external configs is required for auto deployment fuel-stats packages by the DevOps team. For collector COLLECTOR_SETTINGS environment param is used. Value of COLLECTOR_SETTINGS should be path to external config. Config is regular python file. For collector standard Flask external config file feature is used. From collector config removed unused HOST and PORT params For migrator parameter '--config' is added to manage_migration.py. External config is yaml config file. Blueprint: send-anon-usage Change-Id: I3667d22d55b6edbbaa8f81e14dcd3d199e7a87a6
This commit is contained in:
parent
9bdb7459a5
commit
6201c2bf17
|
@ -18,8 +18,6 @@ import os
|
|||
|
||||
class Production(object):
|
||||
DEBUG = False
|
||||
PORT = 5000
|
||||
HOST = 'localhost'
|
||||
VALIDATE_RESPONSE = False
|
||||
LOG_FILE = '/var/log/fuel-stats/collector.log'
|
||||
LOG_LEVEL = logging.ERROR
|
||||
|
@ -31,7 +29,6 @@ class Production(object):
|
|||
|
||||
class Testing(Production):
|
||||
DEBUG = True
|
||||
HOST = '0.0.0.0'
|
||||
VALIDATE_RESPONSE = True
|
||||
LOG_FILE = os.path.realpath(os.path.join(
|
||||
os.path.dirname(__file__), '..', 'test', 'logs', 'collector.log'))
|
||||
|
|
|
@ -20,7 +20,9 @@ from flask_script import Manager
|
|||
|
||||
from collector.api import log
|
||||
from collector.api.app import app
|
||||
from collector.api import app as app_module
|
||||
from collector.api.db.model import *
|
||||
import flask_sqlalchemy
|
||||
|
||||
|
||||
def configure_app(mode=None):
|
||||
|
@ -29,6 +31,8 @@ def configure_app(mode=None):
|
|||
'prod': 'collector.api.config.Production'
|
||||
}
|
||||
app.config.from_object(mode_map.get(mode))
|
||||
app.config.from_envvar('COLLECTOR_SETTINGS', silent=False)
|
||||
setattr(app_module, 'db', flask_sqlalchemy.SQLAlchemy(app))
|
||||
log.init_logger()
|
||||
return app
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ Flask-JsonSchema==0.1.1
|
|||
Flask-Migrate==1.2.0
|
||||
Flask-SQLAlchemy==2.0
|
||||
Flask-Script==2.0.5
|
||||
PyYAML==3.11
|
||||
alembic==0.6.7
|
||||
psycopg2==2.5.4
|
||||
six>=1.8.0
|
||||
six>=1.8.0
|
|
@ -15,6 +15,8 @@
|
|||
# under the License.
|
||||
|
||||
import argparse
|
||||
import six
|
||||
import yaml
|
||||
|
||||
from migration.test.test_env import configure_test_env
|
||||
|
||||
|
@ -24,8 +26,20 @@ def handle_mode(params):
|
|||
configure_test_env()
|
||||
|
||||
|
||||
def handle_external_config(params):
|
||||
if params.config:
|
||||
with open(params.config) as f:
|
||||
from migration import config
|
||||
|
||||
content = yaml.load(f)
|
||||
if isinstance(content, dict):
|
||||
for k, v in six.iteritems(content):
|
||||
setattr(config, k, v)
|
||||
|
||||
|
||||
def execute(params):
|
||||
handle_mode(params)
|
||||
handle_external_config(params)
|
||||
# importing Migrator only after test or prod environment is configured
|
||||
from migration.migrator import Migrator
|
||||
migrator = Migrator()
|
||||
|
@ -56,6 +70,10 @@ if __name__ == '__main__':
|
|||
choices=('test', 'prod'),
|
||||
default='prod'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-c', '--config',
|
||||
help="Path to additional yaml config file"
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(
|
||||
dest='action',
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
elasticsearch==1.2.0
|
||||
psycopg2==2.5.4
|
||||
six>=1.8.0
|
||||
PyYAML==3.11
|
||||
SQLAlchemy==0.9.8
|
||||
|
|
Loading…
Reference in New Issue