[lxc-devel] [lxd/stable-4.0] Network: Don't apply update changes to node when network is pending

tomponline on Github lxc-bot at linuxcontainers.org
Thu Dec 17 09:33:36 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 550 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201217/b6b38a34/attachment-0001.bin>
-------------- next part --------------
From ae88adbb97e31c12e6b5ac569ffe539372c3229c Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 17 Dec 2020 09:23:21 +0000
Subject: [PATCH 1/2] lxd/networks: Prevent re-create attempts on errored
 networks

This is because the stable-4.0 branch does not have per-node state and so we cannot track which nodes have been successfully setup and which are still pending.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/networks.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lxd/networks.go b/lxd/networks.go
index 03acf7aac3..cdf15b2386 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -203,6 +203,12 @@ func networksPost(d *Daemon, r *http.Request) response.Response {
 		return response.InternalError(err)
 	}
 
+	// If the network has previously had a create attempt that failed, then because we cannot track per-node
+	// status, we need to prevent any further create attempts and require the user to delete and re-create.
+	if netInfo != nil && netInfo.Status == api.NetworkStatusErrored {
+		return response.BadRequest(fmt.Errorf("Network is in errored state, please delete and re-create"))
+	}
+
 	// Check if we're clustered.
 	count, err := cluster.Count(d.State())
 	if err != nil {

From 642de5bf4f34b888f44f762f88a16cfeb8419ba2 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Thu, 17 Dec 2020 09:25:43 +0000
Subject: [PATCH 2/2] lxd/network/driver/bridge: Don't apply updates to node
 when network is pending

If no network create attempt has been attempted then we should just update the DB and await the global create attempt.

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/network/driver_bridge.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lxd/network/driver_bridge.go b/lxd/network/driver_bridge.go
index 74d3e107e3..c55644cced 100644
--- a/lxd/network/driver_bridge.go
+++ b/lxd/network/driver_bridge.go
@@ -1497,8 +1497,10 @@ func (n *bridge) Update(newNetwork api.NetworkPut, targetNode string, clientType
 		return nil // Nothing changed.
 	}
 
-	if n.LocalStatus() == api.NetworkStatusPending {
-		// Apply DB change to local node only.
+	// If the network as a whole has not had any previous creation attempts, or the node itself is still
+	// pending, then don't apply the new settings to the node, just to the database record (ready for the
+	// actual global create request to be initiated).
+	if n.Status() == api.NetworkStatusPending || n.LocalStatus() == api.NetworkStatusPending {
 		return n.common.update(newNetwork, targetNode, clientType)
 	}
 


More information about the lxc-devel mailing list