The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/4978
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) ===
From e4b1a8f8156090fe1d554410f630b0e34d54cb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <[email protected]> Date: Sun, 26 Aug 2018 19:38:50 -0400 Subject: [PATCH 1/2] tests: Avoid err == nil pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber <[email protected]> --- test/deps/devlxd-client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/deps/devlxd-client.go b/test/deps/devlxd-client.go index 49ad9382c6..2cf6e71784 100644 --- a/test/deps/devlxd-client.go +++ b/test/deps/devlxd-client.go @@ -82,10 +82,11 @@ func main() { if raw.StatusCode != http.StatusOK { fmt.Println("http error", raw.StatusCode) result, err := ioutil.ReadAll(raw.Body) - if err == nil { - fmt.Println(string(result)) + if err != nil { + os.Exit(1) } - os.Exit(1) + + fmt.Println(string(result)) } result := []string{} From 9d52f385ac765a24f3f94bfb9912d539d2633059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <[email protected]> Date: Sun, 26 Aug 2018 20:10:28 -0400 Subject: [PATCH 2/2] lxd: Don't mask database errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4976 Signed-off-by: Stéphane Graber <[email protected]> --- lxd/api_cluster.go | 6 +++++- lxd/db/images.go | 1 - lxd/images.go | 18 +++++++++++++++--- lxd/storage_volumes.go | 8 +++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go index 1c5da1b6af..785100ea4a 100644 --- a/lxd/api_cluster.go +++ b/lxd/api_cluster.go @@ -356,7 +356,11 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) Response { // Remove the our old server certificate from the trust store, // since it's not needed anymore. _, err = d.cluster.CertificateGet(fingerprint) - if err == nil { + if err != db.ErrNoSuchObject { + if err != nil { + return err + } + err := d.cluster.CertDelete(fingerprint) if err != nil { return errors.Wrap(err, "failed to delete joining node's certificate") diff --git a/lxd/db/images.go b/lxd/db/images.go index 17c066cc7f..e020f453ff 100644 --- a/lxd/db/images.go +++ b/lxd/db/images.go @@ -548,7 +548,6 @@ func (c *Cluster) ImageInsert(fp string, fname string, sz int64, public bool, au } err = c.Transaction(func(tx *ClusterTx) error { - publicInt := 0 if public { publicInt = 1 diff --git a/lxd/images.go b/lxd/images.go index 3b715382d6..6ca4457145 100644 --- a/lxd/images.go +++ b/lxd/images.go @@ -246,7 +246,11 @@ func imgPostContInfo(d *Daemon, r *http.Request, req api.ImagesPost, builddir st info.Fingerprint = fmt.Sprintf("%x", sha256.Sum(nil)) _, _, err = d.cluster.ImageGet(info.Fingerprint, false, true) - if err == nil { + if err != db.ErrNoSuchObject { + if err != nil { + return nil, err + } + return nil, fmt.Errorf("The image already exists: %s", info.Fingerprint) } @@ -709,7 +713,11 @@ func imagesPost(d *Daemon, r *http.Request) Response { // Apply any provided alias for _, alias := range req.Aliases { _, _, err := d.cluster.ImageAliasGet(alias.Name, true) - if err == nil { + if err != db.ErrNoSuchObject { + if err != nil { + return err + } + return fmt.Errorf("Alias already exists: %s", alias.Name) } @@ -1462,7 +1470,11 @@ func aliasesPost(d *Daemon, r *http.Request) Response { // This is just to see if the alias name already exists. _, _, err := d.cluster.ImageAliasGet(req.Name, true) - if err == nil { + if err != db.ErrNoSuchObject { + if err != nil { + return InternalError(err) + } + return Conflict(fmt.Errorf("Alias '%s' already exists", req.Name)) } diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go index 9ee0392fde..c08fdaa8c6 100644 --- a/lxd/storage_volumes.go +++ b/lxd/storage_volumes.go @@ -485,10 +485,12 @@ func storagePoolVolumeTypePost(d *Daemon, r *http.Request) Response { // Check that the name isn't already in use. _, err = d.cluster.StoragePoolNodeVolumeGetTypeID(req.Name, storagePoolVolumeTypeCustom, poolID) - if err == nil { + if err != db.ErrNoSuchObject { + if err != nil { + return InternalError(err) + } + return Conflict(fmt.Errorf("Name '%s' already in use", req.Name)) - } else if err != nil && err != db.ErrNoSuchObject { - return Conflict(err) } doWork := func() error {
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
