From: David Zafman Date: Fri, 28 Mar 2014 22:35:46 +0000 (-0700) Subject: test: Add EC test classes RadosTestEC and RadosTestECPP X-Git-Tag: v0.79~28^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9bd5821aabe2db7b52b870dfb98e776414137b5a;p=ceph.git test: Add EC test classes RadosTestEC and RadosTestECPP Fixes: #7437 Signed-off-by: David Zafman --- diff --git a/src/test/librados/TestCase.cc b/src/test/librados/TestCase.cc index 70c5ac8639d9f..d9e5e49328ccb 100644 --- a/src/test/librados/TestCase.cc +++ b/src/test/librados/TestCase.cc @@ -27,6 +27,7 @@ void RadosTest::SetUp() ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx)); std::string nspace = get_temp_pool_name(); rados_ioctx_set_namespace(ioctx, nspace.c_str()); + ASSERT_FALSE(rados_ioctx_pool_requires_alignment(ioctx)); } void RadosTest::TearDown() @@ -72,6 +73,7 @@ void RadosTestPP::SetUp() 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 RadosTestPP::TearDown() @@ -91,3 +93,94 @@ void RadosTestPP::cleanup_default_namespace(librados::IoCtx ioctx) ASSERT_EQ(0, ioctx.remove(it->first)); } } + +std::string RadosTestEC::pool_name; +rados_t RadosTestEC::s_cluster = NULL; + +void RadosTestEC::SetUpTestCase() +{ + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_ec_pool(pool_name, &s_cluster)); +} + +void RadosTestEC::TearDownTestCase() +{ + ASSERT_EQ(0, destroy_one_ec_pool(pool_name, &s_cluster)); +} + +void RadosTestEC::SetUp() +{ + cluster = RadosTestEC::s_cluster; + ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx)); + std::string nspace = get_temp_pool_name(); + rados_ioctx_set_namespace(ioctx, nspace.c_str()); + ASSERT_TRUE(rados_ioctx_pool_requires_alignment(ioctx)); + alignment = rados_ioctx_pool_required_alignment(ioctx); + ASSERT_NE((unsigned)0, alignment); +} + +void RadosTestEC::TearDown() +{ + cleanup_default_namespace(ioctx); + rados_ioctx_destroy(ioctx); +} + +void RadosTestEC::cleanup_default_namespace(rados_ioctx_t ioctx) +{ + // remove all objects from the default namespace to avoid polluting + // other tests + rados_ioctx_set_namespace(ioctx, ""); + rados_list_ctx_t list_ctx; + ASSERT_EQ(0, rados_objects_list_open(ioctx, &list_ctx)); + int r; + const char *entry = NULL; + const char *key = NULL; + while ((r = rados_objects_list_next(list_ctx, &entry, &key)) != -ENOENT) { + ASSERT_EQ(0, r); + rados_ioctx_locator_set_key(ioctx, key); + ASSERT_EQ(0, rados_remove(ioctx, entry)); + } + rados_objects_list_close(list_ctx); +} + +std::string RadosTestECPP::pool_name; +Rados RadosTestECPP::s_cluster; + +void RadosTestECPP::SetUpTestCase() +{ + pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_ec_pool_pp(pool_name, s_cluster)); +} + +void RadosTestECPP::TearDownTestCase() +{ + ASSERT_EQ(0, destroy_one_ec_pool_pp(pool_name, s_cluster)); +} + +void RadosTestECPP::SetUp() +{ + ASSERT_EQ(0, cluster.ioctx_create(pool_name.c_str(), ioctx)); + ns = get_temp_pool_name(); + ioctx.set_namespace(ns); + ASSERT_TRUE(ioctx.pool_requires_alignment()); + alignment = ioctx.pool_required_alignment(); + ASSERT_NE((unsigned)0, alignment); +} + +void RadosTestECPP::TearDown() +{ + cleanup_default_namespace(ioctx); + ioctx.close(); +} + +void RadosTestECPP::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)); + } +} diff --git a/src/test/librados/TestCase.h b/src/test/librados/TestCase.h index 31fa040938c7e..ccc03597b26e0 100644 --- a/src/test/librados/TestCase.h +++ b/src/test/librados/TestCase.h @@ -53,4 +53,41 @@ protected: std::string ns; }; +class RadosTestEC : public ::testing::Test { +public: + RadosTestEC() {} + virtual ~RadosTestEC() {} +protected: + static void SetUpTestCase(); + static void TearDownTestCase(); + static void cleanup_default_namespace(rados_ioctx_t ioctx); + static rados_t s_cluster; + static std::string pool_name; + + virtual void SetUp(); + virtual void TearDown(); + rados_t cluster; + rados_ioctx_t ioctx; + uint64_t alignment; +}; + +class RadosTestECPP : public ::testing::Test { +public: + RadosTestECPP() : cluster(s_cluster) {}; + virtual ~RadosTestECPP() {}; +protected: + static void SetUpTestCase(); + static void TearDownTestCase(); + static void cleanup_default_namespace(librados::IoCtx ioctx); + static librados::Rados s_cluster; + static std::string pool_name; + + virtual void SetUp(); + virtual void TearDown(); + librados::Rados &cluster; + librados::IoCtx ioctx; + std::string ns; + uint64_t alignment; +}; + #endif diff --git a/src/test/librados/test.cc b/src/test/librados/test.cc index 83f11b0b0b3a2..f8a92a2ffad33 100644 --- a/src/test/librados/test.cc +++ b/src/test/librados/test.cc @@ -43,6 +43,46 @@ std::string create_one_pool(const std::string &pool_name, rados_t *cluster) return ""; } +std::string create_one_ec_pool(const std::string &pool_name, rados_t *cluster) +{ + std::string err = connect_cluster(cluster); + if (err.length()) + return err; + + char *cmd[2]; + + cmd[1] = NULL; + + cmd[0] = (char *)"{\"prefix\": \"osd erasure-code-profile set\", \"name\": \"testprofile\", \"profile\": [ \"k=2\", \"m=1\", \"ruleset-failure-domain=osd\"]}"; + int ret = rados_mon_command(*cluster, (const char **)cmd, 1, "", 0, NULL, NULL, NULL, NULL); + if (ret) { + rados_shutdown(*cluster); + std::ostringstream oss; + oss << "rados_mon_command erasure-code-profile set name:testprofile failed with error " << ret; + return oss.str(); + } + + std::string cmdstr = "{\"prefix\": \"osd pool create\", \"pool\": \"" + + pool_name + "\", \"pool_type\":\"erasure\", \"pg_num\":8, \"pgp_num\":8, \"erasure_code_profile\":\"testprofile\"}"; + cmd[0] = (char *)cmdstr.c_str(); + ret = rados_mon_command(*cluster, (const char **)cmd, 1, "", 0, NULL, 0, NULL, 0); + if (ret) { + std::ostringstream oss; + + cmd[0] = (char *)"{\"prefix\": \"osd erasure-code-profile rm\", \"name\": \"testprofile\"}"; + int ret2 = rados_mon_command(*cluster, (const char **)cmd, 1, "", 0, NULL, 0, NULL, 0); + if (ret2) + oss << "rados_mon_command osd erasure-code-profile rm name:testprofile failed with error " << ret2 << std::endl; + + rados_shutdown(*cluster); + oss << "rados_mon_command erasure-code-profile set name:testprofile failed with error " << ret; + return oss.str(); + } + + rados_wait_for_latest_osdmap(*cluster); + return ""; +} + std::string create_one_pool_pp(const std::string &pool_name, Rados &cluster) { std::string err = connect_cluster_pp(cluster); @@ -58,6 +98,44 @@ std::string create_one_pool_pp(const std::string &pool_name, Rados &cluster) return ""; } +std::string create_one_ec_pool_pp(const std::string &pool_name, Rados &cluster) +{ + std::string err = connect_cluster_pp(cluster); + if (err.length()) + return err; + + bufferlist inbl; + int ret = cluster.mon_command( + "{\"prefix\": \"osd erasure-code-profile set\", \"name\": \"testprofile\", \"profile\": [ \"k=2\", \"m=1\", \"ruleset-failure-domain=osd\"]}", + inbl, NULL, NULL); + if (ret) { + cluster.shutdown(); + std::ostringstream oss; + oss << "mon_command erasure-code-profile set name:testprofile failed with error " << ret; + return oss.str(); + } + + ret = cluster.mon_command( + "{\"prefix\": \"osd pool create\", \"pool\": \"" + pool_name + "\", \"pool_type\":\"erasure\", \"pg_num\":8, \"pgp_num\":8, \"erasure_code_profile\":\"testprofile\"}", + inbl, NULL, NULL); + if (ret) { + std::ostringstream oss; + bufferlist inbl; + int ret2 = cluster.mon_command( + "{\"prefix\": \"osd erasure-code-profile rm\", \"name\": \"testprofile\"}", + inbl, NULL, NULL); + if (ret2) + oss << "mon_command osd erasure-code-profile rm name:testprofile failed with error " << ret2 << std::endl; + + cluster.shutdown(); + oss << "mon_command osd pool create pool:" << pool_name << " pool_type:erasure failed with error " << ret; + return oss.str(); + } + + cluster.wait_for_latest_osdmap(); + return ""; +} + std::string connect_cluster(rados_t *cluster) { char *id = getenv("CEPH_CLIENT_ID"); @@ -129,6 +207,26 @@ int destroy_one_pool(const std::string &pool_name, rados_t *cluster) return 0; } +int destroy_one_ec_pool(const std::string &pool_name, rados_t *cluster) +{ + int ret = rados_pool_delete(*cluster, pool_name.c_str()); + if (ret == 0) { + char *cmd[2]; + + cmd[1] = NULL; + + cmd[0] = (char *)"{\"prefix\": \"osd erasure-code-profile rm\", \"name\": \"testprofile\"}"; + int ret2 = rados_mon_command(*cluster, (const char **)cmd, 1, "", 0, NULL, 0, NULL, 0); + if (ret2) { + rados_shutdown(*cluster); + return ret2; + } + rados_wait_for_latest_osdmap(*cluster); + } + rados_shutdown(*cluster); + return ret; +} + int destroy_one_pool_pp(const std::string &pool_name, Rados &cluster) { int ret = cluster.pool_delete(pool_name.c_str()); @@ -139,3 +237,21 @@ int destroy_one_pool_pp(const std::string &pool_name, Rados &cluster) cluster.shutdown(); return 0; } + +int destroy_one_ec_pool_pp(const std::string &pool_name, Rados &cluster) +{ + int ret = cluster.pool_delete(pool_name.c_str()); + bufferlist inbl; + if (ret == 0) { + int ret2 = cluster.mon_command( + "{\"prefix\": \"osd erasure-code-profile rm\", \"name\": \"testprofile\"}", + inbl, NULL, NULL); + if (ret2) { + cluster.shutdown(); + return ret2; + } + cluster.wait_for_latest_osdmap(); + } + cluster.shutdown(); + return ret; +} diff --git a/src/test/librados/test.h b/src/test/librados/test.h index 652c235972bc4..6cf522def31d8 100644 --- a/src/test/librados/test.h +++ b/src/test/librados/test.h @@ -24,12 +24,17 @@ std::string get_temp_pool_name(); std::string create_one_pool(const std::string &pool_name, rados_t *cluster); +std::string create_one_ec_pool(const std::string &pool_name, rados_t *cluster); std::string create_one_pool_pp(const std::string &pool_name, librados::Rados &cluster); +std::string create_one_ec_pool_pp(const std::string &pool_name, + librados::Rados &cluster); std::string connect_cluster(rados_t *cluster); std::string connect_cluster_pp(librados::Rados &cluster); int destroy_one_pool(const std::string &pool_name, rados_t *cluster); +int destroy_one_ec_pool(const std::string &pool_name, rados_t *cluster); int destroy_one_pool_pp(const std::string &pool_name, librados::Rados &cluster); +int destroy_one_ec_pool_pp(const std::string &pool_name, librados::Rados &cluster); class TestAlarm {