]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: API: options on image create: update tests 6369/head
authorMykola Golub <mgolub@mirantis.com>
Fri, 23 Oct 2015 14:27:33 +0000 (17:27 +0300)
committerMykola Golub <mgolub@mirantis.com>
Thu, 12 Nov 2015 19:43:49 +0000 (21:43 +0200)
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/test/librbd/test_internal.cc
src/test/librbd/test_librbd.cc
src/test/pybind/test_rbd.py

index 805a86c15f469fb1c389a92ac0c09f7571f2a20e..19ed009fc94ea7b5bd433b272360eef883530013 100644 (file)
@@ -672,3 +672,70 @@ TEST_F(TestInternal, ShrinkFlushesCache) {
   ASSERT_EQ(0, cond_ctx.wait());
   c->put();
 }
+
+TEST_F(TestInternal, ImageOptions) {
+  rbd_image_options_t opts1 = NULL, opts2 = NULL;
+  uint64_t uint64_val1 = 10, uint64_val2 = 0;
+  std::string string_val1;
+
+  librbd::image_options_create(&opts1);
+  ASSERT_NE((rbd_image_options_t)NULL, opts1);
+  ASSERT_TRUE(librbd::image_options_is_empty(opts1));
+
+  ASSERT_EQ(-EINVAL, librbd::image_options_get(opts1, RBD_IMAGE_OPTION_FEATURES,
+         &string_val1));
+  ASSERT_EQ(-ENOENT, librbd::image_options_get(opts1, RBD_IMAGE_OPTION_FEATURES,
+         &uint64_val1));
+
+  ASSERT_EQ(-EINVAL, librbd::image_options_set(opts1, RBD_IMAGE_OPTION_FEATURES,
+         string_val1));
+
+  ASSERT_EQ(0, librbd::image_options_set(opts1, RBD_IMAGE_OPTION_FEATURES,
+         uint64_val1));
+  ASSERT_FALSE(librbd::image_options_is_empty(opts1));
+  ASSERT_EQ(0, librbd::image_options_get(opts1, RBD_IMAGE_OPTION_FEATURES,
+         &uint64_val2));
+  ASSERT_EQ(uint64_val1, uint64_val2);
+
+  librbd::image_options_create_ref(&opts2, opts1);
+  ASSERT_NE((rbd_image_options_t)NULL, opts2);
+  ASSERT_FALSE(librbd::image_options_is_empty(opts2));
+
+  uint64_val2 = 0;
+  ASSERT_NE(uint64_val1, uint64_val2);
+  ASSERT_EQ(0, librbd::image_options_get(opts2, RBD_IMAGE_OPTION_FEATURES,
+         &uint64_val2));
+  ASSERT_EQ(uint64_val1, uint64_val2);
+
+  uint64_val2++;
+  ASSERT_NE(uint64_val1, uint64_val2);
+  ASSERT_EQ(-ENOENT, librbd::image_options_get(opts1, RBD_IMAGE_OPTION_ORDER,
+         &uint64_val1));
+  ASSERT_EQ(-ENOENT, librbd::image_options_get(opts2, RBD_IMAGE_OPTION_ORDER,
+         &uint64_val2));
+  ASSERT_EQ(0, librbd::image_options_set(opts2, RBD_IMAGE_OPTION_ORDER,
+         uint64_val2));
+  ASSERT_EQ(0, librbd::image_options_get(opts1, RBD_IMAGE_OPTION_ORDER,
+         &uint64_val1));
+  ASSERT_EQ(0, librbd::image_options_get(opts2, RBD_IMAGE_OPTION_ORDER,
+         &uint64_val2));
+  ASSERT_EQ(uint64_val1, uint64_val2);
+
+  librbd::image_options_destroy(opts1);
+
+  uint64_val2++;
+  ASSERT_NE(uint64_val1, uint64_val2);
+  ASSERT_EQ(0, librbd::image_options_get(opts2, RBD_IMAGE_OPTION_ORDER,
+         &uint64_val2));
+  ASSERT_EQ(uint64_val1, uint64_val2);
+
+  ASSERT_EQ(0, librbd::image_options_unset(opts2, RBD_IMAGE_OPTION_ORDER));
+  ASSERT_EQ(-ENOENT, librbd::image_options_unset(opts2, RBD_IMAGE_OPTION_ORDER));
+
+  librbd::image_options_clear(opts2);
+  ASSERT_EQ(-ENOENT, librbd::image_options_get(opts2, RBD_IMAGE_OPTION_FEATURES,
+         &uint64_val2));
+  ASSERT_TRUE(librbd::image_options_is_empty(opts2));
+
+  librbd::image_options_destroy(opts2);
+}
index ac5d1cbb98fbd435865a84d931b02bce55935288..c5b6c0b2ddcb7087a0c6699704728fbe2be4f792 100644 (file)
@@ -3306,3 +3306,127 @@ TEST_F(TestLibRBD, CacheMayCopyOnWrite) {
   ASSERT_EQ(1024, clone.read(offset + 2048, 1024, read_bl));
   ASSERT_TRUE(expect_bl.contents_equal(read_bl));
 }
