diff --git a/compass/tests/api/test_api.py b/compass/tests/api/test_api.py index 6a695983..18fe47b6 100644 --- a/compass/tests/api/test_api.py +++ b/compass/tests/api/test_api.py @@ -1,10 +1,18 @@ -import simplejson as json from copy import deepcopy from celery import current_app - from mock import Mock +import simplejson as json +import os import unittest2 + +os.environ['COMPASS_IGNORE_SETTING'] = 'true' + + +from compass.utils import setting_wrapper as setting +reload(setting) + + from compass.api import app from compass.db import database from compass.db.model import Switch @@ -15,6 +23,8 @@ from compass.db.model import HostState from compass.db.model import Adapter from compass.db.model import Role from compass.db.model import SwitchConfig +from compass.utils import flags +from compass.utils import logsetting class ApiTestCase(unittest2.TestCase): @@ -1120,4 +1130,6 @@ class TestAPIWorkFlow(ApiTestCase): if __name__ == '__main__': + flags.init() + logsetting.init() unittest2.main() diff --git a/compass/tests/config_management/installers/test_os_installer.py b/compass/tests/config_management/installers/test_os_installer.py index 5de33dc7..f05cb677 100644 --- a/compass/tests/config_management/installers/test_os_installer.py +++ b/compass/tests/config_management/installers/test_os_installer.py @@ -1,6 +1,17 @@ +import os import unittest2 + +os.environ['COMPASS_IGNORE_SETTING'] = 'true' + + +from compass.utils import setting_wrapper as setting +reload(setting) + + from compass.config_management.installers import os_installer +from compass.utils import flags +from compass.utils import logsetting class DummyInstaller(os_installer.Installer): @@ -40,4 +51,6 @@ class TestInstallerFunctions(unittest2.TestCase): if __name__ == '__main__': + flags.init() + logsetting.init() unittest2.main() diff --git a/compass/tests/config_management/installers/test_package_installer.py b/compass/tests/config_management/installers/test_package_installer.py index 60dd46e6..629de6b6 100644 --- a/compass/tests/config_management/installers/test_package_installer.py +++ b/compass/tests/config_management/installers/test_package_installer.py @@ -1,6 +1,17 @@ +import os import unittest2 + +os.environ['COMPASS_IGNORE_SETTING'] = 'true' + + +from compass.utils import setting_wrapper as setting +reload(setting) + + from compass.config_management.installers import package_installer +from compass.utils import flags +from compass.utils import logsetting class DummyInstaller(package_installer.Installer): @@ -42,4 +53,6 @@ class TestInstallerFunctions(unittest2.TestCase): if __name__ == '__main__': + flags.init() + logsetting.init() unittest2.main() diff --git a/compass/tests/config_management/providers/test_config_provider.py b/compass/tests/config_management/providers/test_config_provider.py index 1152a9cf..50cc476c 100644 --- a/compass/tests/config_management/providers/test_config_provider.py +++ b/compass/tests/config_management/providers/test_config_provider.py @@ -1,6 +1,17 @@ +import os import unittest2 + +os.environ['COMPASS_IGNORE_SETTING'] = 'true' + + +from compass.utils import setting_wrapper as setting +reload(setting) + + from compass.config_management.providers import config_provider +from compass.utils import flags +from compass.utils import logsetting class DummyProvider(config_provider.ConfigProvider): @@ -41,4 +52,6 @@ class TestProviderRegisterFunctions(unittest2.TestCase): if __name__ == '__main__': + flags.init() + logsetting.init() unittest2.main() diff --git a/compass/tests/config_management/utils/data/setting b/compass/tests/config_management/utils/data/setting deleted file mode 100644 index 3ff8bc40..00000000 --- a/compass/tests/config_management/utils/data/setting +++ /dev/null @@ -1,19 +0,0 @@ -PROVIDER_NAME = 'mix' -GLOBAL_CONFIG_PROVIDER = 'file' -CLUSTER_CONFIG_PROVIDER = 'db' -HOST_CONFIG_PROVIDER = 'db' -GLOBAL_CONFIG_FILENAME = 'global_config' -CONFIG_FILE_FORMAT = 'python' -SQLALCHEMY_DATABASE_URI = 'sqlite://' -OS_INSTALLER = 'cobbler' -COBBLER_INSTALLER_URL = 'http://localhost/cobbler_api' -COBBLER_INSTALLER_TOKEN = ['cobbler', 'cobbler'] -PACKAGE_INSTALLER = 'chef' -CHEF_INSTALLER_URL = 'https://localhost/' -CHEF_GLOBAL_DATABAG_NAME = 'env_default' -INSTALLATION_LOGDIR = '/var/log/cobbler/anamon' -DEFAULT_LOGLEVEL = 'info' -DEFAULT_LOGDIR = '' -DEFAULT_LOGINTERVAL = 1 -DEFAULT_LOGINTERVAL_UNIT = 'h' -DEFAULT_LOGFORMAT = '%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s' diff --git a/compass/tests/config_management/utils/test_config_manager.py b/compass/tests/config_management/utils/test_config_manager.py index 23a162b3..05895a84 100644 --- a/compass/tests/config_management/utils/test_config_manager.py +++ b/compass/tests/config_management/utils/test_config_manager.py @@ -9,12 +9,17 @@ import xmlrpclib from mock import Mock -os.environ['COMPASS_SETTING'] = '%s/data/setting' % os.path.dirname(os.path.abspath(__file__)) +os.environ['COMPASS_IGNORE_SETTING'] = 'true' from compass.utils import setting_wrapper as setting reload(setting) + +setting.OS_INSTALLER = 'cobbler' +setting.COBBLER_INSTALLER_URL = 'http://localhost/cobbler_api' +setting.PACKAGE_INSTALLER = 'chef' +setting.CHEF_INSTALLER_URL = 'https://localhost/' setting.CONFIG_DIR = '%s/data' % os.path.dirname(os.path.abspath(__file__)) diff --git a/compass/tests/utils/test_util.py b/compass/tests/utils/test_util.py index 82d5071a..4a190a6a 100644 --- a/compass/tests/utils/test_util.py +++ b/compass/tests/utils/test_util.py @@ -1,5 +1,16 @@ +import os import unittest2 + +os.environ['COMPASS_IGNORE_SETTING'] = 'true' + + +from compass.utils import setting_wrapper as setting +reload(setting) + + +from compass.utils import flags +from compass.utils import logsetting from compass.utils import util @@ -125,4 +136,6 @@ class TestGetListWithPossibility(unittest2.TestCase): if __name__ == '__main__': + flags.init() + logsetting.init() unittest2.main() diff --git a/compass/utils/celeryconfig_wrapper.py b/compass/utils/celeryconfig_wrapper.py index e8417bad..b5b67821 100644 --- a/compass/utils/celeryconfig_wrapper.py +++ b/compass/utils/celeryconfig_wrapper.py @@ -5,11 +5,20 @@ import os.path from compass.utils import setting_wrapper as setting -CELERY_CONFIG = os.path.join(setting.CELERYCONFIG_DIR, - setting.CELERYCONFIG_FILE) +CELERY_RESULT_BACKEND = 'amqp://' -try: - execfile(CELERY_CONFIG, globals(), locals()) -except Exception as error: - logging.exception(error) - raise error +BROKER_URL = 'amqp://guest:guest@localhost:5672//' + +CELERY_IMPORTS = ('compass.tasks.tasks',) + + +if setting.CELERYCONFIG_FILE: + CELERY_CONFIG = os.path.join(setting.CELERYCONFIG_DIR, + setting.CELERYCONFIG_FILE) + + try: + logging.info('load celery config from %s', CELERY_CONFIG) + execfile(CELERY_CONFIG, globals(), locals()) + except Exception as error: + logging.exception(error) + raise error diff --git a/compass/utils/setting_wrapper.py b/compass/utils/setting_wrapper.py index 10b860f4..1f6c9390 100644 --- a/compass/utils/setting_wrapper.py +++ b/compass/utils/setting_wrapper.py @@ -3,14 +3,52 @@ import logging import os -if 'COMPASS_SETTING' in os.environ: - SETTING = os.environ['COMPASS_SETTING'] -else: - SETTING = '/etc/compass/setting' +# default setting +PROVIDER_NAME = 'mix' +GLOBAL_CONFIG_PROVIDER = 'file' +CLUSTER_CONFIG_PROVIDER = 'db' +HOST_CONFIG_PROVIDER = 'db' +CONFIG_DIR = '/etc/compass' +GLOBAL_CONFIG_FILENAME = 'global_config' +CONFIG_FILE_FORMAT = 'python' +DATABASE_TYPE = 'file' +DATABASE_FILE = '' +SQLALCHEMY_DATABASE_URI = 'sqlite://' +OS_INSTALLER = 'cobbler' +COBBLER_INSTALLER_URL = '' +COBBLER_INSTALLER_TOKEN = ['cobbler', 'cobbler'] +PACKAGE_INSTALLER = 'chef' +CHEF_INSTALLER_URL = '' +CHEF_GLOBAL_DATABAG_NAME = 'env_default' +INSTALLATION_LOGDIR = '' +DEFAULT_LOGLEVEL = 'info' +DEFAULT_LOGDIR = '' +DEFAULT_LOGINTERVAL = 1 +DEFAULT_LOGINTERVAL_UNIT = 'h' +DEFAULT_LOGFORMAT = ( + '%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s') +WEB_LOGFILE = '' +CELERY_LOGFILE = '' +CELERYCONFIG_DIR = '' +CELERYCONFIG_FILE = '' +PROGRESS_UPDATE_INTERVAL = 30 +POLLSWITCH_INTERVAL = 60 +SWITCHES = [ +] -try: - print 'load setting from %s' % SETTING - execfile(SETTING, globals(), locals()) -except Exception as error: - logging.exception(error) - raise error + +if ('COMPASS_IGNORE_SETTING' in os.environ and + os.environ['COMPASS_IGNORE_SETTING']): + pass +else: + if 'COMPASS_SETTING' in os.environ: + SETTING = os.environ['COMPASS_SETTING'] + else: + SETTING = '/etc/compass/setting' + + try: + logging.info('load setting from %s', SETTING) + execfile(SETTING, globals(), locals()) + except Exception as error: + logging.exception(error) + raise error diff --git a/conf/setting b/conf/setting index bcbcaedb..1977114c 100644 --- a/conf/setting +++ b/conf/setting @@ -15,7 +15,7 @@ PACKAGE_INSTALLER = 'chef' CHEF_INSTALLER_URL = 'https://localhost' CHEF_GLOBAL_DATABAG_NAME = 'env_default' INSTALLATION_LOGDIR = '/var/log/cobbler/anamon' -DEFAULT_LOGLEVEL = 'debug' +DEFAULT_LOGLEVEL = 'info' DEFAULT_LOGDIR = '/var/log/compass' DEFAULT_LOGINTERVAL = 1 DEFAULT_LOGINTERVAL_UNIT = 'h'