]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: add destroy_ec_profile{,_pp} helpers
authorLoic Dachary <ldachary@redhat.com>
Mon, 2 Nov 2015 19:23:52 +0000 (20:23 +0100)
committerLoic Dachary <ldachary@redhat.com>
Mon, 2 Nov 2015 22:20:44 +0000 (23:20 +0100)
Signed-off-by: Loic Dachary <ldachary@redhat.com>
(cherry picked from commit ab46d79bc09fc711fa35302f49eecac81a98519b)

src/test/librados/test.cc

index f8a92a2ffad330f119133d7cb416ea07dbc4247e..e6e3ea2b1eb01f69928f122b4591bb6c5ed06f17 100644 (file)
@@ -43,25 +43,30 @@ std::string create_one_pool(const std::string &pool_name, rados_t *cluster)
   return "";
 }
 
+int destroy_ec_profile(rados_t *cluster)
+{
+    char *cmd[2];
+    cmd[0] = (char *)"{\"prefix\": \"osd erasure-code-profile rm\", \"name\": \"testprofile\"}";
+    cmd[1] = NULL;
+    return rados_mon_command(*cluster, (const char **)cmd, 1, "", 0, NULL, 0, NULL, 0);
+}
+
 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);
+  int ret = destroy_ec_profile(cluster);
   if (ret) {
     rados_shutdown(*cluster);
     std::ostringstream oss;
-    oss << "rados_mon_command erasure-code-profile set name:testprofile failed with error " << ret;
+    oss << "rados_mon_command erasure-code-profile rm testprofile failed with error " << ret;
     return oss.str();
   }
     
+  char *cmd[2];
+  cmd[1] = NULL;
   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();
@@ -69,8 +74,7 @@ std::string create_one_ec_pool(const std::string &pool_name, rados_t *cluster)
   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);
+    int ret2 = destroy_ec_profile(cluster);
     if (ret2)
       oss << "rados_mon_command osd erasure-code-profile rm name:testprofile failed with error " << ret2 << std::endl;
 
@@ -98,6 +102,13 @@ std::string create_one_pool_pp(const std::string &pool_name, Rados &cluster)
   return "";
 }
 
+int destroy_ec_profile_pp(Rados &cluster)
+{
+  bufferlist inbl;
+  return cluster.mon_command("{\"prefix\": \"osd erasure-code-profile rm\", \"name\": \"testprofile\"}",
+                             inbl, NULL, NULL);
+}
+
 std::string create_one_ec_pool_pp(const std::string &pool_name, Rados &cluster)
 {
   std::string err = connect_cluster_pp(cluster);
@@ -105,7 +116,7 @@ std::string create_one_ec_pool_pp(const std::string &pool_name, Rados &cluster)
     return err;
 
   bufferlist inbl;
-  int ret = cluster.mon_command(
+  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) {
@@ -121,9 +132,7 @@ std::string create_one_ec_pool_pp(const std::string &pool_name, Rados &cluster)
   if (ret) {
     std::ostringstream oss;
     bufferlist inbl;
-    int ret2 = cluster.mon_command(
-      "{\"prefix\": \"osd erasure-code-profile rm\", \"name\": \"testprofile\"}",
-      inbl, NULL, NULL);
+    int ret2 = destroy_ec_profile_pp(cluster);
     if (ret2)
       oss << "mon_command osd erasure-code-profile rm name:testprofile failed with error " << ret2 << std::endl;
 
@@ -211,12 +220,7 @@ 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);
+    int ret2 = destroy_ec_profile(cluster);
     if (ret2) {
       rados_shutdown(*cluster);
       return ret2;
@@ -243,9 +247,7 @@ 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);
+    int ret2 = destroy_ec_profile_pp(cluster);
     if (ret2) {
       cluster.shutdown();
       return ret2;