From 3e08577a296bc4ce2c1592849108926b45e9b541 Mon Sep 17 00:00:00 2001 From: PCzhangPC Date: Sat, 21 Oct 2017 11:31:02 +0800 Subject: [PATCH] test_librbd:add a test case of 70 key/val pairs in TestClone Signed-off-by: PCzhangPC --- src/test/librbd/test_librbd.cc | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 7893244ed85..48dfffe4c71 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -2544,6 +2544,28 @@ TEST_F(TestLibRBD, TestClone) ASSERT_EQ(-ENOENT, rbd_get_parent_info(parent, NULL, 0, NULL, 0, NULL, 0)); printf("parent has no parent info\n"); + // create 70 metadatas to verify we can clone all key/value pairs + std::string key; + std::string val; + size_t sum_key_len = 0; + size_t sum_value_len = 0; + for (int i = 1; i <= 70; i++) { + key = "key" + stringify(i); + val = "value" + stringify(i); + ASSERT_EQ(0, rbd_metadata_set(parent, key.c_str(), val.c_str())); + + sum_key_len += (key.size() + 1); + sum_value_len += (val.size() + 1); + } + + char keys[1024]; + char vals[1024]; + size_t keys_len = sizeof(keys); + size_t vals_len = sizeof(vals); + + char value[1024]; + size_t value_len = sizeof(value); + // create a snapshot, reopen as the parent we're interested in ASSERT_EQ(0, rbd_snap_create(parent, "parent_snap")); printf("made snapshot \"parent@parent_snap\"\n"); @@ -2587,6 +2609,22 @@ TEST_F(TestLibRBD, TestClone) EXPECT_EQ(cinfo.order, pinfo.order); printf("sizes and overlaps are good between parent and child\n"); + // check key/value pairs in child image + ASSERT_EQ(0, rbd_metadata_list(child, "", 70, keys, &keys_len, vals, + &vals_len)); + ASSERT_EQ(sum_key_len, keys_len); + ASSERT_EQ(sum_value_len, vals_len); + + for (int i = 1; i <= 70; i++) { + key = "key" + stringify(i); + val = "value" + stringify(i); + ASSERT_EQ(0, rbd_metadata_get(child, key.c_str(), value, &value_len)); + ASSERT_STREQ(val.c_str(), value); + + value_len = sizeof(value); + } + printf("child image successfully cloned all image-meta pairs\n"); + // sizing down child results in changing overlap and size, not parent size ASSERT_EQ(0, rbd_resize(child, 2UL<<20)); ASSERT_EQ(0, rbd_stat(child, &cinfo, sizeof(cinfo))); -- 2.39.5