[lxc-devel] [lxd/master] [WIP] Check if a ceph volume is on the same node of the target

freeekanayaka on Github lxc-bot at linuxcontainers.org
Fri Oct 26 15:22:50 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 361 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181026/b9bb65b7/attachment.bin>
-------------- next part --------------
From 9f4077f52b442e11b5a9dfda19a2421421aacfb7 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Fri, 26 Oct 2018 17:22:02 +0200
Subject: [PATCH] Check if a ceph volume is on the same node of the target

Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
 lxd/container.go          |  18 ++++-
 test/main.sh              | 144 +++++++++++++++++++-------------------
 test/suites/clustering.sh |  12 +++-
 test/suites/projects.sh   |   4 +-
 4 files changed, 101 insertions(+), 77 deletions(-)

diff --git a/lxd/container.go b/lxd/container.go
index 4eba3930c8..07e588a73f 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -328,7 +328,7 @@ func containerValidConfig(sysOS *sys.OS, config map[string]string, profile bool,
 	return nil
 }
 
-func containerValidDevices(db *db.Cluster, devices types.Devices, profile bool, expanded bool) error {
+func containerValidDevices(cluster *db.Cluster, devices types.Devices, profile bool, expanded bool) error {
 	// Empty device list
 	if devices == nil {
 		return nil
@@ -407,10 +407,24 @@ func containerValidDevices(db *db.Cluster, devices types.Devices, profile bool,
 					return fmt.Errorf("Storage volumes cannot be specified as absolute paths")
 				}
 
-				_, err := db.StoragePoolGetID(m["pool"])
+				poolID, err := cluster.StoragePoolGetID(m["pool"])
 				if err != nil {
 					return fmt.Errorf("The \"%s\" storage pool doesn't exist", m["pool"])
 				}
+				if !profile && expanded {
+					_, pool, err := cluster.StoragePoolGet(m["pool"])
+					if err != nil {
+						return errors.Wrap(err, "Fetch storage pool")
+					}
+					if pool.Driver == "ceph" {
+						// Check that the volume is available on this node.
+						_, err := cluster.StoragePoolNodeVolumeGetTypeID(
+							m["source"], db.StoragePoolVolumeTypeCustom, poolID)
+						if err != nil {
+							return fmt.Errorf("The %q storage volume is not available on this node", m["source"])
+						}
+					}
+				}
 			}
 
 			if m["propagation"] != "" {
diff --git a/test/main.sh b/test/main.sh
index e1f9be3b33..406a1e8f79 100755
--- a/test/main.sh
+++ b/test/main.sh
@@ -155,79 +155,79 @@ if [ "$#" -gt 0 ]; then
 fi
 
 run_test test_check_deps "checking dependencies"
-run_test test_static_analysis "static analysis"
-run_test test_database_update "database schema updates"
-run_test test_database_restore "database restore"
-run_test test_sql "lxd sql"
-run_test test_projects_default "default project"
-run_test test_projects_crud "projects CRUD operations"
-run_test test_projects_containers "containers inside projects"
-run_test test_projects_snapshots "snapshots inside projects"
-run_test test_projects_backups "backups inside projects"
-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_projects_network "projects and networks"
-run_test test_remote_url "remote url handling"
-run_test test_remote_admin "remote administration"
-run_test test_remote_usage "remote usage"
-run_test test_basic_usage "basic usage"
-run_test test_security "security features"
-run_test test_security_protection "container protection"
-run_test test_image_expiry "image expiry"
-run_test test_image_list_all_aliases "image list all aliases"
-run_test test_image_auto_update "image auto-update"
-run_test test_image_prefer_cached "image prefer cached"
-run_test test_image_import_dir "import image from directory"
-run_test test_concurrent_exec "concurrent exec"
-run_test test_concurrent "concurrent startup"
-run_test test_snapshots "container snapshots"
-run_test test_snap_restore "snapshot restores"
-run_test test_config_profiles "profiles and configuration"
-run_test test_config_edit "container configuration edit"
-run_test test_config_edit_container_snapshot_pool_config "container and snapshot volume configuration edit"
-run_test test_container_metadata "manage container metadata and templates"
-run_test test_server_config "server configuration"
-run_test test_filemanip "file manipulations"
-run_test test_network "network management"
-run_test test_idmap "id mapping"
-run_test test_template "file templating"
-run_test test_pki "PKI mode"
-run_test test_devlxd "/dev/lxd"
-run_test test_fuidshift "fuidshift"
-run_test test_migration "migration"
-run_test test_fdleak "fd leak"
-run_test test_storage "storage"
-run_test test_storage_volume_snapshots "storage volume snapshots"
-run_test test_init_auto "lxd init auto"
-run_test test_init_interactive "lxd init interactive"
-run_test test_init_preseed "lxd init preseed"
-run_test test_storage_profiles "storage profiles"
-run_test test_container_import "container import"
-run_test test_storage_volume_attach "attaching storage volumes"
-run_test test_storage_driver_ceph "ceph storage driver"
-run_test test_resources "resources"
-run_test test_kernel_limits "kernel limits"
-run_test test_macaroon_auth "macaroon authentication"
-run_test test_console "console"
-run_test test_query "query"
-run_test test_proxy_device "proxy device"
-run_test test_storage_local_volume_handling "storage local volume handling"
-run_test test_backup_import "backup import"
-run_test test_backup_export "backup export"
-run_test test_container_local_cross_pool_handling "container local cross pool handling"
-run_test test_clustering_enable "clustering enable"
-run_test test_clustering_membership "clustering membership"
-run_test test_clustering_containers "clustering containers"
+# run_test test_static_analysis "static analysis"
+# run_test test_database_update "database schema updates"
+# run_test test_database_restore "database restore"
+# run_test test_sql "lxd sql"
+# run_test test_projects_default "default project"
+# run_test test_projects_crud "projects CRUD operations"
+# run_test test_projects_containers "containers inside projects"
+# run_test test_projects_snapshots "snapshots inside projects"
+# run_test test_projects_backups "backups inside projects"
+# 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_projects_network "projects and networks"
+# run_test test_remote_url "remote url handling"
+# run_test test_remote_admin "remote administration"
+# run_test test_remote_usage "remote usage"
+# run_test test_basic_usage "basic usage"
+# run_test test_security "security features"
+# run_test test_security_protection "container protection"
+# run_test test_image_expiry "image expiry"
+# run_test test_image_list_all_aliases "image list all aliases"
+# run_test test_image_auto_update "image auto-update"
+# run_test test_image_prefer_cached "image prefer cached"
+# run_test test_image_import_dir "import image from directory"
+# run_test test_concurrent_exec "concurrent exec"
+# run_test test_concurrent "concurrent startup"
+# run_test test_snapshots "container snapshots"
+# run_test test_snap_restore "snapshot restores"
+# run_test test_config_profiles "profiles and configuration"
+# run_test test_config_edit "container configuration edit"
+# run_test test_config_edit_container_snapshot_pool_config "container and snapshot volume configuration edit"
+# run_test test_container_metadata "manage container metadata and templates"
+# run_test test_server_config "server configuration"
+# run_test test_filemanip "file manipulations"
+# run_test test_network "network management"
+# run_test test_idmap "id mapping"
+# run_test test_template "file templating"
+# run_test test_pki "PKI mode"
+# run_test test_devlxd "/dev/lxd"
+# run_test test_fuidshift "fuidshift"
+# run_test test_migration "migration"
+# run_test test_fdleak "fd leak"
+# run_test test_storage "storage"
+# run_test test_storage_volume_snapshots "storage volume snapshots"
+# run_test test_init_auto "lxd init auto"
+# run_test test_init_interactive "lxd init interactive"
+# run_test test_init_preseed "lxd init preseed"
+# run_test test_storage_profiles "storage profiles"
+# run_test test_container_import "container import"
+# run_test test_storage_volume_attach "attaching storage volumes"
+# run_test test_storage_driver_ceph "ceph storage driver"
+# run_test test_resources "resources"
+# run_test test_kernel_limits "kernel limits"
+# run_test test_macaroon_auth "macaroon authentication"
+# run_test test_console "console"
+# run_test test_query "query"
+# run_test test_proxy_device "proxy device"
+# run_test test_storage_local_volume_handling "storage local volume handling"
+# run_test test_backup_import "backup import"
+# run_test test_backup_export "backup export"
+# run_test test_container_local_cross_pool_handling "container local cross pool handling"
+# run_test test_clustering_enable "clustering enable"
+# run_test test_clustering_membership "clustering membership"
+# run_test test_clustering_containers "clustering containers"
 run_test test_clustering_storage "clustering storage"
-run_test test_clustering_network "clustering network"
-run_test test_clustering_publish "clustering publish"
-run_test test_clustering_profiles "clustering profiles"
-run_test test_clustering_join_api "clustering join api"
-run_test test_clustering_shutdown_nodes "clustering shutdown"
-run_test test_clustering_projects "clustering projects"
+# run_test test_clustering_network "clustering network"
+# run_test test_clustering_publish "clustering publish"
+# run_test test_clustering_profiles "clustering profiles"
+# run_test test_clustering_join_api "clustering join api"
+# run_test test_clustering_shutdown_nodes "clustering shutdown"
+# run_test test_clustering_projects "clustering projects"
 #run_test test_clustering_upgrade "clustering upgrade"
 
 # shellcheck disable=SC2034
diff --git a/test/suites/clustering.sh b/test/suites/clustering.sh
index c3fb76a1a6..6ec444755f 100644
--- a/test/suites/clustering.sh
+++ b/test/suites/clustering.sh
@@ -447,8 +447,8 @@ test_clustering_storage() {
     ! LXD_DIR="${LXD_ONE_DIR}" lxc storage show pool1 | grep -q rsync.bwlimit
   fi
 
-  # Test migration of ceph-based containers
   if [ "${driver}" = "ceph" ]; then
+    # Test migration of ceph-based containers
     LXD_DIR="${LXD_TWO_DIR}" ensure_import_testimage
     LXD_DIR="${LXD_ONE_DIR}" lxc launch --target node2 -s pool1 testimage foo
 
@@ -504,6 +504,16 @@ test_clustering_storage() {
     LXD_DIR="${LXD_ONE_DIR}" lxc cluster remove node3 --force
 
     LXD_DIR="${LXD_ONE_DIR}" lxc delete bar
+
+    # Test attaching custom volumes
+    LXD_DIR="${LXD_ONE_DIR}" lxc storage volume create pool1 v1
+    LXD_DIR="${LXD_ONE_DIR}" lxd sql global .dump
+    LXD_DIR="${LXD_ONE_DIR}" lxc init --target node1 -s pool1 testimage baz
+    LXD_DIR="${LXD_ONE_DIR}" lxc storage volume attach pool1 custom/v1 baz testDevice /opt
+    LXD_DIR="${LXD_ONE_DIR}" lxc storage volume detach pool1 v1 baz
+    LXD_DIR="${LXD_ONE_DIR}" lxc storage volume delete pool1 v1
+    LXD_DIR="${LXD_ONE_DIR}" lxc delete baz
+
     LXD_DIR="${LXD_ONE_DIR}" lxc image delete testimage
   fi
 
diff --git a/test/suites/projects.sh b/test/suites/projects.sh
index 83de0547e7..dc9aed7895 100644
--- a/test/suites/projects.sh
+++ b/test/suites/projects.sh
@@ -68,7 +68,8 @@ test_projects_containers() {
   fingerprint="$(lxc image list -c f --format json | jq -r .[0].fingerprint)"
 
   # Add a root device to the default profile of the project
-  lxc profile device add default root disk path="/" pool="lxdtest-$(basename "${LXD_DIR}")"
+  pool="lxdtest-$(basename "${LXD_DIR}")"
+  lxc profile device add default root disk path="/" pool="${pool}"
 
   # Create a container in the project
   lxc init testimage c1
@@ -78,7 +79,6 @@ test_projects_containers() {
   lxc info c1 | grep -q "Name: c1"
 
   # The container's volume is listed too.
-  pool="lxdtest-$(basename "${LXD_DIR}")"
   lxc storage volume list "${pool}" | grep -q c1
 
   # For backends with optimized storage, we can see the image volume inside the


More information about the lxc-devel mailing list