Browse Source

[trac875] Loading of spec file

Michal 'vorner' Vaner 14 years ago
parent
commit
f80cdaf115

+ 3 - 0
src/bin/cfgmgr/plugins/Makefile.am

@@ -1,2 +1,5 @@
 SUBDIRS = tests
 EXTRA_DIST = README
+
+# TODO: We need to distribute the .py files and .spec files. We also need to
+# install them. How to do that correctly?

+ 1 - 1
src/bin/cfgmgr/plugins/tests/Makefile.am

@@ -10,7 +10,7 @@ if ENABLE_PYTHON_COVERAGE
 endif
 	for pytest in $(PYTESTS) ; do \
 	echo Running test: $$pytest ; \
-	env PLUGIN_DIR=$(abs_srcdir)/.. \
+	env B10_TEST_PLUGIN_DIR=$(abs_srcdir)/..:$(abs_builddir)/.. \
 	env PYTHONPATH=$(abs_top_srcdir)/src/lib/python:$(abs_top_builddir)/src/lib/python:$(abs_top_builddir)/src/bin/cfgmgr \
 	$(PYCOVERAGE_RUN) $(abs_builddir)/$$pytest || exit ; \
 	done

+ 2 - 2
src/bin/cfgmgr/plugins/tests/tsig_keys_test.py

@@ -16,7 +16,7 @@
 # Make sure we can load the module, put it into path
 import sys
 import os
-sys.path.append(os.environ["PLUGIN_DIR"])
+sys.path.extend(os.environ["B10_TEST_PLUGIN_DIR"].split(':'))
 
 import tsig_keys
 import unittest
@@ -47,7 +47,7 @@ class TSigKeysTest(unittest.TestCase):
         # Correct name
         self.assertEqual("tsig_keys", spec.get_module_name())
         # There are no commands, nobody would handle them anyway
-        self.assertEqual({}, spec.get_commands_spec())
+        self.assertEqual([], spec.get_commands_spec())
         # There's some nonempty configuration
         self.assertNotEqual({}, spec.get_config_spec())
 

+ 4 - 2
src/bin/cfgmgr/plugins/tsig_keys.py

@@ -13,8 +13,10 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-# TODO: Put the real spec definition here
-spec = None
+from isc.config.module_spec import module_spec_from_file
+from isc.util.file import path_search
+from bind10_config import PLUGIN_PATHS
+spec = module_spec_from_file(path_search('tsig_keys.spec', PLUGIN_PATHS))
 
 def check():
     pass

+ 3 - 0
src/lib/python/bind10_config.py.in

@@ -46,5 +46,8 @@ def reload():
         PREFIX = "@prefix@"
         DATA_PATH = "@localstatedir@/@PACKAGE@".replace("${prefix}", PREFIX)
         PLUGIN_PATHS = ["@prefix@/share/@PACKAGE@/config_plugins"]
+    # For testing the plugins so they can find their own spec files
+    if "B10_TEST_PLUGIN_DIR" in os.environ:
+        PLUGIN_PATHS = os.environ["B10_TEST_PLUGIN_DIR"].split(':')
 
 reload()

+ 1 - 1
src/lib/python/isc/util/file.py

@@ -26,4 +26,4 @@ def path_search(filename, paths):
         f = join(p, filename)
         if exists(f):
             return f
-    raise IOError("'" + filename + "' not found")
+    raise IOError("'" + filename + "' not found in " + str(paths))