From: Dongsheng Yang Date: Fri, 15 Jul 2016 08:45:14 +0000 (-0400) Subject: test_librbd: add a test for newly introduced api of snap_remove2 X-Git-Tag: ses5-milestone5~282^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F10087%2Fhead;p=ceph.git test_librbd: add a test for newly introduced api of snap_remove2 Signed-off-by: Dongsheng Yang --- diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 9343a28a65c4..2a0c0fa1c170 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -3322,6 +3322,52 @@ TEST_F(TestLibRBD, SnapRemoveViaLockOwner) ASSERT_TRUE(lock_owner); } +TEST_F(TestLibRBD, SnapRemove2) +{ + REQUIRE_FEATURE(RBD_FEATURE_LAYERING); + + librados::IoCtx ioctx; + ASSERT_EQ(0, _rados.ioctx_create(m_pool_name.c_str(), ioctx)); + + librbd::RBD rbd; + std::string name = get_temp_image_name(); + uint64_t size = 2 << 20; + int order = 0; + ASSERT_EQ(0, create_image_pp(rbd, ioctx, name.c_str(), size, &order)); + + librbd::Image image1; + ASSERT_EQ(0, rbd.open(ioctx, image1, name.c_str(), NULL)); + + bufferlist bl; + ASSERT_EQ(0, image1.write(0, 0, bl)); + ASSERT_EQ(0, image1.snap_create("snap1")); + bool exists; + ASSERT_EQ(0, image1.snap_exists2("snap1", &exists)); + ASSERT_TRUE(exists); + ASSERT_EQ(0, image1.snap_protect("snap1")); + bool is_protected; + ASSERT_EQ(0, image1.snap_is_protected("snap1", &is_protected)); + ASSERT_TRUE(is_protected); + + uint64_t features; + ASSERT_EQ(0, image1.features(&features)); + + std::string child_name = get_temp_image_name(); + EXPECT_EQ(0, rbd.clone(ioctx, name.c_str(), "snap1", ioctx, + child_name.c_str(), features, &order)); + + ASSERT_EQ(0, image1.snap_exists2("snap1", &exists)); + ASSERT_TRUE(exists); + ASSERT_EQ(0, image1.snap_is_protected("snap1", &is_protected)); + ASSERT_TRUE(is_protected); + + ASSERT_EQ(-EBUSY, image1.snap_remove("snap1")); + PrintProgress pp; + ASSERT_EQ(0, image1.snap_remove2("snap1", RBD_SNAP_REMOVE_FORCE, pp)); + ASSERT_EQ(0, image1.snap_exists2("snap1", &exists)); + ASSERT_FALSE(exists); +} + TEST_F(TestLibRBD, SnapRenameViaLockOwner) { REQUIRE_FEATURE(RBD_FEATURE_LAYERING | RBD_FEATURE_EXCLUSIVE_LOCK);