]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/librados/cmd_cxx.cc
import quincy 17.2.0
[ceph.git] / 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
3
4 #include <errno.h>
5 #include <condition_variable>
6 #include <map>
7 #include <sstream>
8 #include <string>
9
10 #include "gtest/gtest.h"
11
12 #include "include/rados/librados.hpp"
13 #include "include/stringify.h"
14 #include "test/librados/test_cxx.h"
15
16 using namespace librados;
17 using std::map;
18 using std::ostringstream;
19 using std::string;
20
21 TEST(LibRadosCmd, MonDescribePP) {
22 Rados cluster;
23 ASSERT_EQ("", connect_cluster_pp(cluster));
24 bufferlist inbl, outbl;
25 string outs;
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());
30 cluster.shutdown();
31 }
32
33 TEST(LibRadosCmd, OSDCmdPP) {
34 Rados cluster;
35 ASSERT_EQ("", connect_cluster_pp(cluster));
36 int r;
37 bufferlist inbl, outbl;
38 string outs;
39 string cmd;
40
41 // note: tolerate NXIO here in case the cluster is thrashing out underneath us.
42 cmd = "asdfasdf";
43 r = cluster.osd_command(0, cmd, inbl, &outbl, &outs);
44 ASSERT_TRUE(r == -22 || r == -ENXIO);
45 cmd = "version";
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));
51 cluster.shutdown();
52 }
53
54 TEST(LibRadosCmd, PGCmdPP) {
55 Rados cluster;
56 std::string pool_name = get_temp_pool_name();
57 ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
58
59 int r;
60 bufferlist inbl, outbl;
61 string outs;
62 string cmd;
63
64 int64_t poolid = cluster.pool_lookup(pool_name.c_str());
65 ASSERT_LT(0, poolid);
66
67 string pgid = stringify(poolid) + ".0";
68
69 cmd = "asdfasdf";
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);
73
74 // make sure the pg exists on the osd before we query it
75 IoCtx io;
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));
80 }
81 io.close();
82
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);
87
88 ASSERT_LT(0u, outbl.length());
89
90 ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
91 }
92