]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: import needs to sanity check auto-generated image name 14754/head
authorMykola Golub <mgolub@mirantis.com>
Mon, 24 Apr 2017 18:29:36 +0000 (20:29 +0200)
committerMykola Golub <mgolub@mirantis.com>
Mon, 24 Apr 2017 18:29:36 +0000 (20:29 +0200)
Fixes: http://tracker.ceph.com/issues/19128
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
qa/workunits/rbd/cli_generic.sh
src/tools/rbd/action/Import.cc

index e85ae619becfdc94b6ba2e2fd3cc932a03a8f56b..bbf86b66140bb1fdcf44fc1bd915659d60530c7d 100755 (executable)
@@ -290,7 +290,7 @@ test_pool_image_args() {
 
     ceph osd pool delete test test --yes-i-really-really-mean-it || true
     ceph osd pool create test 100
-    truncate -s 1 /tmp/empty
+    truncate -s 1 /tmp/empty /tmp/empty@snap
 
     rbd ls | wc -l | grep 0
     rbd create -s 1 test1
@@ -302,6 +302,12 @@ test_pool_image_args() {
     rbd import /tmp/empty foo
     rbd ls | grep -q foo
 
+    # should fail due to "destination snapname specified"
+    rbd import --dest test/empty@snap /tmp/empty && exit 1 || true
+    rbd import /tmp/empty test/empty@snap && exit 1 || true
+    rbd import --image test/empty@snap /tmp/empty && exit 1 || true
+    rbd import /tmp/empty@snap && exit 1 || true
+
     rbd ls test | wc -l | grep 0
     rbd import /tmp/empty test/test1
     rbd ls test | grep -q test1
@@ -336,7 +342,7 @@ test_pool_image_args() {
     rbd ls | grep test12
     rbd ls test | grep -qv test12
 
-    rm -f /tmp/empty
+    rm -f /tmp/empty /tmp/empty@snap
     ceph osd pool delete test test --yes-i-really-really-mean-it
 
     for f in foo test1 test10 test12 test2 test3 ; do
index 348915dbcced233a78714f67bf4ed88166e73916..5bea7805da7382da7ba3cfeb062d4f00467a8f0e 100644 (file)
@@ -871,15 +871,21 @@ int execute(const po::variables_map &vm) {
 
   std::string deprecated_image_name;
   if (vm.count(at::IMAGE_NAME)) {
-    utils::extract_spec(vm[at::IMAGE_NAME].as<std::string>(),
-                        &deprecated_pool_name, &deprecated_image_name, nullptr,
-                        utils::SPEC_VALIDATION_FULL);
+    deprecated_image_name = vm[at::IMAGE_NAME].as<std::string>();
     std::cerr << "rbd: --image is deprecated for import, use --dest"
               << std::endl;
   } else {
     deprecated_image_name = path.substr(path.find_last_of("/") + 1);
   }
 
+  std::string deprecated_snap_name;
+  r = utils::extract_spec(deprecated_image_name, &deprecated_pool_name,
+                          &deprecated_image_name, &deprecated_snap_name,
+                          utils::SPEC_VALIDATION_FULL);
+  if (r < 0) {
+    return r;
+  }
+
   size_t sparse_size = utils::RBD_DEFAULT_SPARSE_SIZE;
   if (vm.count(at::IMAGE_SPARSE_SIZE)) {
     sparse_size = vm[at::IMAGE_SPARSE_SIZE].as<size_t>();
@@ -888,7 +894,7 @@ int execute(const po::variables_map &vm) {
   size_t arg_index = 1;
   std::string pool_name = deprecated_pool_name;
   std::string image_name;
-  std::string snap_name;
+  std::string snap_name = deprecated_snap_name;
   r = utils::get_pool_image_snapshot_names(
     vm, at::ARGUMENT_MODIFIER_DEST, &arg_index, &pool_name, &image_name,
     &snap_name, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL,