From: Razvan Becheriu Date: Fri, 22 Mar 2024 11:59:06 +0000 (+0200) Subject: [#3300] revert fix and move poll X-Git-Tag: Kea-2.5.7~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a0a6f9afd0fd38d096cda22edc5e6284290dfa2;p=thirdparty%2Fkea.git [#3300] revert fix and move poll --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 0c0a24c174..54a8d12da2 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -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 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); } diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index 0bcc70d2d5..63ed6a152f 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/src/bin/dhcp4/tests/hooks_unittest.cc @@ -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; diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index e304537ba9..66717ed513 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -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 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); } diff --git a/src/bin/dhcp6/tests/hooks_unittest.cc b/src/bin/dhcp6/tests/hooks_unittest.cc index 7b4d0b5f8b..7ee5e1f6b6 100644 --- a/src/bin/dhcp6/tests/hooks_unittest.cc +++ b/src/bin/dhcp6/tests/hooks_unittest.cc @@ -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;