]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Load Lua bindings before parsing yaml configuration
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 24 Mar 2025 11:46:42 +0000 (12:46 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 25 Mar 2025 09:02:07 +0000 (10:02 +0100)
We need the Lua bindings so that inline and loaded from a file Lua
syntax work. Our regression tests did not catch this because the
setup always created an empty Lua file, causing the Lua bindings to
be loaded. This commit also fixes that by not creating (and removing
if needed) empty Lua files in the regression tests setup.

pdns/dnsdistdist/dnsdist.cc
regression-tests.dnsdist/dnsdisttests.py

index 6d2d0779508ea16672c5c82c05df1e563bdb7846..661324812659cab056ee3b2bd886ff819c131bb5 100644 (file)
@@ -3288,9 +3288,11 @@ static std::optional<std::string> lookForTentativeConfigurationFileWithExtension
 static bool loadConfigurationFromFile(const std::string& configurationFile, bool isClient, bool configCheck)
 {
   if (boost::ends_with(configurationFile, ".yml")) {
+    // the bindings are always needed, for example for inline Lua
+    dnsdist::lua::setupLuaBindingsOnly(*(g_lua.lock()), isClient, configCheck);
+
     if (auto tentativeLuaConfFile = lookForTentativeConfigurationFileWithExtension(configurationFile, "lua")) {
       vinfolog("Loading configuration from auto-discovered Lua file %s", *tentativeLuaConfFile);
-      dnsdist::lua::setupLuaBindingsOnly(*(g_lua.lock()), isClient, configCheck);
       dnsdist::configuration::lua::loadLuaConfigurationFile(*(g_lua.lock()), *tentativeLuaConfFile, configCheck);
     }
     vinfolog("Loading configuration from YAML file %s", configurationFile);
index fbf757454d322bdfa0441c26ce669eba120a8bf9..65b17224ecb37d9a90ccf2be9b7abf357fb40269 100644 (file)
@@ -153,13 +153,16 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
         if not cls._yaml_config_template:
           confFile = luaConfFile
 
-        with open(luaConfFile, 'w') as conf:
+        if len(cls._config_template.strip(' \n\t')) > 0:
+          with open(luaConfFile, 'w') as conf:
             conf.write("-- Autogenerated by dnsdisttests.py\n")
             conf.write(f"-- dnsdist will listen on {cls._dnsDistPort}\n")
             conf.write(cls._config_template % params)
             if not cls._yaml_config_template:
-                conf.write("\n")
-                conf.write("setSecurityPollSuffix('')")
+              conf.write("\n")
+              conf.write("setSecurityPollSuffix('')")
+        elif os.path.exists(luaConfFile):
+          os.unlink(luaConfFile)
 
         if cls._skipListeningOnCL:
           dnsdistcmd = [os.environ['DNSDISTBIN'], '--supervised', '-C', confFile ]