]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1402] Comm recovery enabled via config
authorMarcin Siodelski <marcin@isc.org>
Tue, 22 Dec 2020 13:26:25 +0000 (14:26 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 13 Jan 2021 09:11:31 +0000 (10:11 +0100)
There is a new parameter, delayed-updates-limit, which can be used to
enable communication-recovery state in the load-balancing mode and control
how many lease updates can be queued while being in this state.

src/hooks/dhcp/high_availability/ha_config.cc
src/hooks/dhcp/high_availability/ha_config.h
src/hooks/dhcp/high_availability/ha_config_parser.cc
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/tests/ha_config_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_test.cc
src/hooks/dhcp/high_availability/tests/ha_test.h
src/hooks/dhcp/high_availability/tests/query_filter_unittest.cc

index 04179d86e498ff88f4f8cd45fdc68391b4c5b799..c0b67e2b0ce931b85a6823e1770d54366f50627d 100644 (file)
@@ -153,9 +153,9 @@ HAConfig::StateMachineConfig::getStateConfig(const int state) {
 HAConfig::HAConfig()
     : this_server_name_(), ha_mode_(HOT_STANDBY), send_lease_updates_(true),
       sync_leases_(true), sync_timeout_(60000), sync_page_limit_(10000),
-      heartbeat_delay_(10000), max_response_delay_(60000), max_ack_delay_(10000),
-      max_unacked_clients_(10), wait_backup_ack_(false), peers_(),
-      state_machine_(new StateMachineConfig()) {
+      delayed_updates_limit_(0), heartbeat_delay_(10000), max_response_delay_(60000),
+      max_ack_delay_(10000), max_unacked_clients_(10), wait_backup_ack_(false),
+      peers_(), state_machine_(new StateMachineConfig()) {
 }
 
 HAConfig::PeerConfigPtr
@@ -343,6 +343,13 @@ HAConfig::validate() const {
                       " hot standby configuration");
         }
 
+        // The server must not transition to communication-recovery state in
+        // hot-standby mode.
+        if (delayed_updates_limit_ > 0) {
+            isc_throw(HAConfigValidationError, "'delayed-updates-limit' must be set to 0 in"
+                      " the hot standby configuration");
+        }
+
     } else if (ha_mode_ == PASSIVE_BACKUP) {
         if (peers_cnt.count(PeerConfig::SECONDARY) > 0) {
             isc_throw(HAConfigValidationError, "secondary servers not allowed in the"
@@ -358,6 +365,13 @@ HAConfig::validate() const {
             isc_throw(HAConfigValidationError, "primary server required in the"
                       " passive backup configuration");
         }
+
+        // The server must not transition to communication-recovery state in
+        // passive-backup mode.
+        if (delayed_updates_limit_ > 0) {
+            isc_throw(HAConfigValidationError, "'delayed-updates-limit' must be set to 0 in"
+                      " the passive backup configuration");
+        }
     }
 
 }
index 84c15d9063510fa9a07fae8947d71a803a07bb4f..113dcb07a8b27504e3325fd490ed600d7fa328e5 100644 (file)
@@ -382,6 +382,49 @@ public:
         sync_page_limit_ = sync_page_limit;
     }
 
+    /// @brief Returns the maximum number of lease updates which can be held
+    /// unsent in the communication-recovery state.
+    ///
+    /// If the server is in the communication-recovery state it is unable to
+    /// send lease updates to the partner. Instead it keeps lease updates
+    /// hoping to send them when the communication is resumed. This value
+    /// designates a limit of how many such updates can be held. If this
+    /// number is exceeded the server continues to respond to the clients
+    /// but will have to go through regular lease database synchronization
+    /// when the communication is resumed.
+    ///
+    /// @return Limit of the lease backlog size in communication-recovery.
+    uint32_t getDelayedUpdatesLimit() const {
+        return (delayed_updates_limit_);
+    }
+
+    /// @brief Sets new limit for the number of lease updates to be held
+    /// unsent in the communication-recovery state.
+    ///
+    /// If the server is in the communication-recovery state it is unable to
+    /// send lease updates to the partner. Instead it keeps lease updates
+    /// hoping to send them when the communication is resumed. This value
+    /// designates a limit of how many such updates can be held. If this
+    /// number is exceeded the server continues to respond to the clients
+    /// but will have to go through regular lease database synchronization
+    /// when the communication is resumed.
+    ///
+    /// @param delayed_updates_limit new limit.
+    void setDelayedUpdatesLimit(const uint32_t delayed_updates_limit) {
+        delayed_updates_limit_ = delayed_updates_limit;
+    }
+
+    /// @brief Convenience function checking if communication recovery is allowed.
+    ///
+    /// Communication recovery is only allowed in load-balancing configurations.
+    /// It is enabled by setting delayed-updates-limit to a value greater
+    /// than 0.
+    ///
+    /// @return true if communication recovery is enabled, false otherwise.
+    bool amAllowingCommRecovery() const {
+        return (delayed_updates_limit_ > 0);
+    }
+
     /// @brief Returns heartbeat delay in milliseconds.
     ///
     /// This value indicates the delay in sending a heartbeat command after
@@ -534,6 +577,8 @@ public:
     uint32_t sync_timeout_;               ///< Timeout for syncing lease database (ms)
     uint32_t sync_page_limit_;            ///< Page size limit while synchronizing
                                           ///< leases.
+    uint32_t delayed_updates_limit_;      ///< Maximum number of lease updates held
+                                          ///< for later send in communication-recovery.
     uint32_t heartbeat_delay_;            ///< Heartbeat delay in milliseconds.
     uint32_t max_response_delay_;         ///< Max delay in response to heartbeats.
     uint32_t max_ack_delay_;              ///< Maximum DHCP message ack delay.
index a0ac78f5b70c5a67d5f73a5310520f86295f8fa2..7f4d797f0cce0edabefa2d07eebe118f347dd868 100644 (file)
@@ -18,8 +18,14 @@ using namespace isc::http;
 
 namespace {
 
+/// @brief Default values for HA load balancing.
+const SimpleDefaults HA_CONFIG_LB_DEFAULTS = {
+    { "delayed-updates-limit", Element::integer, "100" },
+};
+
 /// @brief Default values for HA configuration.
 const SimpleDefaults HA_CONFIG_DEFAULTS = {
+    { "delayed-updates-limit", Element::integer, "0" },
     { "heartbeat-delay", Element::integer, "10000" },
     { "max-ack-delay", Element::integer, "10000" },
     { "max-response-delay", Element::integer, "60000" },
@@ -86,7 +92,15 @@ HAConfigParser::parseInternal(const HAConfigPtr& config_storage,
     // Get the HA configuration.
     ElementPtr c = config_vec[0];
 
-    // Set default values.
+    // Get 'mode'. That's the first thing to gather because the defaults we
+    // apply to the configuration depend on the mode.
+    config_storage->setHAMode(getString(c, "mode"));
+
+    // Set load-balancing specific defaults.
+    if (config_storage->getHAMode() == HAConfig::LOAD_BALANCING) {
+        setDefaults(c, HA_CONFIG_LB_DEFAULTS);
+    }
+    // Set general defaults.
     setDefaults(c, HA_CONFIG_DEFAULTS);
 
     // HA configuration must be a map.
@@ -94,7 +108,7 @@ HAConfigParser::parseInternal(const HAConfigPtr& config_storage,
         isc_throw(ConfigError, "expected list of maps in the HA configuration");
     }
 
-    // It must contains peers section.
+    // It must contain peers section.
     if (!c->contains("peers")) {
         isc_throw(ConfigError, "'peers' parameter missing in HA configuration");
     }
@@ -119,15 +133,11 @@ HAConfigParser::parseInternal(const HAConfigPtr& config_storage,
         }
     }
 
-
     // We have made major sanity checks, so let's try to gather some values.
 
     // Get 'this-server-name'.
     config_storage->setThisServerName(getString(c, "this-server-name"));
 
-    // Get 'mode'.
-    config_storage->setHAMode(getString(c, "mode"));
-
     // Get 'send-lease-updates'.
     config_storage->setSendLeaseUpdates(getBoolean(c, "send-lease-updates"));
 
@@ -142,6 +152,10 @@ HAConfigParser::parseInternal(const HAConfigPtr& config_storage,
     uint32_t sync_page_limit = getAndValidateInteger<uint32_t>(c, "sync-page-limit");
     config_storage->setSyncPageLimit(sync_page_limit);
 
+    // Get 'delayed-updates-limit'.
+    uint32_t delayed_updates_limit = getAndValidateInteger<uint32_t>(c, "delayed-updates-limit");
+    config_storage->setDelayedUpdatesLimit(delayed_updates_limit);
+
     // Get 'heartbeat-delay'.
     uint16_t heartbeat_delay = getAndValidateInteger<uint16_t>(c, "heartbeat-delay");
     config_storage->setHeartbeatDelay(heartbeat_delay);
index 43ac7e81f8527b6dc11f66fe9df77866e74b54ee..d19adef6bb3cf1790ab314bd8e6c2c30b4d1b3ab 100644 (file)
@@ -53,8 +53,9 @@ HAService::HAService(const IOServicePtr& io_service, const NetworkStatePtr& netw
                      const HAConfigPtr& config, const HAServerType& server_type)
     : io_service_(io_service), network_state_(network_state), config_(config),
       server_type_(server_type), client_(*io_service), communication_state_(),
-      query_filter_(config), mutex_(), pending_requests_(), lease4_update_backlog_(100),
-      lease6_update_backlog_(100) {
+      query_filter_(config), mutex_(), pending_requests_(),
+      lease4_update_backlog_(config->getDelayedUpdatesLimit()),
+      lease6_update_backlog_(config->getDelayedUpdatesLimit()) {
 
     if (server_type == HAServerType::DHCPv4) {
         communication_state_.reset(new CommunicationState4(io_service_, config));
@@ -81,7 +82,7 @@ HAService::defineEvents() {
     defineEvent(HA_MAINTENANCE_NOTIFY_EVT, "HA_MAINTENANCE_NOTIFY_EVT");
     defineEvent(HA_MAINTENANCE_START_EVT, "HA_MAINTENANCE_START_EVT");
     defineEvent(HA_MAINTENANCE_CANCEL_EVT, "HA_MAINTENANCE_CANCEL_EVT");
-}
+ }
 
 void
 HAService::verifyEvents() {
@@ -309,7 +310,7 @@ HAService::normalStateHandler() {
         if (shouldPartnerDown()) {
             verboseTransition(HA_PARTNER_DOWN_ST);
 
-        } else if (config_->getHAMode() == HAConfig::LOAD_BALANCING) {
+        } else if (config_->amAllowingCommRecovery()) {
             verboseTransition(HA_COMMUNICATION_RECOVERY_ST);
 
         } else {
index 3a523b7c19a910f2fc7eadd427915fad7f1424ad..1dd62d0c74ff54ca5cb4009cdeb9bc2f289444af 100644 (file)
@@ -69,6 +69,7 @@ TEST_F(HAConfigTest, configureLoadBalancing) {
         "        \"sync-leases\": false,"
         "        \"sync-timeout\": 20000,"
         "        \"sync-page-limit\": 3,"
+        "        \"delayed-updates-limit\": 111,"
         "        \"heartbeat-delay\": 8,"
         "        \"max-response-delay\": 11,"
         "        \"max-ack-delay\": 5,"
@@ -124,6 +125,8 @@ TEST_F(HAConfigTest, configureLoadBalancing) {
     EXPECT_FALSE(impl->getConfig()->amSyncingLeases());
     EXPECT_EQ(20000, impl->getConfig()->getSyncTimeout());
     EXPECT_EQ(3, impl->getConfig()->getSyncPageLimit());
+    EXPECT_EQ(111, impl->getConfig()->getDelayedUpdatesLimit());
+    EXPECT_TRUE(impl->getConfig()->amAllowingCommRecovery());
     EXPECT_EQ(8, impl->getConfig()->getHeartbeatDelay());
     EXPECT_EQ(11, impl->getConfig()->getMaxResponseDelay());
     EXPECT_EQ(5, impl->getConfig()->getMaxAckDelay());
@@ -241,6 +244,8 @@ TEST_F(HAConfigTest, configureHotStandby) {
     EXPECT_TRUE(impl->getConfig()->amSyncingLeases());
     EXPECT_EQ(60000, impl->getConfig()->getSyncTimeout());
     EXPECT_EQ(10000, impl->getConfig()->getSyncPageLimit());
+    EXPECT_EQ(0, impl->getConfig()->getDelayedUpdatesLimit());
+    EXPECT_FALSE(impl->getConfig()->amAllowingCommRecovery());
     EXPECT_EQ(10000, impl->getConfig()->getHeartbeatDelay());
     EXPECT_EQ(10000, impl->getConfig()->getMaxAckDelay());
     EXPECT_EQ(10, impl->getConfig()->getMaxUnackedClients());
@@ -1175,7 +1180,7 @@ TEST_F(HAConfigTest, invalidUser) {
         "            },"
         "            {"
         "                \"name\": \"server2\","
-        "                \"url\": \":http//127.0.0.1:8080/\","
+        "                \"url\": \"http://127.0.0.1:8080/\","
         "                \"basic-auth-user\": \"foo:bar\","
         "                \"role\": \"secondary\","
         "                \"auto-failover\": true"
@@ -1186,6 +1191,57 @@ TEST_F(HAConfigTest, invalidUser) {
         "user 'foo:bar' must not contain a ':' in peer 'server2'");
 }
 
+// Test that setting delayed-updates-limit is not allowed in hot-standby mode.
+TEST_F(HAConfigTest, hotStandbyDelayedUpdatesLimit) {
+    testInvalidConfig(
+        "["
+        "    {"
+        "        \"this-server-name\": \"server1\","
+        "        \"mode\": \"hot-standby\","
+        "        \"delayed-updates-limit\": 1,"
+        "        \"peers\": ["
+        "            {"
+        "                \"name\": \"server1\","
+        "                \"url\": \"http://127.0.0.1:8080/\","
+        "                \"role\": \"primary\","
+        "                \"auto-failover\": false"
+        "            },"
+        "            {"
+        "                \"name\": \"server2\","
+        "                \"url\": \"http://127.0.0.1:8080/\","
+        "                \"role\": \"standby\","
+        "                \"auto-failover\": true"
+        "            }"
+        "        ]"
+        "    }"
+        "]",
+        "'delayed-updates-limit' must be set to 0 in the hot standby configuration");
+}
+
+// Test that setting delayed-updates-limit is not allowed in passive-backup mode.
+TEST_F(HAConfigTest, passiveBackupDelayedUpdatesLimit) {
+    testInvalidConfig(
+        "["
+        "    {"
+        "        \"this-server-name\": \"server1\","
+        "        \"mode\": \"passive-backup\","
+        "        \"delayed-updates-limit\": 1,"
+        "        \"peers\": ["
+        "            {"
+        "                \"name\": \"server1\","
+        "                \"url\": \"http://127.0.0.1:8080/\","
+        "                \"role\": \"primary\""
+        "            },"
+        "            {"
+        "                \"name\": \"server2\","
+        "                \"url\": \"http://127.0.0.1:8080/\","
+        "                \"role\": \"backup\""
+        "            }"
+        "        ]"
+        "    }"
+        "]",
+        "'delayed-updates-limit' must be set to 0 in the passive backup configuration");
+}
 
 // Test that conversion of the role names works correctly.
 TEST_F(HAConfigTest, stringToRole) {
index c8ba754cc7691fe4a353e28dd627e445b2bdb78b..6bd786eadd5ae6f0c79e43d28e8b7e18ba5f4781 100644 (file)
@@ -1878,11 +1878,7 @@ TEST_F(HAServiceTest, loadBalancingScopeSelection) {
 
 // Test that primary server in hot standby configuration processes all queries.
 TEST_F(HAServiceTest, hotStandbyScopeSelectionThisPrimary) {
-    // Create HA configuration for load balancing.
-    HAConfigPtr config_storage = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
-    config_storage->setHAMode("hot-standby");
+    HAConfigPtr config_storage = createValidConfiguration(HAConfig::HOT_STANDBY);
     config_storage->getPeerConfig("server2")->setRole("standby");
 
     // ... and HA service using this configuration.
@@ -1931,11 +1927,7 @@ TEST_F(HAServiceTest, hotStandbyScopeSelectionThisPrimary) {
 
 // Test that secondary server in hot standby configuration processes no queries.
 TEST_F(HAServiceTest, hotStandbyScopeSelectionThisStandby) {
-    // Create HA configuration for load balancing.
-    HAConfigPtr config_storage = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
-    config_storage->setHAMode("hot-standby");
+    HAConfigPtr config_storage = createValidConfiguration(HAConfig::HOT_STANDBY);
     config_storage->getPeerConfig("server2")->setRole("standby");
     config_storage->setThisServerName("server2");
 
@@ -5052,11 +5044,10 @@ TEST_F(HAServiceStateMachineTest, waitingParterDownLoadBalancingPartnerDown) {
 //     me to transition to the waiting state and then synchronize my lease
 //     database.
 TEST_F(HAServiceStateMachineTest, waitingParterDownHotStandbyPartnerDown) {
-    HAConfigPtr valid_config = createValidConfiguration();
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
 
     // Turn it into hot-standby configuration.
     valid_config->setThisServerName("server2");
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     // Start the server: offline ---> WAITING state.
@@ -5643,6 +5634,20 @@ TEST_F(HAServiceStateMachineTest, noSyncingTransitionsLoadBalancingPrimary) {
                    FinalState(HA_READY_ST));
 }
 
+// This test verifies that the load balancing server does not transition to
+// the communication recovery state when delayed-updates-limit is set
+// to 0.
+TEST_F(HAServiceStateMachineTest, noCommunicationRecoverytransitionsLoadBalancingPrimary) {
+    partner_->startup();
+
+    HAConfigPtr valid_config = createValidConfiguration();
+    valid_config->setDelayedUpdatesLimit(0);
+    startService(valid_config);
+
+    testTransition(MyState(HA_LOAD_BALANCING_ST), PartnerState(HA_UNAVAILABLE_ST),
+                   FinalState(HA_LOAD_BALANCING_ST));
+}
+
 // This test checks that the server in the load balancing mode transitions to
 // the "terminated" state when the clock skew gets high.
 TEST_F(HAServiceStateMachineTest, terminateTransitionsLoadBalancingPrimary) {
@@ -6356,10 +6361,9 @@ TEST_F(HAServiceStateMachineTest, heartbeatLoadBalancing) {
 TEST_F(HAServiceStateMachineTest, stateTransitionsHotStandbyPrimary) {
     partner_->startup();
 
-    HAConfigPtr valid_config = createValidConfiguration();
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
 
     // Turn it into hot-standby configuration.
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6581,10 +6585,9 @@ TEST_F(HAServiceStateMachineTest, stateTransitionsHotStandbyPrimary) {
 TEST_F(HAServiceStateMachineTest, noSyncingTransitionsHotStandbyPrimary) {
     partner_->startup();
 
-    HAConfigPtr valid_config = createValidConfiguration();
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
 
     // Turn it into hot-standby configuration.
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
     valid_config->setSyncLeases(false);
 
@@ -6605,10 +6608,9 @@ TEST_F(HAServiceStateMachineTest, noSyncingTransitionsHotStandbyPrimary) {
 TEST_F(HAServiceStateMachineTest, terminateTransitionsHotStandbyPrimary) {
     partner_->startup();
 
-    HAConfigPtr valid_config = createValidConfiguration();
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
 
     // Turn it into hot-standby configuration.
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6627,11 +6629,10 @@ TEST_F(HAServiceStateMachineTest, stateTransitionsHotStandbyStandby) {
     partner_.reset(new HAPartner(listener_, factory_));
     partner_->startup();
 
-    HAConfigPtr valid_config = createValidConfiguration();
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
 
     // Turn it into hot-standby configuration.
     valid_config->setThisServerName("server2");
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6820,11 +6821,10 @@ TEST_F(HAServiceStateMachineTest, noSyncingTransitionsHotStandbyStandby) {
     partner_.reset(new HAPartner(listener_, factory_));
     partner_->startup();
 
-    HAConfigPtr valid_config = createValidConfiguration();
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
 
     // Turn it into hot-standby configuration.
     valid_config->setThisServerName("server2");
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
     valid_config->setSyncLeases(false);
 
@@ -6846,11 +6846,10 @@ TEST_F(HAServiceStateMachineTest, terminateTransitionsHotStandbyStandby) {
     partner_.reset(new HAPartner(listener_, factory_));
     partner_->startup();
 
-    HAConfigPtr valid_config = createValidConfiguration();
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
 
     // Turn it into hot-standby configuration.
     valid_config->setThisServerName("server2");
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6865,10 +6864,7 @@ TEST_F(HAServiceStateMachineTest, terminateTransitionsHotStandbyStandby) {
 // and whether the DHCP service is disabled or enabled in certain states.
 // This is primary server.
 TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyPrimary) {
-    HAConfigPtr valid_config = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
-    valid_config->setHAMode("hot-standby");
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6890,9 +6886,7 @@ TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyPrimary) {
 // This test verifies that auto-failover setting does not affect scopes
 // handling by the primary server in the hot-standby mode.
 TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyPrimaryNoFailover) {
-    HAConfigPtr valid_config = createValidConfiguration();
-    // Turn it into hot-standby configuration.
-    valid_config->setHAMode("hot-standby");
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     // Disable auto-failover.
@@ -6918,10 +6912,7 @@ TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyPrimaryNoFailover) {
 // while being in various states. The HA configuration is hot standby and
 // the server is primary.
 TEST_F(HAServiceStateMachineTest, shouldSendLeaseUpdatesHotStandbyPrimary) {
-    HAConfigPtr valid_config = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
-    valid_config->setHAMode("hot-standby");
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6941,10 +6932,7 @@ TEST_F(HAServiceStateMachineTest, shouldSendLeaseUpdatesHotStandbyPrimary) {
 // This test verifies if the server would send heartbeat to the partner
 // while being in various states. The HA configuration is hot standby.
 TEST_F(HAServiceStateMachineTest, heartbeatHotStandby) {
-    HAConfigPtr valid_config = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
-    valid_config->setHAMode("hot-standby");
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6962,11 +6950,8 @@ TEST_F(HAServiceStateMachineTest, heartbeatHotStandby) {
 // and whether the DHCP service is disabled or enabled in certain states.
 // This is standby server.
 TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyStandby) {
-    HAConfigPtr valid_config = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->setThisServerName("server2");
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
@@ -6992,11 +6977,8 @@ TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyStandby) {
 // This test verifies that the standby server does not take ownership
 // of the primary server's scope when auto-failover is set to false
 TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyStandbyNoFailover) {
-    HAConfigPtr valid_config = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->setThisServerName("server2");
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     // Disable auto-failover.
@@ -7032,11 +7014,8 @@ TEST_F(HAServiceStateMachineTest, scopesServingHotStandbyStandbyNoFailover) {
 // while being in various states. The HA configuration is hot standby and
 // the server is secondary.
 TEST_F(HAServiceStateMachineTest, shouldSendLeaseUpdatesHotStandbyStandby) {
-    HAConfigPtr valid_config = createValidConfiguration();
-
-    // Turn it into hot-standby configuration.
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->setThisServerName("server2");
-    valid_config->setHAMode("hot-standby");
     valid_config->getPeerConfig("server2")->setRole("standby");
 
     startService(valid_config);
index a8ee67d1f025ca89a85c62ec36c6083b692a38a6..fd3fd3b19a9059d946067018b5cfbd8802bab124 100644 (file)
@@ -216,11 +216,11 @@ HATest::createValidPassiveBackupJsonConfiguration() const {
 
 
 HAConfigPtr
-HATest::createValidConfiguration() const {
+HATest::createValidConfiguration(const HAConfig::HAMode& ha_mode) const {
     HAConfigPtr config_storage(new HAConfig());
     HAConfigParser parser;
 
-    parser.parse(config_storage, createValidJsonConfiguration());
+    parser.parse(config_storage, createValidJsonConfiguration(ha_mode));
     return (config_storage);
 }
 
index 94d230827b8f7525b64feeae798984569e36c794..60a2314cda9486cbdbd43f98ba59a182bf7902f6 100644 (file)
@@ -150,8 +150,10 @@ public:
 
     /// @brief Return HA configuration with three servers.
     ///
+    /// @param ha_mode HA operation mode (default is load balancing).
     /// @return Pointer to the parsed configuration.
-    HAConfigPtr createValidConfiguration() const;
+    HAConfigPtr createValidConfiguration(const HAConfig::HAMode& ha_mode =
+                                         HAConfig::LOAD_BALANCING) const;
 
     /// @brief Return passive-backup configuration.
     ///
index 3f54e4dd81850ec1621fb835b0e4c32005f20ad7..3f8485aeeac700aab21e6555cd881a8563fa13ee 100644 (file)
@@ -314,9 +314,7 @@ QueryFilterTest::loadBalancingThisBackup() {
 
 void
 QueryFilterTest::hotStandbyThisPrimary() {
-    HAConfigPtr config = createValidConfiguration();
-
-    config->setHAMode("hot-standby");
+    HAConfigPtr config = createValidConfiguration(HAConfig::HOT_STANDBY);
     config->getPeerConfig("server2")->setRole("standby");
 
     QueryFilter filter(config);
@@ -350,9 +348,7 @@ QueryFilterTest::hotStandbyThisPrimary() {
 
 void
 QueryFilterTest::hotStandbyThisSecondary() {
-    HAConfigPtr config = createValidConfiguration();
-
-    config->setHAMode("hot-standby");
+    HAConfigPtr config = createValidConfiguration(HAConfig::HOT_STANDBY);
     config->getPeerConfig("server2")->setRole("standby");
     config->setThisServerName("server2");
 
@@ -389,9 +385,7 @@ QueryFilterTest::hotStandbyThisSecondary() {
 
 void
 QueryFilterTest::hotStandbyThisBackup() {
-    HAConfigPtr config = createValidConfiguration();
-
-    config->setHAMode("hot-standby");
+    HAConfigPtr config = createValidConfiguration(HAConfig::HOT_STANDBY);
     config->getPeerConfig("server2")->setRole("standby");
     config->setThisServerName("server3");
 
@@ -577,9 +571,7 @@ QueryFilterTest::loadBalancingThisBackup6() {
 
 void
 QueryFilterTest::hotStandbyThisPrimary6() {
-    HAConfigPtr config = createValidConfiguration();
-
-    config->setHAMode("hot-standby");
+    HAConfigPtr config = createValidConfiguration(HAConfig::HOT_STANDBY);
     config->getPeerConfig("server2")->setRole("standby");
 
     QueryFilter filter(config);
@@ -613,9 +605,7 @@ QueryFilterTest::hotStandbyThisPrimary6() {
 
 void
 QueryFilterTest::hotStandbyThisSecondary6() {
-    HAConfigPtr config = createValidConfiguration();
-
-    config->setHAMode("hot-standby");
+    HAConfigPtr config = createValidConfiguration(HAConfig::HOT_STANDBY);
     config->getPeerConfig("server2")->setRole("standby");
     config->setThisServerName("server2");
 
@@ -652,9 +642,7 @@ QueryFilterTest::hotStandbyThisSecondary6() {
 
 void
 QueryFilterTest::hotStandbyThisBackup6() {
-    HAConfigPtr config = createValidConfiguration();
-
-    config->setHAMode("hot-standby");
+    HAConfigPtr config = createValidConfiguration(HAConfig::HOT_STANDBY);
     config->getPeerConfig("server2")->setRole("standby");
     config->setThisServerName("server3");