From: Sage Weil Date: Sat, 12 Apr 2014 00:05:21 +0000 (-0700) Subject: test/librados/TestCase: add Param option that can set up a cache pool X-Git-Tag: v0.80-rc1~45^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b31107b7776122b903b080d571096aa62f616b90;p=ceph.git test/librados/TestCase: add Param option that can set up a cache pool Signed-off-by: Sage Weil --- diff --git a/src/test/librados/TestCase.cc b/src/test/librados/TestCase.cc index d9e5e49328cc..9f68af14e2b1 100644 --- a/src/test/librados/TestCase.cc +++ b/src/test/librados/TestCase.cc @@ -94,6 +94,87 @@ void RadosTestPP::cleanup_default_namespace(librados::IoCtx ioctx) } } +std::string RadosTestParamPP::pool_name; +std::string RadosTestParamPP::cache_pool_name; +Rados RadosTestParamPP::s_cluster; + +void RadosTestParamPP::SetUpTestCase() +{ + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster)); +} + +void RadosTestParamPP::TearDownTestCase() +{ + if (cache_pool_name.length()) { + // tear down tiers + bufferlist inbl; + ASSERT_EQ(0, s_cluster.mon_command( + "{\"prefix\": \"osd tier remove-overlay\", \"pool\": \"" + pool_name + + "\"}", + inbl, NULL, NULL)); + ASSERT_EQ(0, s_cluster.mon_command( + "{\"prefix\": \"osd tier remove\", \"pool\": \"" + pool_name + + "\", \"tierpool\": \"" + cache_pool_name + "\"}", + inbl, NULL, NULL)); + ASSERT_EQ(0, s_cluster.mon_command( + "{\"prefix\": \"osd pool delete\", \"pool\": \"" + cache_pool_name + + "\", \"pool2\": \"" + cache_pool_name + "\", \"sure\": \"--yes-i-really-really-mean-it\"}", + inbl, NULL, NULL)); + cache_pool_name = ""; + } + ASSERT_EQ(0, destroy_one_pool_pp(pool_name, s_cluster)); +} + +void RadosTestParamPP::SetUp() +{ + if (strcmp(GetParam(), "cache") == 0 && cache_pool_name.empty()) { + cache_pool_name = get_temp_pool_name(); + bufferlist inbl; + ASSERT_EQ(0, cluster.mon_command( + "{\"prefix\": \"osd pool create\", \"pool\": \"" + cache_pool_name + + "\", \"pg_num\": 4}", + inbl, NULL, NULL)); + ASSERT_EQ(0, cluster.mon_command( + "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name + + "\", \"tierpool\": \"" + cache_pool_name + + "\", \"force_nonempty\": \"--force-nonempty\" }", + inbl, NULL, NULL)); + ASSERT_EQ(0, cluster.mon_command( + "{\"prefix\": \"osd tier set-overlay\", \"pool\": \"" + pool_name + + "\", \"overlaypool\": \"" + cache_pool_name + "\"}", + inbl, NULL, NULL)); + ASSERT_EQ(0, cluster.mon_command( + "{\"prefix\": \"osd tier cache-mode\", \"pool\": \"" + cache_pool_name + + "\", \"mode\": \"writeback\"}", + inbl, NULL, NULL)); + cluster.wait_for_latest_osdmap(); + } + + ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); + ns = get_temp_pool_name(); + ioctx.set_namespace(ns); + ASSERT_FALSE(ioctx.pool_requires_alignment()); +} + +void RadosTestParamPP::TearDown() +{ + cleanup_default_namespace(ioctx); + ioctx.close(); +} + +void RadosTestParamPP::cleanup_default_namespace(librados::IoCtx ioctx) +{ + // remove all objects from the default namespace to avoid polluting + // other tests + ioctx.set_namespace(""); + for (ObjectIterator it = ioctx.objects_begin(); + it != ioctx.objects_end(); ++it) { + ioctx.locator_set_key(it->second); + ASSERT_EQ(0, ioctx.remove(it->first)); + } +} + std::string RadosTestEC::pool_name; rados_t RadosTestEC::s_cluster = NULL; diff --git a/src/test/librados/TestCase.h b/src/test/librados/TestCase.h index ccc03597b26e..5bd084fcfcd4 100644 --- a/src/test/librados/TestCase.h +++ b/src/test/librados/TestCase.h @@ -53,6 +53,25 @@ protected: std::string ns; }; +class RadosTestParamPP : public ::testing::TestWithParam { +public: + RadosTestParamPP() : cluster(s_cluster) {} + virtual ~RadosTestParamPP() {} + static void SetUpTestCase(); + static void TearDownTestCase(); +protected: + static void cleanup_default_namespace(librados::IoCtx ioctx); + static librados::Rados s_cluster; + static std::string pool_name; + static std::string cache_pool_name; + + virtual void SetUp(); + virtual void TearDown(); + librados::Rados &cluster; + librados::IoCtx ioctx; + std::string ns; +}; + class RadosTestEC : public ::testing::Test { public: RadosTestEC() {}