[lxc-devel] [lxd/master] Make custom volumes visible from non-default projects
freeekanayaka on Github
lxc-bot at linuxcontainers.org
Fri Oct 12 10:54:41 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 377 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181012/6c0ab784/attachment.bin>
-------------- next part --------------
From 4ecedb87df3b9c39c66c6bdc02a6e35343c84070 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Fri, 12 Oct 2018 12:45:25 +0200
Subject: [PATCH] Make custom volumes visible from non-default projects
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_pools.go | 14 ++++++++++----
test/main.sh | 1 +
test/suites/projects.sh | 18 ++++++++++++++++++
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/lxd/db/storage_pools.go b/lxd/db/storage_pools.go
index 1cbaf1ca92..adbe123c64 100644
--- a/lxd/db/storage_pools.go
+++ b/lxd/db/storage_pools.go
@@ -696,8 +696,8 @@ func (c *Cluster) StoragePoolVolumesGet(project string, poolID int64, volumeType
SELECT DISTINCT node_id
FROM storage_volumes
JOIN projects ON projects.id = storage_volumes.project_id
- WHERE projects.name=? AND storage_pool_id=?
-`, project, poolID)
+ WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=?
+`, project, StoragePoolVolumeTypeCustom, poolID)
return err
})
if err != nil {
@@ -756,9 +756,9 @@ func (c *Cluster) StoragePoolVolumesGetType(project string, volumeType int, pool
SELECT storage_volumes.name
FROM storage_volumes
JOIN projects ON projects.id=storage_volumes.project_id
- WHERE projects.name=? AND storage_pool_id=? AND node_id=? AND type=?
+ WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=? AND node_id=? AND type=?
`
- inargs := []interface{}{project, poolID, nodeID, volumeType}
+ inargs := []interface{}{project, StoragePoolVolumeTypeCustom, poolID, nodeID, volumeType}
outargs := []interface{}{poolName}
result, err := queryScan(c.db, query, inargs, outargs)
@@ -806,6 +806,12 @@ func (c *Cluster) StoragePoolNodeVolumesGetType(volumeType int, poolID int64) ([
// StoragePoolVolumeGetType returns a single storage volume attached to a
// given storage pool of a given type, on the node with the given ID.
func (c *Cluster) StoragePoolVolumeGetType(project string, volumeName string, volumeType int, poolID, nodeID int64) (int64, *api.StorageVolume, error) {
+ // Custom volumes are "global", i.e. they are associated with the
+ // default project.
+ if volumeType == StoragePoolVolumeTypeCustom {
+ project = "default"
+ }
+
volumeID, err := c.StoragePoolVolumeGetTypeID(project, volumeName, volumeType, poolID, nodeID)
if err != nil {
return -1, nil, err
diff --git a/test/main.sh b/test/main.sh
index 1fbf5d085a..e63417deb0 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -168,6 +168,7 @@ run_test test_projects_profiles "profiles inside projects"
run_test test_projects_profiles_default "profiles from the global default project"
run_test test_projects_images "images inside projects"
run_test test_projects_images_default "images from the global default project"
+run_test test_projects_storage "projects and storage pools"
run_test test_remote_url "remote url handling"
run_test test_remote_admin "remote administration"
run_test test_remote_usage "remote usage"
diff --git a/test/suites/projects.sh b/test/suites/projects.sh
index 5df27872f9..28901a7701 100644
--- a/test/suites/projects.sh
+++ b/test/suites/projects.sh
@@ -347,3 +347,21 @@ test_projects_images_default() {
lxc project delete foo
}
+
+# Interaction between projects and storage pools.
+test_projects_storage() {
+ pool="lxdtest-$(basename "${LXD_DIR}")"
+
+ lxc storage volume create "${pool}" vol
+
+ lxc project create foo
+ lxc project switch foo
+
+ lxc storage volume list "${pool}" | grep custom | grep -q vol
+
+ lxc storage volume delete "${pool}" vol
+
+ lxc project switch default
+
+ ! lxc storage volume list "${pool}" | grep -q custom
+}
More information about the lxc-devel
mailing list