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

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) ===
Fixes https://github.com/lxc/lxd/issues/8273

Adds test for this scenario.
From 954eadfa158f37860127f06422658a6d73ced0a0 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Fri, 18 Dec 2020 14:02:06 +0000
Subject: [PATCH 1/5] lxd/instances/post: Use source.Project when loading
 instance to get instance type in containersPost

Fixes #8273

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/instances_post.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/instances_post.go b/lxd/instances_post.go
index 92047db448..e10f4d79e1 100644
--- a/lxd/instances_post.go
+++ b/lxd/instances_post.go
@@ -838,7 +838,7 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
                                        return fmt.Errorf("Must specify a 
source instance")
                                }
 
-                               source, err := 
instance.LoadInstanceDatabaseObject(tx, project, req.Source.Source)
+                               source, err := 
instance.LoadInstanceDatabaseObject(tx, req.Source.Project, req.Source.Source)
                                if err != nil {
                                        return errors.Wrap(err, "Load source 
instance from database")
                                }

From 48df8c87eef5e4e106d1f8f740464773541d9233 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Fri, 18 Dec 2020 14:06:24 +0000
Subject: [PATCH 2/5] lxd/instances/post: Rename project to targetProject to
 differentiate between source.Project in containersPost

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/instances_post.go | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/lxd/instances_post.go b/lxd/instances_post.go
index e10f4d79e1..edc32e78ba 100644
--- a/lxd/instances_post.go
+++ b/lxd/instances_post.go
@@ -722,12 +722,12 @@ func createFromBackup(d *Daemon, projectName string, data 
io.Reader, pool string
 }
 
 func containersPost(d *Daemon, r *http.Request) response.Response {
-       project := projectParam(r)
+       targetProject := projectParam(r)
        logger.Debugf("Responding to instance create")
 
        // If we're getting binary content, process separately
        if r.Header.Get("Content-Type") == "application/octet-stream" {
-               return createFromBackup(d, project, r.Body, 
r.Header.Get("X-LXD-pool"), r.Header.Get("X-LXD-name"))
+               return createFromBackup(d, targetProject, r.Body, 
r.Header.Get("X-LXD-pool"), r.Header.Get("X-LXD-name"))
        }
 
        // Parse the request
@@ -754,7 +754,7 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
                // the selected node is the local one, this is effectively a
                // no-op, since GetNodeWithLeastInstances() will return an empty
                // string.
-               architectures, err := instance.SuitableArchitectures(d.State(), 
project, req)
+               architectures, err := instance.SuitableArchitectures(d.State(), 
targetProject, req)
                if err != nil {
                        return response.BadRequest(err)
                }
@@ -780,7 +780,7 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
                                return response.SmartError(err)
                        }
 
-                       client = client.UseProject(project)
+                       client = client.UseProject(targetProject)
                        client = client.UseTarget(targetNode)
 
                        logger.Debugf("Forward instance post request to %s", 
address)
@@ -790,7 +790,7 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
                        }
 
                        opAPI := op.Get()
-                       return operations.ForwardedOperationResponse(project, 
&opAPI)
+                       return 
operations.ForwardedOperationResponse(targetProject, &opAPI)
                }
        }
 
@@ -849,13 +849,13 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
                        }
                }
 
-               err := projecthelpers.AllowInstanceCreation(tx, project, req)
+               err := projecthelpers.AllowInstanceCreation(tx, targetProject, 
req)
                if err != nil {
                        return err
                }
 
                if req.Name == "" {
-                       names, err := tx.GetInstanceNames(project)
+                       names, err := tx.GetInstanceNames(targetProject)
                        if err != nil {
                                return err
                        }
@@ -883,13 +883,13 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
 
        switch req.Source.Type {
        case "image":
-               return createFromImage(d, project, &req)
+               return createFromImage(d, targetProject, &req)
        case "none":
-               return createFromNone(d, project, &req)
+               return createFromNone(d, targetProject, &req)
        case "migration":
-               return createFromMigration(d, project, &req)
+               return createFromMigration(d, targetProject, &req)
        case "copy":
-               return createFromCopy(d, project, &req)
+               return createFromCopy(d, targetProject, &req)
        default:
                return response.BadRequest(fmt.Errorf("Unknown source type %s", 
req.Source.Type))
        }

From dc934a91e4315f2a7a2c9affce19d51f4c8611b1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Fri, 18 Dec 2020 14:06:50 +0000
Subject: [PATCH 3/5] lxd/instances/post: Error quoting in containersPost

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/instances_post.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/instances_post.go b/lxd/instances_post.go
index edc32e78ba..5d8d0494c7 100644
--- a/lxd/instances_post.go
+++ b/lxd/instances_post.go
@@ -822,7 +822,7 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
        }
 
        if strings.Contains(req.Name, shared.SnapshotDelimiter) {
-               return response.BadRequest(fmt.Errorf("Invalid instance name: 
'%s' is reserved for snapshots", shared.SnapshotDelimiter))
+               return response.BadRequest(fmt.Errorf("Invalid instance name: 
%q is reserved for snapshots", shared.SnapshotDelimiter))
        }
 
        // Check that the project's limits are not violated. Also, possibly

From 2cc26d7eb34429ee0486c1fbac99cbe6447a192d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Fri, 18 Dec 2020 14:16:49 +0000
Subject: [PATCH 4/5] lxd/instances/post: Add comment about default instance
 type for migration in containersPost

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/instances_post.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/instances_post.go b/lxd/instances_post.go
index 5d8d0494c7..54bf6c88ea 100644
--- a/lxd/instances_post.go
+++ b/lxd/instances_post.go
@@ -845,7 +845,7 @@ func containersPost(d *Daemon, r *http.Request) 
response.Response {
 
                                req.Type = 
api.InstanceType(source.Type.String())
                        case "migration":
-                               req.Type = api.InstanceTypeContainer
+                               req.Type = api.InstanceTypeContainer // Default 
to container if not specified.
                        }
                }
 

From 0fe49e76e33f632fce66e39d92dc01ccff0c1b6c Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Fri, 18 Dec 2020 14:26:13 +0000
Subject: [PATCH 5/5] test/suites/projects: Adds tests for copying snapshot to
 another project

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 test/suites/projects.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/test/suites/projects.sh b/test/suites/projects.sh
index 5b676ba6bb..7be7499049 100644
--- a/test/suites/projects.sh
+++ b/test/suites/projects.sh
@@ -153,6 +153,10 @@ test_projects_copy() {
   lxc --project foo snapshot c1
   lxc --project foo snapshot c1
 
+  lxc --project foo copy c1/snap0 c1 --target-project bar
+  lxc --project bar start c1
+  lxc --project bar delete c1 -f
+
   lxc --project foo copy c1 c1 --target-project bar
   lxc --project foo start c1
   lxc --project bar start c1
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to