Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Local configuration override in ionlocal.config. Unit tests get broke…
Browse files Browse the repository at this point in the history
…r host from config
  • Loading branch information
Michael Meisinger committed May 21, 2010
1 parent 8f71941 commit 342829f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*.pid
_trial*
docs
res/config/ionlocal.config
7 changes: 6 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Or in the CC shell:
send(1, {'op':'hello','content':'Hello you there!'})

from ion.play.hello_service import HelloServiceClient
hc = HelloServiceClient()
hc = HelloServiceClient()
hc.hello()


Expand Down Expand Up @@ -120,6 +120,11 @@ again (see above). Please review the branch logs for any hints.
Change log:
===========

2010-05-20:
- The system now looks for a local config file ionlocal.config and if exists,
overrides entries in ion.config.
- Test cases use the config file to determine the broker host to use. If local
config override exists, a different broker (e.g. localhast) can be given.
2010-05-16:
- Removed support for BaseProcess.send_message and reply_message. Always use
send, reply and rpc_send now.
Expand Down
6 changes: 6 additions & 0 deletions ion/core/ionconst.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
@brief definitions of ION packages wide constants
"""

# Name of central logginf configuration file
LOGCONF_FILENAME = 'res/logging/ionlogging.conf'

# Name of central ION configuration file (not to be changed)
ION_CONF_FILENAME = 'res/config/ion.config'

# Name of local ION config override file (can be changed locally)
ION_LOCAL_CONF_FILENAME = 'res/config/ionlocal.config'

# @todo use magnet version system
VERSION = "ion 0.2.1"

# Minimum version of Magnet required
MIN_MAGNET = "0.3.4"
5 changes: 4 additions & 1 deletion ion/core/ioninit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# Load configuration properties for any module to access
ion_config = Config(ic.ION_CONF_FILENAME)

# Update configuration with local override config
ion_config.update_from_file(ic.ION_LOCAL_CONF_FILENAME)

# Arguments given to the container (i.e. the python process executing this code)
cont_args = {}

Expand Down Expand Up @@ -48,4 +51,4 @@ def check_magnet_version():
if mv[0]<minmv[0] or mv[1]<minmv[1] or mv[2]<minmv[2]:
logging.error("*********** ATTENTION! Magnet %s required. Is %s ***********" % (ic.MIN_MAGNET, magnet.__version__))

check_magnet_version()
check_magnet_version()
15 changes: 8 additions & 7 deletions ion/test/iontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

from twisted.trial import unittest
from twisted.internet import defer

from magnet import container
from magnet.container import Id
from ion.data.store import Store

from ion.core import base_process, bootstrap
from ion.core import base_process, bootstrap, ioninit
from ion.core import ioninit
from ion.data.store import Store
import ion.util.procutils as pu

CONF = ioninit.config(__name__)

class IonTestCase(unittest.TestCase):
"""
Extension of python unittest.TestCase and trial unittest.TestCase for the
Expand All @@ -37,9 +38,9 @@ def _start_container(self):
@note Hardwired to connect to amoeba for broker.
"""
mopt = {}
mopt['broker_host'] = 'amoeba.ucsd.edu'
mopt['broker_port'] = 5672
mopt['broker_vhost'] = '/'
mopt['broker_host'] = CONF['broker_host']
mopt['broker_port'] = CONF['broker_port']
mopt['broker_vhost'] = CONF['broker_vhost']
mopt['boot_script'] = None
mopt['script'] = None

Expand Down Expand Up @@ -72,7 +73,7 @@ def _declare_messaging(self, messaging):

def _spawn_processes(self, procs):
return bootstrap.spawn_processes(procs)

def _get_procid(self, name):
"""
@param name process instance label given when spawning
Expand Down
30 changes: 30 additions & 0 deletions ion/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
@brief supports work with config files
"""

import logging
import os.path

class Config(object):
"""
Helper class managing config files
Expand Down Expand Up @@ -48,3 +51,30 @@ def getValue2(self, key1, key2, default=None):
def getValue3(self, key1, key2, key3, default=None):
value = self.getValue2(key1, key2, {})
return self._getValue(value, key3, default)

def update_from_file(self, filename):
if os.path.isfile(filename):
logging.info("Updating config from local file: "+filename)
# Load config override from filename
filecontent = open(filename,).read()
updates = eval(filecontent)
self.update(updates)

def update(self, updates):
"""
Recursively updates configuration dict with values in given dict.
"""
self._update_dict(self.obj, updates)

def _update_dict(self, src, upd):
"""
Recursively updates a dict with values in another dict.
"""
assert type(src) is dict and type(upd) is dict
for ukey,uval in upd.iteritems():
if type(uval) is dict:
if not ukey in src:
src[ukey] = {}
self._update_dict(src[ukey], uval)
else:
src[ukey] = uval
8 changes: 8 additions & 0 deletions res/config/_ionlocal.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Override configuration file for "ion.config". Any entry in here replaces
# or adds configuration in ion.config.
# For a local configuration, copy to "ionlocal.config" and modify settings here.
{
'#REMOVEME#ion.test.iontest':{
'broker_host' : 'localhost',
},
}
12 changes: 8 additions & 4 deletions res/config/ion.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Central configuration file for ION services and modules
# Entried are key'ed by the __name__ of their module,
# or startup for boot scripts
# Entries are key'ed by the __name__ of their module,
# or startup for boot scripts.
# Do not modify this file locally! Set overrides in ionlocal.config
{
'ion.core.bootstrap':{
'ccagent_cfg' : 'res/config/ionccagent.cfg',
Expand Down Expand Up @@ -34,6 +35,11 @@
'backend_class':'ion.data.store.Store',
},

'ion.test.iontest':{
'broker_host' : 'amoeba.ucsd.edu',
'broker_port' : 5672,
'broker_vhost' : '/',
},

'startup.bootstrap1':{
'coreservices_cfg':'res/config/ioncoreservices.cfg',
Expand All @@ -45,6 +51,4 @@
'services_cfg' : 'res/config/iondx_services.cfg',
'messaging_cfg': 'res/config/ionmessaging.cfg'
},


}

0 comments on commit 342829f

Please sign in to comment.