Remove datasource.conf from needing to exist

This patch refactors out the datasource.conf file from the project.

Change-Id: I322974704fc909430b044898fb17afeb01208105
This commit is contained in:
Aaron Rosen 2015-02-11 11:53:03 -08:00
parent dbef982ea7
commit 6fc440828d
7 changed files with 28 additions and 49 deletions

View File

@ -13,7 +13,6 @@
# under the License.
#
import ConfigParser
import os
import os.path
import re
@ -30,7 +29,7 @@ from congress.policy.base import ACTION_POLICY_TYPE
LOG = logging.getLogger(__name__)
def create(rootdir, statedir, config_file, config_override=None):
def create(rootdir, statedir, config_override=None):
"""Get Congress up and running when src is installed in rootdir.
i.e. ROOTDIR=/path/to/congress/congress.
@ -40,15 +39,16 @@ def create(rootdir, statedir, config_file, config_override=None):
dictionaries store values for that section.
"""
LOG.debug("Starting Congress with rootdir=%s, statedir=%s, "
"datasource_config=%s, config_override=%s",
rootdir, statedir, config_file, config_override)
"config_override=%s",
rootdir, statedir, config_override)
# create message bus
cage = d6cage.d6Cage()
cage.system_service_names.add(cage.name)
# read in datasource configurations
cage.config = initialize_config(config_file, config_override)
cage.config = config_override or {}
# path to congress source dir
src_path = os.path.join(rootdir, "congress")
@ -254,36 +254,3 @@ def load_data_service(service_name, config, cage, rootdir):
service_name, module_name)
cage.createservice(name=service_name, moduleName=module_name,
args=config)
def initialize_config(config_file, config_override):
"""Turn config_file into a dictionary of dictionaries.
Also doing insulate rest of code from idiosyncracies of ConfigParser.
"""
# FIXME(arosen): config_override is just being used to aid in testing
# but we don't need to do this.
if config_override is None:
config_override = {}
if config_file is None:
LOG.info("Starting with override configuration: %s", config_override)
return config_override
config = ConfigParser.ConfigParser()
# If we can't process the config file, we should die
config.readfp(open(config_file))
d = {}
# turn the config into a dictionary of dictionaries,
# taking the config_override values into account.
for section in config.sections():
if section in config_override:
override = config_override[section]
else:
override = {}
e = {}
for opt in config.options(section):
e[opt] = config.get(section, opt)
# union e and override, with conflicts decided by override
e = dict(e, **override)
d[section] = e
LOG.info("Starting with configuration: %s", d)
return d

View File

@ -35,8 +35,7 @@ class TestStatusModel(base.SqlTestCase):
# any tests currently testing cage. Once we do we should mock out
# cage so we don't have to create one here.
self.cage = harness.create(helper.root_path(), helper.state_path(),
None, {})
self.cage = harness.create(helper.root_path(), helper.state_path())
self.datasource_mgr = datasource_manager.DataSourceManager
self.datasource_mgr.validate_configured_drivers()
req = {'driver': 'fake_datasource',

View File

@ -31,8 +31,7 @@ class TestDataSourceManager(base.SqlTestCase):
['congress.tests.fake_datasource.FakeDataSource'])
self.datasource_mgr = datasource_manager.DataSourceManager
self.datasource_mgr.validate_configured_drivers()
self.cage = harness.create(helper.root_path(), helper.state_path(),
None, {})
self.cage = harness.create(helper.root_path(), helper.state_path())
def _get_datasource_request(self):
return {'id': 'asdf',

View File

@ -133,7 +133,7 @@ class TestDsePerformance(testbase.SqlTestCase):
super(TestDsePerformance, self).setUp()
self.cage = harness.create(
helper.root_path(), helper.state_path(),
None, config_override={})
config_override={})
self.api = {'policy': self.cage.service_object('api-policy'),
'rule': self.cage.service_object('api-rule'),
'table': self.cage.service_object('api-table'),

View File

@ -53,8 +53,27 @@ class TestCongress(base.SqlTestCase):
neutron_mock2 = mock_factory.CreateMock(
neutronclient.v2_0.client.Client)
config_override = {'neutron2': {'username': 'demo', 'tenant_name':
'demo', 'password': 'password',
'auth_url':
'http://127.0.0.1:5000/v2.0',
'module':
'datasources/neutron_driver.py'},
'nova': {'username': 'demo',
'tenant_name': 'demo',
'password': 'password',
'auth_url': 'http://127.0.0.1:5000/v2.0',
'module': 'datasources/nova_driver.py'},
'neutron': {'username': 'demo',
'tenant_name': 'demo',
'password': 'password',
'auth_url':
'http://127.0.0.1:5000/v2.0',
'module':
'datasources/neutron_driver.py'}}
cage = harness.create(helper.root_path(), helper.state_path(),
helper.datasource_config_path())
config_override)
engine = cage.service_object('engine')
api = {'policy': cage.service_object('api-policy'),
@ -95,7 +114,6 @@ class TestCongress(base.SqlTestCase):
cage.service_object('neutron').neutron = neutron_mock
cage.service_object('neutron2').neutron = neutron_mock2
# delete all policies that aren't builtin, so we have clean slate
names = set(engine.policy_names()) - engine.builtin_policy_names
for name in names:

View File

@ -88,10 +88,6 @@ function configure_congress {
sudo chown $STACK_USER $CONGRESS_CONF_DIR
cp $CONGRESS_DIR/etc/congress.conf.sample $CONGRESS_CONF
# FIXME(arosen) quick work around for now.
touch /etc/congress/datasource.conf
# If needed, move config file from ``$CONGRESS_DIR/etc/congress`` to ``CONGRESS_CONF_DIR``
# Format logging
if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then

View File