diff --git a/congress/common/config.py b/congress/common/config.py index 4ac9d7537..010054623 100644 --- a/congress/common/config.py +++ b/congress/common/config.py @@ -40,6 +40,8 @@ core_opts = [ help="The path to the latest policy dump"), cfg.StrOpt('datasource_file', default=None, help="The file containing datasource configuration"), + cfg.StrOpt('root_path', default=None, + help="The absolute path to the congress repo"), cfg.IntOpt('api_workers', default=1, help='The number of worker processes to serve the congress ' 'API application.'), diff --git a/congress/harness.py b/congress/harness.py index 3bd9d4352..cdd379951 100644 --- a/congress/harness.py +++ b/congress/harness.py @@ -48,15 +48,18 @@ def create(rootdir, statedir, config_file, config_override=None): # read in datasource configurations cage.config = initialize_config(config_file, config_override) + # path to congress source dir + src_path = os.path.join(rootdir, "congress") + # add policy engine - engine_path = os.path.join(rootdir, "policy/dsepolicy.py") + engine_path = os.path.join(src_path, "policy/dsepolicy.py") LOG.info("main::start() engine_path: " + str(engine_path)) cage.loadModule("PolicyEngine", engine_path) cage.createservice( name="engine", moduleName="PolicyEngine", description="Policy Engine (DseRuntime instance)", - args={'d6cage': cage, 'rootdir': rootdir}) + args={'d6cage': cage, 'rootdir': src_path}) engine = cage.service_object('engine') if statedir is not None: engine.load_dir(statedir) @@ -66,7 +69,7 @@ def create(rootdir, statedir, config_file, config_override=None): # add policy api # TODO(thinrichs): change to real API path. - api_path = os.path.join(rootdir, "api/policy_model.py") + api_path = os.path.join(src_path, "api/policy_model.py") LOG.info("main::start() api_path: " + str(api_path)) cage.loadModule("API-policy", api_path) cage.createservice( @@ -77,7 +80,7 @@ def create(rootdir, statedir, config_file, config_override=None): cage.system_service_names.add('api-policy') # add rule api - api_path = os.path.join(rootdir, "api/rule_model.py") + api_path = os.path.join(src_path, "api/rule_model.py") LOG.info("main::start() api_path: " + str(api_path)) cage.loadModule("API-rule", api_path) cage.createservice( @@ -88,7 +91,7 @@ def create(rootdir, statedir, config_file, config_override=None): cage.system_service_names.add('api-rule') # add table api - api_path = os.path.join(rootdir, "api/table_model.py") + api_path = os.path.join(src_path, "api/table_model.py") LOG.info("main::start() api_path: " + str(api_path)) cage.loadModule("API-table", api_path) cage.createservice( @@ -99,7 +102,7 @@ def create(rootdir, statedir, config_file, config_override=None): cage.system_service_names.add('api-table') # add row api - api_path = os.path.join(rootdir, "api/row_model.py") + api_path = os.path.join(src_path, "api/row_model.py") LOG.info("main::start() api_path: " + str(api_path)) cage.loadModule("API-row", api_path) cage.createservice( @@ -110,7 +113,7 @@ def create(rootdir, statedir, config_file, config_override=None): cage.system_service_names.add('api-row') # add datasource api - api_path = os.path.join(rootdir, "api/datasource_model.py") + api_path = os.path.join(src_path, "api/datasource_model.py") LOG.info("main::start() api_path: " + str(api_path)) cage.loadModule("API-datasource", api_path) cage.createservice( @@ -133,7 +136,7 @@ def create(rootdir, statedir, config_file, config_override=None): if cage.config: for name in cage.config: if 'module' in cage.config[name]: - load_data_service(name, cage.config[name], cage, rootdir) + load_data_service(name, cage.config[name], cage, src_path) return cage diff --git a/congress/service.py b/congress/service.py index a7b341c06..96e0f92d9 100644 --- a/congress/service.py +++ b/congress/service.py @@ -42,18 +42,18 @@ def fail_gracefully(f): @fail_gracefully def congress_app_factory(global_conf, **local_conf): - fpath = os.path.dirname(__file__) # drop filename - src_path = os.path.dirname(fpath) # drop to congress src dir + root_path = cfg.CONF.root_path + if root_path is None: + root_path = os.path.dirname(__file__) # drop filename + root_path = os.path.dirname(root_path) # drop to congress src dir policy_path = cfg.CONF.policy_path if policy_path is None: - policy_path = os.path.dirname(src_path) - policy_path = os.path.join(policy_path, 'etc', 'snapshot') + policy_path = os.path.join(root_path, 'etc', 'snapshot') data_path = cfg.CONF.datasource_file if data_path is None: - data_path = os.path.dirname(src_path) - data_path = os.path.join(data_path, 'etc', 'datasources.conf') + data_path = os.path.join(root_path, 'etc', 'datasources.conf') - cage = harness.create(src_path, policy_path, data_path) + cage = harness.create(root_path, policy_path, data_path) api_resource_mgr = application.ResourceManager() congress_server.initialize_resources(api_resource_mgr, cage) diff --git a/congress/tests/helper.py b/congress/tests/helper.py index 35f19c4c2..e183c25eb 100644 --- a/congress/tests/helper.py +++ b/congress/tests/helper.py @@ -25,6 +25,15 @@ from congress.policy import runtime LOG = logging.getLogger(__name__) +def root_path(): + """Return path to root of source code.""" + x = os.path.realpath(__file__) + x, y = os.path.split(x) # drop "helper.py" + x, y = os.path.split(x) # drop "tests" + x, y = os.path.split(x) # drop "congress" + return x + + def source_path(): """Return path to root of source code.""" x = os.path.realpath(__file__) diff --git a/congress/tests/test_congress.py b/congress/tests/test_congress.py index 09af69714..61afb2487 100644 --- a/congress/tests/test_congress.py +++ b/congress/tests/test_congress.py @@ -107,7 +107,7 @@ class TestCongress(base.TestCase): override['neutron2'] = {'client': neutron_mock2, 'poll_time': 0} override['nova'] = {'poll_time': 0} - cage = harness.create(helper.source_path(), self.state_path(), + cage = harness.create(helper.root_path(), self.state_path(), helper.datasource_config_path(), override) engine = cage.service_object('engine') api = {'policy': cage.service_object('api-policy'), diff --git a/etc/datasources.conf.sample b/etc/datasources.conf.sample index 763dc8cac..4d2cbebbd 100644 --- a/etc/datasources.conf.sample +++ b/etc/datasources.conf.sample @@ -6,3 +6,11 @@ password: password auth_url: http://127.0.0.1:5000/v2.0 tenant_name: demo +[nova] +module: datasources/nova_driver.py +username: demo +password: password +auth_url: http://127.0.0.1:5000/v2.0 +tenant_name: demo + +