]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/librados/cmd_cxx.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 #include <condition_variable>
10 #include "gtest/gtest.h"
12 #include "include/rados/librados.hpp"
13 #include "include/stringify.h"
14 #include "test/librados/test_cxx.h"
16 using namespace librados
;
18 using std::ostringstream
;
21 TEST(LibRadosCmd
, MonDescribePP
) {
23 ASSERT_EQ("", connect_cluster_pp(cluster
));
24 bufferlist inbl
, outbl
;
26 ASSERT_EQ(0, cluster
.mon_command("{\"prefix\": \"get_command_descriptions\"}",
27 inbl
, &outbl
, &outs
));
28 ASSERT_LT(0u, outbl
.length());
29 ASSERT_LE(0u, outs
.length());
33 TEST(LibRadosCmd
, OSDCmdPP
) {
35 ASSERT_EQ("", connect_cluster_pp(cluster
));
37 bufferlist inbl
, outbl
;
41 // note: tolerate NXIO here in case the cluster is thrashing out underneath us.
43 r
= cluster
.osd_command(0, cmd
, inbl
, &outbl
, &outs
);
44 ASSERT_TRUE(r
== -22 || r
== -ENXIO
);
46 r
= cluster
.osd_command(0, cmd
, inbl
, &outbl
, &outs
);
47 ASSERT_TRUE(r
== -22 || r
== -ENXIO
);
48 cmd
= "{\"prefix\":\"version\"}";
49 r
= cluster
.osd_command(0, cmd
, inbl
, &outbl
, &outs
);
50 ASSERT_TRUE((r
== 0 && outbl
.length() > 0) || (r
== -ENXIO
&& outbl
.length() == 0));
54 TEST(LibRadosCmd
, PGCmdPP
) {
56 std::string pool_name
= get_temp_pool_name();
57 ASSERT_EQ("", create_one_pool_pp(pool_name
, cluster
));
60 bufferlist inbl
, outbl
;
64 int64_t poolid
= cluster
.pool_lookup(pool_name
.c_str());
67 string pgid
= stringify(poolid
) + ".0";
70 // note: tolerate NXIO here in case the cluster is thrashing out underneath us.
71 r
= cluster
.pg_command(pgid
.c_str(), cmd
, inbl
, &outbl
, &outs
);
72 ASSERT_TRUE(r
== -22 || r
== -ENXIO
);
74 // make sure the pg exists on the osd before we query it
76 cluster
.ioctx_create(pool_name
.c_str(), io
);
77 for (int i
=0; i
<100; i
++) {
78 string oid
= "obj" + stringify(i
);
79 ASSERT_EQ(-ENOENT
, io
.stat(oid
, NULL
, NULL
));
83 cmd
= "{\"prefix\":\"pg\", \"cmd\":\"query\", \"pgid\":\"" + pgid
+ "\"}";
84 // note: tolerate ENOENT/ENXIO here if hte osd is thrashing out underneath us
85 r
= cluster
.pg_command(pgid
.c_str(), cmd
, inbl
, &outbl
, &outs
);
86 ASSERT_TRUE(r
== 0 || r
== -ENOENT
|| r
== -ENXIO
);
88 ASSERT_LT(0u, outbl
.length());
90 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, cluster
));