Skip to content

Commit da46dbf

Browse files
authored
Merge pull request #22 from innogames/ndco_4445
Respect LBNode->admin_state when satisfying min_nodes
2 parents 3f7ccdf + 19b7385 commit da46dbf

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/lb_pool.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ void LbPool::pool_logic(LbNode *last_node) {
224224
// First add the one which changed state recently.
225225
// If it was up, it is already added.
226226
if (last_node && last_node->state == LbNodeState::STATE_DOWN &&
227+
last_node->admin_state == LbNodeAdminState::STATE_ENABLED &&
227228
wanted_nodes.size() < min_nodes) {
228229
wanted_nodes.insert(last_node);
229230
last_node->min_nodes_kept = true;
@@ -236,12 +237,12 @@ void LbPool::pool_logic(LbNode *last_node) {
236237
for (LbNode *node : nodes) {
237238
if (last_node && node == last_node)
238239
continue; // Don't add recently changed LB Node.
239-
if (node->state < LbNodeState::STATE_DOWN)
240+
if (node->admin_state < LbNodeAdminState::STATE_ENABLED)
240241
continue; // Don't add downtimed LB Nodes.
241242
force_up_candidates.insert(node);
242243
}
243244

244-
// Not enough nodes? Add those which wer force-kept previously.
245+
// Not enough nodes? Add those which were force-kept previously.
245246
for (LbNode *fuc : force_up_candidates) {
246247
if (wanted_nodes.size() >= min_nodes)
247248
break; // Enough nodes already wanted.

tests/lb_pool_test.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,39 @@ TEST_F(LbPoolTest, InitUpDowntimedDrain) {
294294
EndDummyHC(test_lb_pool, "lbnode1", HealthcheckResult::HC_PASS, true);
295295
EXPECT_EQ(UpNodesNames(), set<string>({"lbnode2", "lbnode3"}));
296296
}
297+
298+
// NDCO-4445: Force-up LB Nodes not added after downtime ends
299+
// if they change state.
300+
//
301+
TEST_F(LbPoolTest, ForceUpDowntimedDrain) {
302+
// Only one LB Node in this test.
303+
base_config["lbpool.example.com"]["nodes"].erase("lbnode2");
304+
base_config["lbpool.example.com"]["nodes"].erase("lbnode3");
305+
306+
base_config["lbpool.example.com"]["health_checks"][0]["hc_max_failed"] = 1;
307+
base_config["lbpool.example.com"]["min_nodes"] = 1;
308+
base_config["lbpool.example.com"]["min_nodes_action"] = "force_up";
309+
310+
SetUp(true);
311+
312+
// Start with an online, up LB Node.
313+
EndDummyHC(test_lb_pool, "lbnode1", HealthcheckResult::HC_PASS, true);
314+
EXPECT_EQ(UpNodesNames(), set<string>({"lbnode1"}));
315+
316+
// Start a deployment.
317+
GetLbNode(test_lb_pool, "lbnode1")->change_downtime("deploy_offline");
318+
EXPECT_EQ(UpNodesNames(), set<string>());
319+
320+
// Web server is stopped while the deployment is in progress.
321+
EndDummyHC(test_lb_pool, "lbnode1", HealthcheckResult::HC_FAIL, true);
322+
EXPECT_EQ(UpNodesNames(), set<string>());
323+
324+
// The LB Node is set back to online before the deployment is finished.
325+
// min_nodes_action is obeyed, the LB Node is added even though it's down.
326+
GetLbNode(test_lb_pool, "lbnode1")->change_downtime("online");
327+
EXPECT_EQ(UpNodesNames(), set<string>({"lbnode1"}));
328+
329+
// The deployment is finished.
330+
EndDummyHC(test_lb_pool, "lbnode1", HealthcheckResult::HC_PASS, true);
331+
EXPECT_EQ(UpNodesNames(), set<string>({"lbnode1"}));
332+
}

0 commit comments

Comments
 (0)