+
+TEST_F(TestLibRBD, TestImageOptions)
+{
+  rados_ioctx_t ioctx;
+  rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx);
+
+  //make create image options
+  uint64_t features = RBD_FEATURE_LAYERING | RBD_FEATURE_STRIPINGV2 ;
+  uint64_t order = 0;
+  uint64_t stripe_unit = 65536;
+  uint64_t stripe_count = 16;
+  rbd_image_options_t opts;
+  rbd_image_options_create(&opts);
+  ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FORMAT,
+         2));
+  ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FEATURES,
+         features));
+  ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_ORDER,
+         order));
+  ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_STRIPE_UNIT,
+         stripe_unit));
+  ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_STRIPE_COUNT,
+         stripe_count));
+
+  std::string parent_name = get_temp_image_name();
+
+  // make parent
+  ASSERT_EQ(0, rbd_create4(ioctx, parent_name.c_str(), 4<<20, opts));
+
+  // check order is returned in opts
+  ASSERT_EQ(0, rbd_image_options_get_uint64(opts, RBD_IMAGE_OPTION_ORDER,
+         &order));
+  ASSERT_NE((uint64_t)0, order);
+
+  // write some data to parent
+  rbd_image_t parent;
+  ASSERT_EQ(0, rbd_open(ioctx, parent_name.c_str(), &parent, NULL));
+  char *data = (char *)"testdata";
+  ASSERT_EQ((ssize_t)strlen(data), rbd_write(parent, 0, strlen(data), data));
+  ASSERT_EQ((ssize_t)strlen(data), rbd_write(parent, 12, strlen(data), data));
+
+  // create a snapshot, reopen as the parent we're interested in
+  ASSERT_EQ(0, rbd_snap_create(parent, "parent_snap"));
+  ASSERT_EQ(0, rbd_close(parent));
+  ASSERT_EQ(0, rbd_open(ioctx, parent_name.c_str(), &parent, "parent_snap"));
+
+  // clone
+  std::string child_name = get_temp_image_name();
+  ASSERT_EQ(0, rbd_snap_protect(parent, "parent_snap"));
+  ASSERT_EQ(0, rbd_clone3(ioctx, parent_name.c_str(), "parent_snap", ioctx,
+         child_name.c_str(), opts));
+
+  // copy
+  std::string copy1_name = get_temp_image_name();
+  ASSERT_EQ(0, rbd_copy3(parent, ioctx, copy1_name.c_str(), opts));
+  std::string copy2_name = get_temp_image_name();
+  ASSERT_EQ(0, rbd_copy_with_progress3(parent, ioctx, copy2_name.c_str(), opts,
+         print_progress_percent, NULL));
+
+  ASSERT_EQ(0, rbd_close(parent));
+
+  rbd_image_options_destroy(opts);
+
+  rados_ioctx_destroy(ioctx);
+}
+
+TEST_F(TestLibRBD, TestImageOptionsPP)
+{
+  librados::IoCtx ioctx;
+  ASSERT_EQ(0, _rados.ioctx_create(m_pool_name.c_str(), ioctx));
+
+  //make create image options
+  uint64_t features = RBD_FEATURE_LAYERING | RBD_FEATURE_STRIPINGV2 ;
+  uint64_t order = 0;
+  uint64_t stripe_unit = 65536;
+  uint64_t stripe_count = 16;
+  librbd::ImageOptions opts;
+  ASSERT_EQ(0, opts.set(RBD_IMAGE_OPTION_FORMAT, static_cast<uint64_t>(2)));
+  ASSERT_EQ(0, opts.set(RBD_IMAGE_OPTION_FEATURES, features));
+  ASSERT_EQ(0, opts.set(RBD_IMAGE_OPTION_ORDER, order));
+  ASSERT_EQ(0, opts.set(RBD_IMAGE_OPTION_STRIPE_UNIT, stripe_unit));
+  ASSERT_EQ(0, opts.set(RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count));
+
+  librbd::RBD rbd;
+  std::string parent_name = get_temp_image_name();
+
+  // make parent
+  ASSERT_EQ(0, rbd.create4(ioctx, parent_name.c_str(), 4<<20, opts));
+
+  // check order is returned in opts
+  ASSERT_EQ(0, opts.get(RBD_IMAGE_OPTION_ORDER, &order));
+  ASSERT_NE((uint64_t)0, order);
+
+  // write some data to parent
+  librbd::Image parent;
+  ASSERT_EQ(0, rbd.open(ioctx, parent, parent_name.c_str(), NULL));
+
+  ssize_t len = 1024;
+  bufferlist bl;
+  bl.append(buffer::create(len));
+  bl.zero();
+  ASSERT_EQ(len, parent.write(0, len, bl));
+  ASSERT_EQ(len, parent.write(len, len, bl));
+
+  // create a snapshot, reopen as the parent we're interested in
+  ASSERT_EQ(0, parent.snap_create("parent_snap"));
+  ASSERT_EQ(0, parent.close());
+  ASSERT_EQ(0, rbd.open(ioctx, parent, parent_name.c_str(), "parent_snap"));
+
+  // clone
+  std::string child_name = get_temp_image_name();
+  ASSERT_EQ(0, parent.snap_protect("parent_snap"));
+  ASSERT_EQ(0, rbd.clone3(ioctx, parent_name.c_str(), "parent_snap", ioctx,
+         child_name.c_str(), opts));
+
+  // copy
+  std::string copy1_name = get_temp_image_name();
+  ASSERT_EQ(0, parent.copy3(ioctx, copy1_name.c_str(), opts));
+  std::string copy2_name = get_temp_image_name();
+  PrintProgress pp;
+  ASSERT_EQ(0, parent.copy_with_progress3(ioctx, copy2_name.c_str(), opts, pp));
+
+  ASSERT_EQ(0, parent.close());
+}
index abd7a70ea3a3c5dc372f970588b23ca0556d2a0d..1e8d95c1bfc9268629429cd17fab12598b2f8068 100644 (file)
@@ -300,6 +300,24 @@ class TestImage(object):
         self.image.update_features(RBD_FEATURE_EXCLUSIVE_LOCK, True)
         eq(features | RBD_FEATURE_EXCLUSIVE_LOCK, self.image.features())
 
