1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 #include "include/rados/librados.h"
3 #include "include/rados/librados.hpp"
4 #include "test/librados/test.h"
15 using namespace librados;
17 using std::ostringstream;
22 class WatchNotifyTestCtx : public WatchCtx
25 void notify(uint8_t opcode, uint64_t ver, bufferlist& bl) override
31 #pragma GCC diagnostic ignored "-Wpragmas"
32 #pragma GCC diagnostic push
33 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
36 test_loop(Rados &cluster, std::string pool_name, std::string obj_name)
40 ret = cluster.ioctx_create(pool_name.c_str(), ioctx);
42 std::cerr << "ioctx_create " << pool_name << " failed with " << ret << std::endl;
45 ioctx.application_enable("rados", true);
47 ret = ioctx.create(obj_name, false);
49 std::cerr << "create failed with " << ret << std::endl;
53 for (int i = 0; i < 10000; ++i) {
54 std::cerr << "Iteration " << i << std::endl;
56 WatchNotifyTestCtx ctx;
57 ret = ioctx.watch(obj_name, 0, &handle, &ctx);
60 ret = ioctx.notify(obj_name, 0, bl2);
64 ioctx.unwatch(obj_name, handle);
68 ret = cluster.pool_delete(pool_name.c_str());
70 std::cerr << "pool_delete failed with " << ret << std::endl;
75 #pragma GCC diagnostic pop
76 #pragma GCC diagnostic warning "-Wpragmas"
79 test_replicated(Rados &cluster, std::string pool_name, std::string obj_name)
82 cluster.pool_create(pool_name.c_str());
84 test_loop(cluster, pool_name, obj_name);
88 test_erasure(Rados &cluster, std::string pool_name, std::string obj_name)
93 ret = cluster.mon_command(
94 "{\"prefix\": \"osd erasure-code-profile set\", \"name\": \"testprofile\", \"profile\": [ \"k=2\", \"m=1\", \"crush-failure-domain=osd\"]}",
97 std::cerr << "mon_command erasure-code-profile set failed with " << ret << std::endl;
100 //std::cout << outs << std::endl;
103 ret = cluster.mon_command(
104 "{\"prefix\": \"osd pool create\", \"pool\": \"" + pool_name + "\", \"pool_type\":\"erasure\", \"pg_num\":12, \"pgp_num\":12, \"erasure_code_profile\":\"testprofile\"}",
107 std::cerr << outs << std::endl;
108 std::cerr << "mon_command create pool failed with " << ret << std::endl;
111 //std::cout << outs << std::endl;
113 cluster.wait_for_latest_osdmap();
114 test_loop(cluster, pool_name, obj_name);
118 int main(int args, char **argv)
120 if (args != 3 && args != 4) {
121 std::cerr << "Error: " << argv[0] << " [ec|rep] pool_name obj_name" << std::endl;
125 std::string pool_name, obj_name, type;
126 // For backward compatibility with unmodified teuthology version
136 std::cerr << "Test type " << type << std::endl;
137 std::cerr << "pool_name, obj_name are " << pool_name << ", " << obj_name << std::endl;
139 if (type != "ec" && type != "rep") {
140 std::cerr << "Error: " << argv[0] << " Invalid arg must be 'ec' or 'rep' saw " << type << std::endl;
144 char *id = getenv("CEPH_CLIENT_ID");
145 if (id) std::cerr << "Client id is: " << id << std::endl;
148 ret = cluster.init(id);
150 std::cerr << "Error " << ret << " in cluster.init" << std::endl;
153 ret = cluster.conf_read_file(NULL);
155 std::cerr << "Error " << ret << " in cluster.conf_read_file" << std::endl;
158 ret = cluster.conf_parse_env(NULL);
160 std::cerr << "Error " << ret << " in cluster.conf_read_env" << std::endl;
163 ret = cluster.connect();
165 std::cerr << "Error " << ret << " in cluster.connect" << std::endl;
169 test_replicated(cluster, pool_name, obj_name);
170 else if (type == "ec")
171 test_erasure(cluster, pool_name, obj_name);