]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test / librbd: image data pool test support
authorVenky Shankar <vshankar@redhat.com>
Tue, 8 Nov 2016 11:29:14 +0000 (16:59 +0530)
committerVenky Shankar <vshankar@redhat.com>
Sun, 20 Nov 2016 15:51:50 +0000 (21:21 +0530)
Signed-off-by: Venky Shankar <vshankar@redhat.com>
src/test/librbd/test_fixture.cc
src/test/librbd/test_fixture.h
src/test/librbd/test_librbd.cc
src/test/librbd/test_support.cc
src/test/librbd/test_support.h

index 82e7408ff88979030ff72616435fc6d0ffb92425..604e9bef41f3e4d0182edd5c909472ad597b6772 100644 (file)
@@ -20,6 +20,7 @@
 std::string TestFixture::_pool_name;
 librados::Rados TestFixture::_rados;
 uint64_t TestFixture::_image_number = 0;
+std::string TestFixture::_data_pool;
 
 TestFixture::TestFixture() : m_image_size(0) {
 }
@@ -27,9 +28,22 @@ TestFixture::TestFixture() : m_image_size(0) {
 void TestFixture::SetUpTestCase() {
   _pool_name = get_temp_pool_name("test-librbd-");
   ASSERT_EQ("", create_one_pool_pp(_pool_name, _rados));
+
+  bool created = false;
+  ASSERT_EQ(0, create_image_data_pool(_rados, _data_pool, &created));
+  if (!_data_pool.empty()) {
+    printf("using image data pool: %s\n", _data_pool.c_str());
+    if (!created) {
+      _data_pool.clear();
+    }
+  }
 }
 
 void TestFixture::TearDownTestCase() {
+  if (!_data_pool.empty()) {
+    ASSERT_EQ(0, _rados.pool_delete(_data_pool.c_str()));
+  }
+
   ASSERT_EQ(0, destroy_one_pool_pp(_pool_name, _rados));
 }
 
index a6fa6af77b76a0dcd6c3e5b1d7e1097a0e87f485..2fbeaf91f89a8164ec00713cb9f2d3d13e7e5274 100644 (file)
@@ -40,6 +40,7 @@ public:
   static std::string _pool_name;
   static librados::Rados _rados;
   static uint64_t _image_number;
+  static std::string _data_pool;
 
   librados::IoCtx m_ioctx;
   librbd::RBD m_rbd;
index 24015173e068dbe24bdb9662ecf8d988c3bcec83..2e67032a122fec5668aab0a7ac04b30c843419b4 100644 (file)
@@ -161,6 +161,8 @@ public:
     _image_number = 0;
     ASSERT_EQ("", connect_cluster(&_cluster));
     ASSERT_EQ("", connect_cluster_pp(_rados));
+
+    create_optional_data_pool();
   }
 
   static void TearDownTestCase() {
@@ -197,6 +199,18 @@ public:
     return "image" + stringify(_image_number);
   }
 
+  static void create_optional_data_pool() {
+    bool created = false;
+    std::string data_pool;
+    ASSERT_EQ(0, create_image_data_pool(_rados, data_pool, &created));
+    if (!data_pool.empty()) {
+      printf("using image data pool: %s\n", data_pool.c_str());
+      if (created) {
+        _unique_pool_names.push_back(data_pool);
+      }
+    }
+  }
+
   std::string create_pool(bool unique = false) {
     librados::Rados rados;
     std::string pool_name;
index e9f63bd2cda3312209504a75ef235c2189da5381..da29338eb3b373c08362296f525a9f0e3282a70e 100644 (file)
@@ -48,3 +48,21 @@ int get_image_id(librbd::Image &image, std::string *image_id)
   return 0;
 }
 
+int create_image_data_pool(librados::Rados &rados, std::string &data_pool, bool *created) {
+  std::string pool;
+  int r = rados.conf_get("rbd_default_data_pool", pool);
+  if (r != 0) {
+    return r;
+  } else if (pool.empty()) {
+    return 0;
+  }
+
+  r = rados.pool_create(pool.c_str());
+  if ((r == 0) || (r == -EEXIST)) {
+    data_pool = pool;
+    *created = (r == 0);
+    return 0;
+  }
+
+  return r;
+}
index bce931ad91c3eab8ecc8e2687921129aa8c61d10..243850a87c2439f3e74879bb49d51882fce24ad4 100644 (file)
@@ -10,6 +10,7 @@ bool is_feature_enabled(uint64_t feature);
 int create_image_pp(librbd::RBD &rbd, librados::IoCtx &ioctx,
                     const std::string &name, uint64_t size);
 int get_image_id(librbd::Image &image, std::string *image_id);
+int create_image_data_pool(librados::Rados &rados, std::string &data_pool, bool *created);
 
 #define REQUIRE(x) {                     \
   if (!(x)) {                            \