Browse Source

[trac615] Prepagate corectly trough config manager

Michal 'vorner' Vaner 14 years ago
parent
commit
e33f9a6d10
2 changed files with 26 additions and 8 deletions
  1. 12 6
      src/lib/python/isc/config/cfgmgr.py
  2. 14 2
      src/lib/python/isc/config/tests/cfgmgr_test.py

+ 12 - 6
src/lib/python/isc/config/cfgmgr.py

@@ -158,15 +158,18 @@ class ConfigManager:
        channel session. If not, a new session will be created.
        The ability to specify a custom session is for testing purposes
        and should not be needed for normal usage."""
-    def __init__(self, data_path, session = None):
+    def __init__(self, data_path, database_filename = "b10-config.db",
+                 session = None):
         """Initialize the configuration manager. The data_path string
            is the path to the directory where the configuration is
-           stored (in <data_path>/b10-config.db). Session is an optional
+           stored (in <data_path>/b10-config.db). The dabase_filename
+           is the config file to load. Session is an optional
            cc-channel session. If this is not given, a new one is
-           created"""
+           created."""
         self.data_path = data_path
+        self.database_filename = database_filename
         self.module_specs = {}
-        self.config = ConfigManagerData(data_path)
+        self.config = ConfigManagerData(data_path, database_filename)
         if session:
             self.cc = session
         else:
@@ -237,10 +240,13 @@ class ConfigManager:
         """Read the current configuration from the b10-config.db file
            at the path specificied at init()"""
         try:
-            self.config = ConfigManagerData.read_from_file(self.data_path)
+            self.config = ConfigManagerData.read_from_file(self.data_path,
+                                                           self.\
+                                                           database_filename)
         except ConfigManagerDataEmpty:
             # ok, just start with an empty config
-            self.config = ConfigManagerData(self.data_path)
+            self.config = ConfigManagerData(self.data_path,
+                                            self.database_filename)
         
     def write_config(self):
         """Write the current configuration to the b10-config.db file

+ 14 - 2
src/lib/python/isc/config/tests/cfgmgr_test.py

@@ -95,10 +95,22 @@ class TestConfigManager(unittest.TestCase):
         self.data_path = os.environ['CONFIG_TESTDATA_PATH']
         self.writable_data_path = os.environ['CONFIG_WR_TESTDATA_PATH']
         self.fake_session = FakeModuleCCSession()
-        self.cm = ConfigManager(self.writable_data_path, self.fake_session)
+        self.cm = ConfigManager(self.writable_data_path,
+                                session=self.fake_session)
         self.name = "TestModule"
         self.spec = isc.config.module_spec_from_file(self.data_path + os.sep + "/spec2.spec")
-    
+
+    def test_paths(self):
+        """
+        Test data_path and database filename is passed trough to
+        underlying ConfigManagerData.
+        """
+        cm = ConfigManager("/data/path", "filename", self.fake_session)
+        self.assertEqual("/data/path/filename", cm.config.db_filename)
+        # It should preserve it while reading
+        cm.read_config()
+        self.assertEqual("/data/path/filename", cm.config.db_filename)
+
     def test_init(self):
         self.assert_(self.cm.module_specs == {})
         self.assert_(self.cm.data_path == self.writable_data_path)