]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add rados_nobjects_list_xyz functions to librados test stub
authorJason Dillaman <dillaman@redhat.com>
Tue, 20 Jan 2015 17:12:43 +0000 (12:12 -0500)
committerJason Dillaman <dillaman@redhat.com>
Fri, 23 Jan 2015 17:27:41 +0000 (12:27 -0500)
The new RBD copy-on-read unit test case uses these RADOS functions
to verify that the CoR operation was successful.  This implements
these functions in the librados_test_stub library.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/librados_test_stub/LibradosTestStub.cc
src/test/librados_test_stub/TestMemRadosClient.cc
src/test/librados_test_stub/TestMemRadosClient.h
src/test/librados_test_stub/TestRadosClient.h
src/test/librbd/test_librbd.cc

index 0fb46da67289694af731f6c2256641b15e0bb918..57f1a62d00958e87d305a4802e8cc392db59c5f1 100644 (file)
@@ -15,6 +15,7 @@
 #include "objclass/objclass.h"
 #include <boost/bind.hpp>
 #include <deque>
+#include <list>
 #include <vector>
 
 static librados::TestClassHandler *get_class_handler() {
@@ -207,6 +208,53 @@ extern "C" int rados_mon_command(rados_t cluster, const char **cmd,
   return ret;
 }
 
+extern "C" int rados_nobjects_list_open(rados_ioctx_t io,
+                                        rados_list_ctx_t *ctx) {
+  librados::TestIoCtxImpl *io_ctx =
+    reinterpret_cast<librados::TestIoCtxImpl*>(io);
+  librados::TestRadosClient *client = io_ctx->get_rados_client();
+
+  std::list<librados::TestRadosClient::Object> *list =
+    new std::list<librados::TestRadosClient::Object>();
+  
+  client->object_list(io_ctx->get_id(), list);
+  list->push_front(librados::TestRadosClient::Object());
+  *ctx = reinterpret_cast<rados_list_ctx_t>(list);
+  return 0;
+}
+
+extern "C" int rados_nobjects_list_next(rados_list_ctx_t ctx,
+                                        const char **entry,
+                                        const char **key,
+                                        const char **nspace) {
+  std::list<librados::TestRadosClient::Object> *list =
+    reinterpret_cast<std::list<librados::TestRadosClient::Object> *>(ctx);
+  if (!list->empty()) {
+    list->pop_front();
+  }
+  if (list->empty()) {
+    return -ENOENT;
+  }
+
+  librados::TestRadosClient::Object &obj = list->front();
+  if (entry != NULL) {
+    *entry = obj.oid.c_str();
+  }
+  if (key != NULL) {
+    *key = obj.locator.c_str();
+  }
+  if (nspace != NULL) {
+    *nspace = obj.nspace.c_str();
+  }
+  return 0;
+}
+
+extern "C" void rados_nobjects_list_close(rados_list_ctx_t ctx) {
+  std::list<librados::TestRadosClient::Object> *list =
+    reinterpret_cast<std::list<librados::TestRadosClient::Object> *>(ctx);
+  delete list;
+}
+
 extern "C" int rados_pool_create(rados_t cluster, const char *pool_name) {
   librados::TestRadosClient *client =
     reinterpret_cast<librados::TestRadosClient*>(cluster);
index bb6034f2a02a6cc9f920d00929eaa8ecc8381b66..a225702adabc6466e509d8c7ca2f11f82da8dd9a 100644 (file)
@@ -44,6 +44,25 @@ TestIoCtxImpl *TestMemRadosClient::create_ioctx(int64_t pool_id,
   return new TestMemIoCtxImpl(*this, pool_id, pool_name, iter->second);
 }
 
+void TestMemRadosClient::object_list(int64_t pool_id,
+                                    std::list<librados::TestRadosClient::Object> *list) {
+  list->clear();
+
+  for (Pools::iterator p_it = m_pools.begin(); p_it != m_pools.end(); ++p_it) {
+    Pool *pool = p_it->second;
+    if (pool->pool_id == pool_id) {
+      RWLock::RLocker l(pool->file_lock);
+      for (Files::iterator it = pool->files.begin();
+          it != pool->files.end(); ++it) {
+       Object obj;
+       obj.oid = it->first;
+       list->push_back(obj);
+      } 
+      break;
+    }
+  }
+} 
+
 int TestMemRadosClient::pool_create(const std::string &pool_name) {
   if (m_pools.find(pool_name) != m_pools.end()) {
     return -EEXIST;
index 418415d4a5eb41ba73d16e1172f17f333ad8b6fb..5031d8c4ce8779abd5a151ffda59acf2b62fec53 100644 (file)
@@ -68,6 +68,9 @@ public:
   virtual TestIoCtxImpl *create_ioctx(int64_t pool_id,
                                       const std::string &pool_name);
 
+  virtual void object_list(int64_t pool_id, 
+                          std::list<librados::TestRadosClient::Object> *list);
+
   virtual int pool_create(const std::string &pool_name);
   virtual int pool_delete(const std::string &pool_name);
   virtual int pool_get_base_tier(int64_t pool_id, int64_t* base_tier);
index 8174d656872a38ce655ba9f478cd54b62a1f0f3f..bfccad6d998108fa207a3a89b39d09b308a73f53 100644 (file)
@@ -11,6 +11,7 @@
 #include "test/librados_test_stub/TestWatchNotify.h"
 #include <boost/function.hpp>
 #include <boost/functional/hash.hpp>
+#include <list>
 #include <map>
 #include <string>
 #include <vector>
@@ -26,6 +27,12 @@ public:
 
   typedef boost::function<int()> AioFunction;
 
+  struct Object {
+    std::string oid;
+    std::string locator;
+    std::string nspace;
+  };
+
   TestRadosClient(CephContext *cct);
 
   void get();
@@ -46,6 +53,9 @@ public:
                           const bufferlist &inbl,
                           bufferlist *outbl, std::string *outs);
 
+  virtual void object_list(int64_t pool_id,
+                          std::list<librados::TestRadosClient::Object> *list) = 0;
+
   virtual int pool_create(const std::string &pool_name) = 0;
   virtual int pool_delete(const std::string &pool_name) = 0;
   virtual int pool_get_base_tier(int64_t pool_id, int64_t* base_tier) = 0;
index 4723fe10275743f0ec6da740c6faed78169d1e4d..5fbbbd673836e09bc00137155455d3e9e5703f0e 100644 (file)
@@ -1464,14 +1464,14 @@ TEST_F(TestLibRBD, TestCoR)
 
   // find out what objects the parent image has generated
   ASSERT_EQ(0, rbd_stat(parent, &p_info, sizeof(p_info)));
-  ASSERT_EQ(0, rados_objects_list_open(ioctx, &list_ctx));
-  while (rados_objects_list_next(list_ctx, &entry, NULL) != -ENOENT) {
+  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx));
+  while (rados_nobjects_list_next(list_ctx, &entry, NULL, NULL) != -ENOENT) {
     if (strstr(entry, p_info.block_name_prefix)) {
       const char *block_name_suffix = entry + strlen(p_info.block_name_prefix) + 1;
       obj_checker.insert(block_name_suffix);
     }
   }
-  rados_objects_list_close(list_ctx);
+  rados_nobjects_list_close(list_ctx);
   ASSERT_EQ(obj_checker.size(), write_tracker.size());
 
   // create a snapshot, reopen as the parent we're interested in and protect it
@@ -1514,8 +1514,8 @@ TEST_F(TestLibRBD, TestCoR)
   printf("check whether child image has the same set of objects as parent\n");
   ASSERT_EQ(0, rbd_open(ioctx, "child", &child, NULL));
   ASSERT_EQ(0, rbd_stat(child, &c_info, sizeof(c_info)));
-  ASSERT_EQ(0, rados_objects_list_open(ioctx, &list_ctx));
-  while (rados_objects_list_next(list_ctx, &entry, NULL) != -ENOENT) {
+  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &list_ctx));
+  while (rados_nobjects_list_next(list_ctx, &entry, NULL, NULL) != -ENOENT) {
     if (strstr(entry, c_info.block_name_prefix)) {
       const char *block_name_suffix = entry + strlen(c_info.block_name_prefix) + 1;
       set<string>::iterator it = obj_checker.find(block_name_suffix);
@@ -1523,7 +1523,7 @@ TEST_F(TestLibRBD, TestCoR)
       obj_checker.erase(it);
     }
   }
-  rados_objects_list_close(list_ctx);
+  rados_nobjects_list_close(list_ctx);
   ASSERT_TRUE(obj_checker.empty());
   ASSERT_EQ(0, rbd_close(child));