From 3d3d0fb31e0f43e910718fe7ec9222b0db292409 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Tue, 8 Nov 2016 16:59:14 +0530 Subject: [PATCH] test / librbd: image data pool test support Signed-off-by: Venky Shankar --- src/test/librbd/test_fixture.cc | 14 ++++++++++++++ src/test/librbd/test_fixture.h | 1 + src/test/librbd/test_librbd.cc | 14 ++++++++++++++ src/test/librbd/test_support.cc | 18 ++++++++++++++++++ src/test/librbd/test_support.h | 1 + 5 files changed, 48 insertions(+) diff --git a/src/test/librbd/test_fixture.cc b/src/test/librbd/test_fixture.cc index 82e7408ff88..604e9bef41f 100644 --- a/src/test/librbd/test_fixture.cc +++ b/src/test/librbd/test_fixture.cc @@ -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)); } diff --git a/src/test/librbd/test_fixture.h b/src/test/librbd/test_fixture.h index a6fa6af77b7..2fbeaf91f89 100644 --- a/src/test/librbd/test_fixture.h +++ b/src/test/librbd/test_fixture.h @@ -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; diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 24015173e06..2e67032a122 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -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; diff --git a/src/test/librbd/test_support.cc b/src/test/librbd/test_support.cc index e9f63bd2cda..da29338eb3b 100644 --- a/src/test/librbd/test_support.cc +++ b/src/test/librbd/test_support.cc @@ -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; +} diff --git a/src/test/librbd/test_support.h b/src/test/librbd/test_support.h index bce931ad91c..243850a87c2 100644 --- a/src/test/librbd/test_support.h +++ b/src/test/librbd/test_support.h @@ -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)) { \ -- 2.39.5