From: Venky Shankar Date: Thu, 10 Nov 2016 12:32:45 +0000 (+0530) Subject: test / rbd-mirror: image data pool test support X-Git-Tag: v11.1.0~219^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e98b8ceb8678326579283241505595c078247770;p=ceph-ci.git test / rbd-mirror: image data pool test support Signed-off-by: Venky Shankar --- diff --git a/src/test/rbd_mirror/test_ClusterWatcher.cc b/src/test/rbd_mirror/test_ClusterWatcher.cc index 204064ce35b..111a973401a 100644 --- a/src/test/rbd_mirror/test_ClusterWatcher.cc +++ b/src/test/rbd_mirror/test_ClusterWatcher.cc @@ -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 @@ -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") diff --git a/src/test/rbd_mirror/test_ImageReplayer.cc b/src/test/rbd_mirror/test_ImageReplayer.cc index 38bee88bee8..535f36cef94 100644 --- a/src/test/rbd_mirror/test_ImageReplayer.cc +++ b/src/test/rbd_mirror/test_ImageReplayer.cc @@ -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; diff --git a/src/test/rbd_mirror/test_PoolWatcher.cc b/src/test/rbd_mirror/test_PoolWatcher.cc index b73cdbfe0e2..f2ae6090e3e 100644 --- a/src/test/rbd_mirror/test_PoolWatcher.cc +++ b/src/test/rbd_mirror/test_PoolWatcher.cc @@ -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"), diff --git a/src/test/rbd_mirror/test_fixture.cc b/src/test/rbd_mirror/test_fixture.cc index 9a13bda85a5..6e0a8954a09 100644 --- a/src/test/rbd_mirror/test_fixture.cc +++ b/src/test/rbd_mirror/test_fixture.cc @@ -18,6 +18,7 @@ std::string TestFixture::_local_pool_name; std::string TestFixture::_remote_pool_name; std::shared_ptr 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 diff --git a/src/test/rbd_mirror/test_fixture.h b/src/test/rbd_mirror/test_fixture.h index c0ebd55d7d7..ce751409148 100644 --- a/src/test/rbd_mirror/test_fixture.h +++ b/src/test/rbd_mirror/test_fixture.h @@ -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 _rados; static uint64_t _image_number; + static std::string _data_pool; }; } // namespace mirror