Parcourir la source

[2854] updated specfile path guessing more reliable, trying FROM_BUILD.

also loosen the check for the corresponding test so it reasonably works.
JINMEI Tatuya il y a 12 ans
Parent
commit
2379e411e9

+ 13 - 7
src/lib/python/isc/server_common/bind10_server.py.in

@@ -101,13 +101,19 @@ class BIND10Server:
         path for the spec file.
 
         """
-        if 'B10_FROM_SOURCE' in os.environ:
-            specfile_path = os.environ['B10_FROM_SOURCE'] + '/src/bin/' + \
-                self.__module_name
-        else:
-            specfile_path = '${datarootdir}/bind10'\
-                .replace('${datarootdir}', '${prefix}/share')\
-                .replace('${prefix}', '/Users/jinmei/opt')
+        # First check if it's running under an 'in-source' environment,
+        # then try commonly used paths and file names.  If found, use it.
+        for ev in ['B10_FROM_SOURCE', 'B10_FROM_BUILD']:
+            if ev in os.environ:
+                specfile = os.environ[ev] + '/src/bin/' + self.__module_name +\
+                    '/' + self.__module_name + '.spec'
+                if os.path.exists(specfile):
+                    return specfile
+        # Otherwise, just use the installed path, whether or not it really
+        # exists; leave error handling to the caller.
+        specfile_path = '${datarootdir}/bind10'\
+            .replace('${datarootdir}', '${prefix}/share')\
+            .replace('${prefix}', '/Users/jinmei/opt')
         return specfile_path + '/' + self.__module_name + '.spec'
 
     def _trigger_shutdown(self):

+ 5 - 3
src/lib/python/isc/server_common/tests/bind10_server_test.py

@@ -137,9 +137,11 @@ class TestBIND10Server(unittest.TestCase):
         self.__server._run_internal = lambda: None # prevent looping
         self.assertEqual(0, self.__server.run('test'))
         # module CC session should have been setup.
-        self.assertEqual(self.__server.mod_ccsession.specfile_param,
-                         os.environ['B10_FROM_SOURCE'] +
-                         '/src/bin/test/test.spec')
+        # The exact path to the spec file can vary, so we simply check
+        # it works and it's the expected name stripping the path.
+        self.assertEqual(
+            self.__server.mod_ccsession.specfile_param.split('/')[-1],
+            'test.spec')
         self.assertEqual(self.__server.mod_ccsession.config_handler_param,
                          self.__server._config_handler)
         self.assertEqual(self.__server.mod_ccsession.command_handler_param,