The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6783

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Since this is not an internal request we can't redirect it, we need to handle
it.

Fixes #6770.

Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com>
From fc33dbfaecaec65af066a64b55b89002f72a2d3b Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanay...@canonical.com>
Date: Mon, 27 Jan 2020 09:03:48 +0000
Subject: [PATCH] Fix request redirect when removing a cluster member

Since this is not an internal request we can't redirect it, we need to handle
it.

Fixes #6770.

Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com>
---
 lxd/api_cluster.go        | 25 +++++++++++++++----------
 test/suites/clustering.sh |  9 +++++++--
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go
index ce608d6181..8829745e7d 100644
--- a/lxd/api_cluster.go
+++ b/lxd/api_cluster.go
@@ -909,6 +909,13 @@ func clusterNodeDelete(d *Daemon, r *http.Request) 
response.Response {
        d.clusterMembershipMutex.Lock()
        defer d.clusterMembershipMutex.Unlock()
 
+       force, err := strconv.Atoi(r.FormValue("force"))
+       if err != nil {
+               force = 0
+       }
+
+       name := mux.Vars(r)["name"]
+
        // Redirect all requests to the leader, which is the one with
        // knowning what nodes are part of the raft cluster.
        localAddress, err := node.ClusterAddress(d.db)
@@ -921,20 +928,18 @@ func clusterNodeDelete(d *Daemon, r *http.Request) 
response.Response {
        }
        if localAddress != leader {
                logger.Debugf("Redirect member delete request to %s", leader)
-               url := &url.URL{
-                       Scheme: "https",
-                       Path:   "/internal/cluster/accept",
-                       Host:   leader,
+               client, err := cluster.Connect(leader, 
d.endpoints.NetworkCert(), false)
+               if err != nil {
+                       return response.SmartError(err)
+               }
+               err = client.DeleteClusterMember(name, force == 1)
+               if err != nil {
+                       return response.SmartError(err)
                }
-               return response.SyncResponseRedirect(url.String())
-       }
 
-       force, err := strconv.Atoi(r.FormValue("force"))
-       if err != nil {
-               force = 0
+               return response.EmptySyncResponse
        }
 
-       name := mux.Vars(r)["name"]
        logger.Debugf("Deleting member %s from cluster (force=%d)", name, force)
 
        // First check that the node is clear from containers and images and
diff --git a/test/suites/clustering.sh b/test/suites/clustering.sh
index 8aff5590b6..e855206b6b 100644
--- a/test/suites/clustering.sh
+++ b/test/suites/clustering.sh
@@ -124,8 +124,13 @@ test_clustering_membership() {
   LXD_DIR="${LXD_ONE_DIR}" lxc config set cluster.offline_threshold 12
   LXD_DIR="${LXD_THREE_DIR}" lxd shutdown
   sleep 15
-  LXD_DIR="${LXD_TWO_DIR}" lxc cluster list
-  #| grep "node3" | grep -q "OFFLINE"
+  LXD_DIR="${LXD_TWO_DIR}" lxc cluster list | grep "node3" | grep -q "OFFLINE"
+
+  # Gracefully remove a node.
+  LXD_DIR="${LXD_TWO_DIR}" lxc cluster remove node4
+
+  # The node isn't clustered anymore.
+  ! LXD_DIR="${LXD_FOUR_DIR}" lxc cluster list || false
 
   LXD_DIR="${LXD_FIVE_DIR}" lxd shutdown
   LXD_DIR="${LXD_FOUR_DIR}" lxd shutdown
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to