]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3300] revert fix and move poll
authorRazvan Becheriu <razvan@isc.org>
Fri, 22 Mar 2024 11:59:06 +0000 (13:59 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 22 Mar 2024 14:17:03 +0000 (14:17 +0000)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/tests/hooks_unittest.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/tests/hooks_unittest.cc

index 0c0a24c174a05d7d2ba4e75b5dea1c403ab49b91..54a8d12da21a19d48716339ad0dd0d167bc46b55 100644 (file)
@@ -450,6 +450,16 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
         LOG_FATAL(dhcp4_logger, DHCP4_CONFIG_UNRECOVERABLE_ERROR);
     }
 
+    /// Let postponed hook initializations to run.
+    try {
+        getIOService()->poll();
+    } catch (const std::exception& ex) {
+        std::ostringstream err;
+        err << "Error initializing hooks: "
+            << ex.what();
+        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
+    }
+
     return (result);
 }
 
@@ -913,7 +923,7 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
 
     // Allow DB reconnect on startup. The database connection parameters specify
     // respective details.
-    std::shared_ptr<DbConnectionInitWithRetry> dbr(new DbConnectionInitWithRetry());
+    DbConnectionInitWithRetry retry;
 
     // Single stream instance used in all error clauses
     std::ostringstream err;
@@ -1092,17 +1102,6 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
         return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
     }
 
-    dbr.reset();
-
-    /// Let postponed hook initializations to run.
-    try {
-        ControlledDhcpv4Srv::getInstance()->getIOService()->poll();
-    } catch (const std::exception& ex) {
-        err << "Error initializing hooks: "
-            << ex.what();
-        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
-    }
-
     return (answer);
 }
 
index 0bcc70d2d5491e4164276e45dfc1f49b47ecf0be..63ed6a152f3ab224ac68c966801528c9c0ef45d8 100644 (file)
@@ -4052,7 +4052,7 @@ TEST_F(LoadUnloadDhcpv4SrvTest, startServiceFail) {
     // section which loads the callout library #4, which implements
     // dhcp4_srv_configured callout and a failing start service.
     string config_str =
-        "{"
+        "{ \"Dhcp4\": {"
         "    \"interfaces-config\": {"
         "        \"interfaces\": [ ]"
         "    },"
@@ -4069,13 +4069,13 @@ TEST_F(LoadUnloadDhcpv4SrvTest, startServiceFail) {
         "            \"library\": \"" + std::string(CALLOUT_LIBRARY_4) + "\""
         "        }"
         "    ]"
-        "}";
+        "} }";
 
     ConstElementPtr config = Element::fromJSON(config_str);
 
     // Configure the server.
     ConstElementPtr answer;
-    ASSERT_NO_THROW(answer = srv->processConfig(config));
+    ASSERT_NO_THROW(answer = srv->processCommand("config-set", config));
 
     // Make sure there was an error with expected message.
     int status_code;
index e304537ba971dddf80c2837171a247bf80b7a3a3..66717ed51377a48c6b2000062c8232715427d2f6 100644 (file)
@@ -452,6 +452,16 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
         LOG_FATAL(dhcp6_logger, DHCP6_CONFIG_UNRECOVERABLE_ERROR);
     }
 
+    /// Let postponed hook initializations to run.
+    try {
+        getIOService()->poll();
+    } catch (const std::exception& ex) {
+        std::ostringstream err;
+        err << "Error initializing hooks: "
+            << ex.what();
+        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
+    }
+
     return (result);
 }
 
@@ -918,7 +928,7 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
 
     // Allow DB reconnect on startup. The database connection parameters specify
     // respective details.
-    std::shared_ptr<DbConnectionInitWithRetry> dbr(new DbConnectionInitWithRetry());
+    DbConnectionInitWithRetry retry;
 
     // Single stream instance used in all error clauses
     std::ostringstream err;
@@ -1112,17 +1122,6 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
         return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
     }
 
-    dbr.reset();
-
-    /// Let postponed hook initializations to run.
-    try {
-        ControlledDhcpv6Srv::getInstance()->getIOService()->poll();
-    } catch (const std::exception& ex) {
-        err << "Error initializing hooks: "
-            << ex.what();
-        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
-    }
-
     return (answer);
 }
 
index 7b4d0b5f8b5c67d6480ec0781c1a991eea65e321..7ee5e1f6b61eda0ea25740f71723dfdf3a9e09cf 100644 (file)
@@ -5846,7 +5846,7 @@ TEST_F(LoadUnloadDhcpv6SrvTest, startServiceFail) {
     // section which loads the callout library #4, which implements
     // dhcp6_srv_configured callout and a failing start service.
     string config_str =
-        "{"
+        "{ \"Dhcp6\": {"
         "    \"interfaces-config\": {"
         "        \"interfaces\": [ ]"
         "    },"
@@ -5864,13 +5864,13 @@ TEST_F(LoadUnloadDhcpv6SrvTest, startServiceFail) {
         "            \"library\": \"" + std::string(CALLOUT_LIBRARY_4) + "\""
         "        }"
         "    ]"
-        "}";
+        "} }";
 
     ConstElementPtr config = Element::fromJSON(config_str);
 
     // Configure the server.
     ConstElementPtr answer;
-    ASSERT_NO_THROW(answer = srv->processConfig(config));
+    ASSERT_NO_THROW(answer = srv->processCommand("config-set", config));
 
     // Make sure there was an error with expected message.
     int status_code;