+    @require_features([RBD_FEATURE_STRIPINGV2])
+    def test_create_with_params(self):
+        global features
+        image_name = get_temp_image_name()
+        order = 20
+        stripe_unit = 1 << 20
+        stripe_count = 10
+        self.rbd.create(ioctx, image_name, IMG_SIZE, order,
+                        False, features, stripe_unit, stripe_count)
+        image = Image(ioctx, image_name)
+        info = image.stat()
+        check_stat(info, IMG_SIZE, order)
+        eq(image.features(), features)
+        eq(image.stripe_unit(), stripe_unit)
+        eq(image.stripe_count(), stripe_count)
+        image.close()
+        RBD().remove(ioctx, image_name)
+
     def test_invalidate_cache(self):
         self.image.write('abc', 0)
         eq('abc', self.image.read(0, 3))
@@ -393,12 +411,23 @@ class TestImage(object):
         read = self.image.read(IMG_SIZE / 2 - 5, 251)
         eq('\0' * 251, read)
 
-    def test_copy(self):
+    def _test_copy(self, features=None, order=None, stripe_unit=None,
+                   stripe_count=None):
         global ioctx
         data = rand_data(256)
         self.image.write(data, 256)
         image_name = get_temp_image_name()
-        self.image.copy(ioctx, image_name)
+        if features is None:
+            self.image.copy(ioctx, image_name)
+        elif order is None:
+            self.image.copy(ioctx, image_name, features)
+        elif stripe_unit is None:
+            self.image.copy(ioctx, image_name, features, order)
+        elif stripe_count is None:
+            self.image.copy(ioctx, image_name, features, order, stripe_unit)
+        else:
+            self.image.copy(ioctx, image_name, features, order, stripe_unit,
+                            stripe_count)
         assert_raises(ImageExists, self.image.copy, ioctx, image_name)
         copy = Image(ioctx, image_name)
         copy_data = copy.read(256, 256)
@@ -406,6 +435,18 @@ class TestImage(object):
         self.rbd.remove(ioctx, image_name)
         eq(data, copy_data)
 
+    def test_copy(self):
+        self._test_copy()
+
+    def test_copy2(self):
+        self._test_copy(self.image.features(), self.image.stat()['order'])
+
+    @require_features([RBD_FEATURE_STRIPINGV2])
+    def test_copy3(self):
+        global features
+        self._test_copy(features, self.image.stat()['order'],
+                        self.image.stripe_unit(), self.image.stripe_count())
+
     def test_create_snap(self):
         global ioctx
         self.image.create_snap('snap1')
@@ -707,6 +748,19 @@ class TestClone(object):
         self.image.close()
         remove_image()
 
+    @require_features([RBD_FEATURE_STRIPINGV2])
+    def test_with_params(self):
+        global features
+        self.image.create_snap('snap2')
+        self.image.protect_snap('snap2')
+        clone_name2 = get_temp_image_name()
+        self.rbd.clone(ioctx, image_name, 'snap2', ioctx, clone_name2,
+                       features, self.image.stat()['order'],
+                       self.image.stripe_unit(), self.image.stripe_count())
+        self.rbd.remove(ioctx, clone_name2)
+        self.image.unprotect_snap('snap2')
+        self.image.remove_snap('snap2')
+
     def test_unprotected(self):
         self.image.create_snap('snap2')
         global features