The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3246
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) === Signed-off-by: Christian Brauner <[email protected]>
From 129fc5520ae968a5c94e68844b24ad17fce1e07c Mon Sep 17 00:00:00 2001 From: Christian Brauner <[email protected]> Date: Fri, 28 Apr 2017 11:23:13 +0200 Subject: [PATCH] lxc {copy,move}: improve error handling Signed-off-by: Christian Brauner <[email protected]> --- lxc/copy.go | 27 ++++++++++++++++++--------- lxc/move.go | 12 ++++++++++-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lxc/copy.go b/lxc/copy.go index d2ebf4e..95127c6 100644 --- a/lxc/copy.go +++ b/lxc/copy.go @@ -216,17 +216,20 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR if err != nil { msg[senderid] = err ch <- msg + return } msg[senderid] = nil ch <- msg } + + var migrationErrFromClient error for _, addr := range addresses { var migration *api.Response sourceWSUrl := "https://" + addr + sourceWSResponse.Operation - migration, err = dest.MigrateFrom(destName, sourceWSUrl, source.Certificate, secrets, status.Architecture, status.Config, status.Devices, status.Profiles, baseImage, ephemeral == 1, false, source, sourceWSResponse.Operation, containerOnly) - if err != nil { + migration, migrationErrFromClient = dest.MigrateFrom(destName, sourceWSUrl, source.Certificate, secrets, status.Architecture, status.Config, status.Devices, status.Profiles, baseImage, ephemeral == 1, false, source, sourceWSResponse.Operation, containerOnly) + if migrationErrFromClient != nil { continue } @@ -238,18 +241,24 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR sourceOpId := 1 go wait(source, sourceWSResponse.Operation, waitchan, sourceOpId) - opStatus := make([]map[int]error, 2) + var sourceOpErr error + var destOpErr error for i := 0; i < cap(waitchan); i++ { - opStatus[i] = <-waitchan + tmp := <-waitchan + err, ok := tmp[sourceOpId] + if ok { + sourceOpErr = err + } else { + destOpErr = err + } } - if opStatus[0][destOpId] != nil { + if destOpErr != nil { continue } - err = opStatus[1][sourceOpId] - if err != nil { - return err + if sourceOpErr != nil { + return sourceOpErr } if destResource == "" { @@ -277,7 +286,7 @@ func (c *copyCmd) copyContainer(config *lxd.Config, sourceResource string, destR } // Return the error from destination - return fmt.Errorf(i18n.G("Migration failed on target host: %s"), err) + return fmt.Errorf(i18n.G("Migration failed on target host: %s"), migrationErrFromClient) } func (c *copyCmd) run(config *lxd.Config, args []string) error { diff --git a/lxc/move.go b/lxc/move.go index 9f7d258..56834a8 100644 --- a/lxc/move.go +++ b/lxc/move.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/lxc/lxd" "github.com/lxc/lxd/shared/i18n" @@ -66,9 +67,16 @@ func (c *moveCmd) run(config *lxd.Config, args []string) error { // A move is just a copy followed by a delete; however, we want to // keep the volatile entries around since we are moving the container. - if err := cpy.copyContainer(config, args[0], args[1], true, -1, true, c.containerOnly); err != nil { + err := cpy.copyContainer(config, args[0], args[1], true, -1, true, c.containerOnly) + if err != nil { return err } - return commands["delete"].run(config, args[:1]) + err = commands["delete"].run(config, args[:1]) + if err != nil { + fmt.Println("asdf") + return err + } + + return nil }
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
