diff --git a/src/cls_rbd.cc b/src/cls_rbd.cc index 61edd14d85e..c1f2d046b01 100644 --- a/src/cls_rbd.cc +++ b/src/cls_rbd.cc @@ -20,6 +20,7 @@ cls_method_handle_t h_snapshot_add; cls_method_handle_t h_snapshot_remove; cls_method_handle_t h_snapshot_revert; cls_method_handle_t h_assign_bid; +cls_method_handle_t h_test_exec; static int snap_read_header(cls_method_context_t hctx, bufferlist& bl) { @@ -366,6 +367,15 @@ int rbd_assign_bid(cls_method_context_t hctx, bufferlist *in, bufferlist *out) return out->length(); } +/* Used for testing rados_exec */ +static int test_exec(cls_method_context_t hctx, bufferlist *in, bufferlist *out) +{ + bufferlist bl; + std::string testing123("testing123"); + ::encode(testing123, *out); + return out->length(); +} + void __cls_init() { CLS_LOG("Loaded rbd class!"); @@ -379,6 +389,8 @@ void __cls_init() /* assign a unique block id for rbd blocks */ cls_register_cxx_method(h_class, "assign_bid", CLS_METHOD_RD | CLS_METHOD_WR | CLS_METHOD_PUBLIC, rbd_assign_bid, &h_assign_bid); + cls_register_cxx_method(h_class, "test_exec", CLS_METHOD_RD | CLS_METHOD_PUBLIC, test_exec, &h_test_exec); + return; } diff --git a/src/test/rados-api/misc.cc b/src/test/rados-api/misc.cc index a6d77933863..1cd1fdacd95 100644 --- a/src/test/rados-api/misc.cc +++ b/src/test/rados-api/misc.cc @@ -114,25 +114,46 @@ TEST(LibRadosMisc, TmapUpdatePP) { ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); } -//TEST(LibRadosMisc, Exec) { -// char buf[128]; -// char buf2[sizeof(buf)]; -// char buf3[sizeof(buf)]; -// rados_t cluster; -// rados_ioctx_t ioctx; -// std::string pool_name = get_temp_pool_name(); -// ASSERT_EQ("", create_one_pool(pool_name, &cluster)); -// rados_ioctx_create(cluster, pool_name.c_str(), &ioctx); -// memset(buf, 0xcc, sizeof(buf)); -// ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); -// strncpy(buf2, "abracadabra", sizeof(buf2)); -// memset(buf3, 0, sizeof(buf3)); -// ASSERT_EQ(0, rados_exec(ioctx, "foo", "crypto", "md5", -// buf2, strlen(buf2) + 1, buf3, sizeof(buf3))); -// ASSERT_EQ(string("06fce6115b1efc638e0cc2026f69ec43"), string(buf3)); -// rados_ioctx_destroy(ioctx); -// ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster)); -//} +TEST(LibRadosMisc, Exec) { + char buf[128]; + rados_t cluster; + rados_ioctx_t ioctx; + std::string pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool(pool_name, &cluster)); + rados_ioctx_create(cluster, pool_name.c_str(), &ioctx); + memset(buf, 0xcc, sizeof(buf)); + ASSERT_EQ((int)sizeof(buf), rados_write(ioctx, "foo", buf, sizeof(buf), 0)); + char buf2[512]; + int res = rados_exec(ioctx, "foo", "rbd", "test_exec", + NULL, 0, buf2, sizeof(buf2)); + ASSERT_GT(res, 0); + bufferlist bl; + bl.append(buf2, res); + bufferlist::iterator iter = bl.begin(); + std::string outstring; + ::decode(outstring, iter); + ASSERT_EQ(outstring, string("testing123")); + rados_ioctx_destroy(ioctx); + ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster)); +} + +TEST(LibRadosMisc, ExecPP) { + Rados cluster; + std::string pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool_pp(pool_name, cluster)); + IoCtx ioctx; + cluster.ioctx_create(pool_name.c_str(), ioctx); + bufferlist bl; + ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0)); + bufferlist bl2, out; + ASSERT_EQ(0, ioctx.exec("foo", "rbd", "test_exec", bl2, out)); + bufferlist::iterator iter = out.begin(); + std::string outstring; + ::decode(outstring, iter); + ASSERT_EQ(outstring, string("testing123")); + ioctx.close(); + ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); +} //int rados_tmap_update(rados_ioctx_t io, const char *o, const char *cmdbuf, size_t cmdbuflen);