]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test / rbd-mirror: image data pool test support
authorVenky Shankar <vshankar@redhat.com>
Thu, 10 Nov 2016 12:32:45 +0000 (18:02 +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/rbd_mirror/test_ClusterWatcher.cc
src/test/rbd_mirror/test_ImageReplayer.cc
src/test/rbd_mirror/test_PoolWatcher.cc
src/test/rbd_mirror/test_fixture.cc
src/test/rbd_mirror/test_fixture.h

index 204064ce35bee18eb28463a1727c3a3e2a2f42c7..111a973401a4da1d714c67d887f41ae14f75e9d5 100644 (file)
@@ -7,6 +7,7 @@
 #include "librbd/internal.h"
 #include "tools/rbd_mirror/ClusterWatcher.h"
 #include "tools/rbd_mirror/types.h"
+#include "test/rbd_mirror/test_fixture.h"
 #include "test/librados/test.h"
 #include "gtest/gtest.h"
 #include <boost/scope_exit.hpp>
@@ -25,7 +26,7 @@ using std::string;
 void register_test_cluster_watcher() {
 }
 
-class TestClusterWatcher : public ::testing::Test {
+class TestClusterWatcher : public ::rbd::mirror::TestFixture {
 public:
 
   TestClusterWatcher() : m_lock("TestClusterWatcherLock")
index 38bee88bee87bbfaa4eb5fc34913f1f2ee18fb72..535f36cef9489ee646e8b9255f0b6124b95390fc 100644 (file)
@@ -17,6 +17,7 @@
 #include "include/rados/librados.hpp"
 #include "include/rbd/librbd.hpp"
 #include "include/stringify.h"
+#include "test/rbd_mirror/test_fixture.h"
 #include "cls/journal/cls_journal_types.h"
 #include "cls/journal/cls_journal_client.h"
 #include "cls/rbd/cls_rbd_types.h"
@@ -48,7 +49,7 @@ void register_test_rbd_mirror() {
 #define TEST_IO_SIZE 512
 #define TEST_IO_COUNT 11
 
-class TestImageReplayer : public ::testing::Test {
+class TestImageReplayer : public ::rbd::mirror::TestFixture {
 public:
   struct C_WatchCtx : public librados::WatchCtx2 {
     TestImageReplayer *test;
index b73cdbfe0e2bc57e20f1eff72a7e1970e1a0f026..f2ae6090e3eadc263292d5ba639dcc3555b9f162 100644 (file)
@@ -3,6 +3,7 @@
 #include "include/rados/librados.hpp"
 #include "include/rbd/librbd.hpp"
 #include "include/stringify.h"
+#include "test/rbd_mirror/test_fixture.h"
 #include "cls/rbd/cls_rbd_types.h"
 #include "cls/rbd/cls_rbd_client.h"
 #include "include/rbd_types.h"
@@ -35,7 +36,7 @@ using std::string;
 void register_test_pool_watcher() {
 }
 
-class TestPoolWatcher : public ::testing::Test {
+class TestPoolWatcher : public ::rbd::mirror::TestFixture {
 public:
 
 TestPoolWatcher() : m_lock("TestPoolWatcherLock"),
index 9a13bda85a58dfc1b0cdec016da7f664bc817871..6e0a8954a0903c0db96201d17552e502e37a0546 100644 (file)
@@ -18,6 +18,7 @@ std::string TestFixture::_local_pool_name;
 std::string TestFixture::_remote_pool_name;
 std::shared_ptr<librados::Rados> TestFixture::_rados;
 uint64_t TestFixture::_image_number = 0;
+std::string TestFixture::_data_pool;
 
 TestFixture::TestFixture() {
 }
@@ -32,9 +33,18 @@ void TestFixture::SetUpTestCase() {
 
   _remote_pool_name = get_temp_pool_name("test-rbd-mirror-");
   ASSERT_EQ(0, _rados->pool_create(_remote_pool_name.c_str()));
+
+  ASSERT_EQ(0, create_image_data_pool(_data_pool));
+  if (!_data_pool.empty()) {
+    printf("using image data pool: %s\n", _data_pool.c_str());
+  }
 }
 
 void TestFixture::TearDownTestCase() {
+  if (!_data_pool.empty()) {
+    ASSERT_EQ(0, _rados->pool_delete(_data_pool.c_str()));
+  }
+
   ASSERT_EQ(0, _rados->pool_delete(_remote_pool_name.c_str()));
   ASSERT_EQ(0, _rados->pool_delete(_local_pool_name.c_str()));
   _rados->shutdown();
@@ -111,5 +121,23 @@ std::string TestFixture::get_temp_image_name() {
   return "image" + stringify(_image_number);
 }
 
+int TestFixture::create_image_data_pool(std::string &data_pool) {
+  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) {
+    data_pool = pool;
+    return 0;
+  }
+
+  return r;
+}
+
 } // namespace mirror
 } // namespace rbd
index c0ebd55d7d7fafde4c0a24a019186c5c30e46320..ce751409148867814b789d6eba9cea3ca3305a02 100644 (file)
@@ -39,6 +39,7 @@ public:
 
   Threads *m_threads = nullptr;
 
+
   int create_image(librbd::RBD &rbd, librados::IoCtx &ioctx,
                    const std::string &name, uint64_t size);
   int open_image(librados::IoCtx &io_ctx, const std::string &image_name,
@@ -48,11 +49,13 @@ public:
                   librados::snap_t *snap_id = nullptr);
 
   static std::string get_temp_image_name();
+  static int create_image_data_pool(std::string &data_pool);
 
   static std::string _local_pool_name;
   static std::string _remote_pool_name;
   static std::shared_ptr<librados::Rados> _rados;
   static uint64_t _image_number;
+  static std::string _data_pool;
 };
 
 } // namespace mirror