fix bug #244 by printing an error when some non-unique directory names are

used in the custom_services_dir setting
(Boeing r1841)
This commit is contained in:
ahrenholz 2014-04-30 21:27:41 +00:00
parent 422ecab341
commit 1ab6be9625
2 changed files with 13 additions and 3 deletions

View file

@ -47,6 +47,9 @@ class CoreServices(ConfigurableManager):
_name = "services"
_type = coreapi.CORE_TLV_REG_UTILITY
_invalid_custom_names = ('core', 'addons', 'api', 'bsd', 'emane', 'misc',
'netns', 'phys', 'services', 'xen')
def __init__(self, session):
ConfigurableManager.__init__(self, session)
# dict of default services tuples, key is node type
@ -72,10 +75,11 @@ class CoreServices(ConfigurableManager):
return
try:
parentdir, childdir = os.path.split(path)
if childdir == "services":
if childdir in self._invalid_custom_names:
raise ValueError, "use a unique custom services dir name, " \
"not 'services'"
sys.path.append(parentdir)
"not '%s'" % childdir
if not parentdir in sys.path:
sys.path.append(parentdir)
exec("from %s import *" % childdir)
except Exception, e:
self.session.warn("error importing custom services from " \

View file

@ -1640,6 +1640,12 @@ defines the service; then the `custom_services_dir` entry must be set
in the :file:`/etc/core/core.conf` configuration file. A sample is provided in
the :file:`myservices/` directory.
.. NOTE::
The directory name used in `custom_services_dir` should be unique and
should not correspond to
any existing Python module name. For example, don't use the name `subprocess`
or `services`.
If you have created a new service type that may be useful to others, please
consider contributing it to the CORE project.