[lxc-devel] [lxd/master] Fix copying container without target

freeekanayaka on Github lxc-bot at linuxcontainers.org
Mon May 14 11:49:39 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 414 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180514/9696ba0e/attachment.bin>
-------------- next part --------------
From 8b57234dcc9a82a95763922b4c4eee82472d6c5c Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Mon, 14 May 2018 11:04:59 +0000
Subject: [PATCH 1/2] Consider a copy to be local only when not clustered

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 client/lxd_containers.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/client/lxd_containers.go b/client/lxd_containers.go
index b0ad0a8d1..e325283c4 100644
--- a/client/lxd_containers.go
+++ b/client/lxd_containers.go
@@ -250,7 +250,7 @@ func (r *ProtocolLXD) CopyContainer(source ContainerServer, container api.Contai
 	}
 
 	// Optimization for the local copy case
-	if r == source && r.clusterTarget == "" {
+	if r == source && !r.IsClustered() {
 		// Local copy source fields
 		req.Source.Type = "copy"
 		req.Source.Source = container.Name

From d858b5d5f36f30ea8c6ced1603f4a285f53dcc46 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Mon, 14 May 2018 11:47:37 +0000
Subject: [PATCH 2/2] Add integration tests

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 test/suites/clustering.sh | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/test/suites/clustering.sh b/test/suites/clustering.sh
index 22fcfc0c6..e3e5b2246 100644
--- a/test/suites/clustering.sh
+++ b/test/suites/clustering.sh
@@ -491,6 +491,46 @@ test_clustering_storage() {
     LXD_DIR="${LXD_ONE_DIR}" lxc image delete testimage
   fi
 
+  # Test migration of zfs/btrfs-based containers
+  if [ "${driver}" = "zfs" ] || [ "${driver}" = "btrfs" ]; then
+    # Launch a container on node2
+    LXD_DIR="${LXD_TWO_DIR}" ensure_import_testimage
+    LXD_DIR="${LXD_ONE_DIR}" lxc launch --target node2 testimage foo
+    LXD_DIR="${LXD_ONE_DIR}" lxc info foo | grep -q "Location: node2"
+
+    # Stop the container and move it to node1
+    LXD_DIR="${LXD_ONE_DIR}" lxc stop foo
+    LXD_DIR="${LXD_TWO_DIR}" lxc move foo bar --target node1
+    LXD_DIR="${LXD_ONE_DIR}" lxc info bar | grep -q "Location: node1"
+
+    # Start and stop the migrated container on node1
+    LXD_DIR="${LXD_TWO_DIR}" lxc start bar
+    LXD_DIR="${LXD_ONE_DIR}" lxc stop bar
+
+    # Rename the container locally on node1
+    LXD_DIR="${LXD_TWO_DIR}" lxc rename bar foo
+    LXD_DIR="${LXD_ONE_DIR}" lxc info foo | grep -q "Location: node1"
+
+    # Copy the container without specifying a target, it will be placed on node2
+    # since it's the one with the least number of containers (0 vs 1)
+    LXD_DIR="${LXD_ONE_DIR}" lxc copy foo bar
+    LXD_DIR="${LXD_ONE_DIR}" lxc info bar | grep -q "Location: node2"
+
+    # Start and stop the copied container on node2
+    LXD_DIR="${LXD_TWO_DIR}" lxc start bar
+    LXD_DIR="${LXD_ONE_DIR}" lxc stop bar
+
+    # Purge the containers
+    LXD_DIR="${LXD_ONE_DIR}" lxc delete bar
+    LXD_DIR="${LXD_ONE_DIR}" lxc delete foo
+
+    # Delete the image too, and remove its volumes since they are not
+    # automatically deleted.
+    fp="$(LXD_DIR="${LXD_ONE_DIR}" lxc image list -c f --format json | jq .[0].fingerprint)"
+    LXD_DIR="${LXD_ONE_DIR}" lxc image delete testimage
+    LXD_DIR="${LXD_ONE_DIR}" lxc storage volume delete data "image/${fp}"
+  fi
+
   # Delete the storage pool
   LXD_DIR="${LXD_ONE_DIR}" lxc storage delete pool1
   ! LXD_DIR="${LXD_ONE_DIR}" lxc storage list | grep -q pool1


More information about the lxc-devel mailing list