]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: Add EC test classes RadosTestEC and RadosTestECPP
authorDavid Zafman <david.zafman@inktank.com>
Fri, 28 Mar 2014 22:35:46 +0000 (15:35 -0700)
committerDavid Zafman <david.zafman@inktank.com>
Tue, 1 Apr 2014 18:53:50 +0000 (11:53 -0700)
Fixes: #7437
Signed-off-by: David Zafman <david.zafman@inktank.com>
src/test/librados/TestCase.cc
src/test/librados/TestCase.h
src/test/librados/test.cc
src/test/librados/test.h

index 70c5ac8639d9f7ce2554cc431b70881fc422fe66..d9e5e49328ccb95f828d31f6cefe8dc7f1513702 100644 (file)
@@ -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));
+  }
+}
index 31fa040938c7e9786705983a8910a5ba6da1318d..ccc03597b26e0cf18f6aa802c15c3398325f40a7 100644 (file)
@@ -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
index 83f11b0b0b3a2d6e0270b910f35c2877c58d568e..f8a92a2ffad330f119133d7cb416ea07dbc4247e 100644 (file)
@@ -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;
+}
index 652c235972bc4b1ae90a836ead6db60a972e0bf5..6cf522def31d8194c9170311c4f3fd44be69d000 100644 (file)
 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
 {