[lxc-devel] [lxd/master] Make container copy more robust

stgraber on Github lxc-bot at linuxcontainers.org
Fri Nov 25 02:07:33 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161125/35858929/attachment.bin>
-------------- next part --------------
From 47786aaded478582a17f4e6dae898b070307fc9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 24 Nov 2016 20:53:25 -0500
Subject: [PATCH] Make container copy more robust
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2640

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 client.go              | 10 ++++++----
 lxc/copy.go            |  8 ++++----
 lxd/containers_post.go |  3 +++
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/client.go b/client.go
index 6388fdb..1f036e9 100644
--- a/client.go
+++ b/client.go
@@ -352,14 +352,16 @@ func NewClientFromInfo(info ConnectInfo) (*Client, error) {
 func (c *Client) Addresses() ([]string, error) {
 	addresses := make([]string, 0)
 
+	serverStatus, err := c.ServerStatus()
+	if err != nil {
+		return nil, err
+	}
+
 	if c.Transport == "unix" {
-		serverStatus, err := c.ServerStatus()
-		if err != nil {
-			return nil, err
-		}
 		addresses = serverStatus.Environment.Addresses
 	} else if c.Transport == "https" {
 		addresses = append(addresses, c.BaseURL[8:])
+		addresses = append(addresses, serverStatus.Environment.Addresses...)
 	} else {
 		return nil, fmt.Errorf("unknown transport type: %s", c.Transport)
 	}
diff --git a/lxc/copy.go b/lxc/copy.go
index ca69b62..2e1f318 100644
--- a/lxc/copy.go
+++ b/lxc/copy.go
@@ -215,14 +215,14 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR
 			continue
 		}
 
-		if err := source.WaitForSuccess(sourceWSResponse.Operation); err != nil {
-			return err
-		}
-
 		// If push mode is implemented then MigrateFrom will return a
 		// non-waitable operation. So this needs to be conditionalized
 		// on pull mode.
 		if err = dest.WaitForSuccess(migration.Operation); err != nil {
+			continue
+		}
+
+		if err = source.WaitForSuccess(sourceWSResponse.Operation); err != nil {
 			return err
 		}
 
diff --git a/lxd/containers_post.go b/lxd/containers_post.go
index 6f844e1..21e6742 100644
--- a/lxd/containers_post.go
+++ b/lxd/containers_post.go
@@ -255,11 +255,13 @@ func createFromMigration(d *Daemon, req *containerPostReq) Response {
 	if req.Source.Certificate != "" {
 		certBlock, _ := pem.Decode([]byte(req.Source.Certificate))
 		if certBlock == nil {
+			c.Delete()
 			return InternalError(fmt.Errorf("Invalid certificate"))
 		}
 
 		cert, err = x509.ParseCertificate(certBlock.Bytes)
 		if err != nil {
+			c.Delete()
 			return InternalError(err)
 		}
 	}
@@ -303,6 +305,7 @@ func createFromMigration(d *Daemon, req *containerPostReq) Response {
 
 		err = c.TemplateApply("copy")
 		if err != nil {
+			c.Delete()
 			return err
 		}
 


More information about the lxc-devel mailing list