fix python tests depending on /etc/compass/seting file bug.

Change-Id: Ia9aff7654e5720942a78acc0334e782e5022b4da
This commit is contained in:
xiaodongwang 2014-01-29 00:24:22 -08:00
parent 2f5c551505
commit f009619f9a
10 changed files with 137 additions and 40 deletions

View File

@ -1,10 +1,18 @@
import simplejson as json
from copy import deepcopy from copy import deepcopy
from celery import current_app from celery import current_app
from mock import Mock from mock import Mock
import simplejson as json
import os
import unittest2 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.api import app
from compass.db import database from compass.db import database
from compass.db.model import Switch 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 Adapter
from compass.db.model import Role from compass.db.model import Role
from compass.db.model import SwitchConfig from compass.db.model import SwitchConfig
from compass.utils import flags
from compass.utils import logsetting
class ApiTestCase(unittest2.TestCase): class ApiTestCase(unittest2.TestCase):
@ -1120,4 +1130,6 @@ class TestAPIWorkFlow(ApiTestCase):
if __name__ == '__main__': if __name__ == '__main__':
flags.init()
logsetting.init()
unittest2.main() unittest2.main()

View File

@ -1,6 +1,17 @@
import os
import unittest2 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.config_management.installers import os_installer
from compass.utils import flags
from compass.utils import logsetting
class DummyInstaller(os_installer.Installer): class DummyInstaller(os_installer.Installer):
@ -40,4 +51,6 @@ class TestInstallerFunctions(unittest2.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
flags.init()
logsetting.init()
unittest2.main() unittest2.main()

View File

@ -1,6 +1,17 @@
import os
import unittest2 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.config_management.installers import package_installer
from compass.utils import flags
from compass.utils import logsetting
class DummyInstaller(package_installer.Installer): class DummyInstaller(package_installer.Installer):
@ -42,4 +53,6 @@ class TestInstallerFunctions(unittest2.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
flags.init()
logsetting.init()
unittest2.main() unittest2.main()

View File

@ -1,6 +1,17 @@
import os
import unittest2 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.config_management.providers import config_provider
from compass.utils import flags
from compass.utils import logsetting
class DummyProvider(config_provider.ConfigProvider): class DummyProvider(config_provider.ConfigProvider):
@ -41,4 +52,6 @@ class TestProviderRegisterFunctions(unittest2.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
flags.init()
logsetting.init()
unittest2.main() unittest2.main()

View File

@ -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'

View File

@ -9,12 +9,17 @@ import xmlrpclib
from mock import Mock 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 from compass.utils import setting_wrapper as setting
reload(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__)) setting.CONFIG_DIR = '%s/data' % os.path.dirname(os.path.abspath(__file__))

View File

@ -1,5 +1,16 @@
import os
import unittest2 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 from compass.utils import util
@ -125,4 +136,6 @@ class TestGetListWithPossibility(unittest2.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
flags.init()
logsetting.init()
unittest2.main() unittest2.main()

View File

@ -5,11 +5,20 @@ import os.path
from compass.utils import setting_wrapper as setting from compass.utils import setting_wrapper as setting
CELERY_CONFIG = os.path.join(setting.CELERYCONFIG_DIR, CELERY_RESULT_BACKEND = 'amqp://'
setting.CELERYCONFIG_FILE)
try: BROKER_URL = 'amqp://guest:guest@localhost:5672//'
execfile(CELERY_CONFIG, globals(), locals())
except Exception as error: CELERY_IMPORTS = ('compass.tasks.tasks',)
logging.exception(error)
raise error
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

View File

@ -3,14 +3,52 @@ import logging
import os import os
if 'COMPASS_SETTING' in os.environ: # default setting
SETTING = os.environ['COMPASS_SETTING'] PROVIDER_NAME = 'mix'
else: GLOBAL_CONFIG_PROVIDER = 'file'
SETTING = '/etc/compass/setting' 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 if ('COMPASS_IGNORE_SETTING' in os.environ and
execfile(SETTING, globals(), locals()) os.environ['COMPASS_IGNORE_SETTING']):
except Exception as error: pass
logging.exception(error) else:
raise error 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

View File

@ -15,7 +15,7 @@ PACKAGE_INSTALLER = 'chef'
CHEF_INSTALLER_URL = 'https://localhost' CHEF_INSTALLER_URL = 'https://localhost'
CHEF_GLOBAL_DATABAG_NAME = 'env_default' CHEF_GLOBAL_DATABAG_NAME = 'env_default'
INSTALLATION_LOGDIR = '/var/log/cobbler/anamon' INSTALLATION_LOGDIR = '/var/log/cobbler/anamon'
DEFAULT_LOGLEVEL = 'debug' DEFAULT_LOGLEVEL = 'info'
DEFAULT_LOGDIR = '/var/log/compass' DEFAULT_LOGDIR = '/var/log/compass'
DEFAULT_LOGINTERVAL = 1 DEFAULT_LOGINTERVAL = 1
DEFAULT_LOGINTERVAL_UNIT = 'h' DEFAULT_LOGINTERVAL_UNIT = 'h'