]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add test case for c++ osd/pg command 6893/head
authorYunchuan Wen <yunchuan.wen@kylin-cloud.com>
Fri, 11 Dec 2015 02:16:25 +0000 (10:16 +0800)
committerYunchuan Wen <yunchuan.wen@kylin-cloud.com>
Fri, 11 Dec 2015 02:16:25 +0000 (10:16 +0800)
Signed-off-by: Yunchuan Wen <yunchuan.wen@kylin-cloud.com>
src/test/librados/cmd.cc

index d5e9d71fb6a5a9acb7765be1a00512837dcb069b..62b7d610a9ba9765ce539c66dd37efa28e20ea3d 100644 (file)
@@ -93,6 +93,27 @@ TEST(LibRadosCmd, OSDCmd) {
   rados_shutdown(cluster);
 }
 
+TEST(LibRadosCmd, OSDCmdPP) {
+  Rados cluster;
+  ASSERT_EQ("", connect_cluster_pp(cluster));
+  int r;
+  bufferlist inbl, outbl;
+  string outs;
+  string cmd;
+
+  // note: tolerate NXIO here in case the cluster is thrashing out underneath us.
+  cmd = "asdfasdf";
+  r = cluster.osd_command(0, cmd, inbl, &outbl, &outs);
+  ASSERT_TRUE(r == -22 || r == -ENXIO);
+  cmd = "version";
+  r = cluster.osd_command(0, cmd, inbl, &outbl, &outs);
+  ASSERT_TRUE(r == -22 || r == -ENXIO);
+  cmd = "{\"prefix\":\"version\"}";
+  r = cluster.osd_command(0, cmd, inbl, &outbl, &outs);
+  ASSERT_TRUE((r == 0 && outbl.length() > 0) || (r == -ENXIO && outbl.length() == 0));
+  cluster.shutdown();
+}
+
 TEST(LibRadosCmd, PGCmd) {
   rados_t cluster;
   std::string pool_name = get_temp_pool_name();
@@ -135,6 +156,45 @@ TEST(LibRadosCmd, PGCmd) {
   ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
 }
 
+TEST(LibRadosCmd, PGCmdPP) {
+  Rados cluster;
+  std::string pool_name = get_temp_pool_name();
+  ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
+
+  int r;
+  bufferlist inbl, outbl;
+  string outs;
+  string cmd;
+
+  int64_t poolid = cluster.pool_lookup(pool_name.c_str());
+  ASSERT_LT(0, poolid);
+
+  string pgid = stringify(poolid) + ".0";
+
+  cmd = "asdfasdf";
+  // note: tolerate NXIO here in case the cluster is thrashing out underneath us.
+  r = cluster.pg_command(pgid.c_str(), cmd, inbl, &outbl, &outs);
+  ASSERT_TRUE(r == -22 || r == -ENXIO);
+
+  // make sure the pg exists on the osd before we query it
+  IoCtx io;
+  cluster.ioctx_create(pool_name.c_str(), io);
+  for (int i=0; i<100; i++) {
+    string oid = "obj" + stringify(i);
+    ASSERT_EQ(-ENOENT, io.stat(oid, NULL, NULL));
+  }
+  io.close();
+
+  cmd = "{\"prefix\":\"pg\", \"cmd\":\"query\", \"pgid\":\"" +  pgid + "\"}";
+  // note: tolerate ENOENT/ENXIO here if hte osd is thrashing out underneath us
+  r = cluster.pg_command(pgid.c_str(), cmd, inbl, &outbl, &outs);
+  ASSERT_TRUE(r == 0 || r == -ENOENT || r == -ENXIO);
+
+  ASSERT_LT(0u, outbl.length());
+
+  ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
+}
+
 struct Log {
   list<string> log;
   Cond cond;