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

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) ===
This bug was effectively preventing from creating two storage pools in the same clusters, under certain circumstances (e.g. a zfs pool and a ceph pool).

Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com>
From ecde85ec27f683a2ad2f1ea5752efad71dc6e03b Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanay...@canonical.com>
Date: Thu, 5 Apr 2018 07:47:40 +0000
Subject: [PATCH] Properly filter node-level storage configs by pool ID

Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com>
---
 lxd/db/storage_pools.go      |  3 ++-
 lxd/db/storage_pools_test.go | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/lxd/db/storage_pools.go b/lxd/db/storage_pools.go
index 91e5192680..00f5160e8d 100644
--- a/lxd/db/storage_pools.go
+++ b/lxd/db/storage_pools.go
@@ -332,7 +332,8 @@ WHERE storage_pools.id = ? AND storage_pools.state = ?
 
        configs := map[string]map[string]string{}
        for _, node := range nodes {
-               config, err := query.SelectConfig(c.tx, "storage_pools_config", 
"node_id=?", node.ID)
+               config, err := query.SelectConfig(
+                       c.tx, "storage_pools_config", "storage_pool_id=? AND 
node_id=?", poolID, node.ID)
                if err != nil {
                        return nil, err
                }
diff --git a/lxd/db/storage_pools_test.go b/lxd/db/storage_pools_test.go
index 523a014cff..11e503f084 100644
--- a/lxd/db/storage_pools_test.go
+++ b/lxd/db/storage_pools_test.go
@@ -46,6 +46,44 @@ func TestStoragePoolsCreatePending(t *testing.T) {
        assert.Equal(t, map[string]string{"source": "/egg"}, configs["none"])
 }
 
+func TestStoragePoolsCreatePending_OtherPool(t *testing.T) {
+       tx, cleanup := db.NewTestClusterTx(t)
+       defer cleanup()
+
+       // Create a pending pool named 'pool1' on two nodes (the default 'none'
+       // and 'buzz')
+       _, err := tx.NodeAdd("buzz", "1.2.3.4:666")
+       require.NoError(t, err)
+
+       config := map[string]string{"source": "/foo"}
+       err = tx.StoragePoolCreatePending("none", "pool1", "dir", config)
+       require.NoError(t, err)
+
+       config = map[string]string{"source": "/bar"}
+       err = tx.StoragePoolCreatePending("buzz", "pool1", "dir", config)
+       require.NoError(t, err)
+
+       // Create a second pending pool named pool2 on the same two nodes.
+       config = map[string]string{}
+       err = tx.StoragePoolCreatePending("none", "pool2", "dir", config)
+       require.NoError(t, err)
+
+       poolID, err := tx.StoragePoolID("pool2")
+       require.NoError(t, err)
+
+       config = map[string]string{}
+       err = tx.StoragePoolCreatePending("buzz", "pool2", "dir", config)
+       require.NoError(t, err)
+
+       // The node-level configs of the second pool do not contain any key
+       // from the first pool.
+       configs, err := tx.StoragePoolNodeConfigs(poolID)
+       require.NoError(t, err)
+       assert.Len(t, configs, 2)
+       assert.Equal(t, map[string]string{}, configs["none"])
+       assert.Equal(t, map[string]string{}, configs["buzz"])
+}
+
 // If an entry for the given pool and node already exists, an error is
 // returned.
 func TestStoragePoolsCreatePending_AlreadyDefined(t *testing.T) {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to