Skip to content

Commit

Permalink
test / rbd-mirror: image data pool test support
Browse files Browse the repository at this point in the history
Signed-off-by: Venky Shankar <vshankar@redhat.com>
  • Loading branch information
vshankar committed Nov 15, 2016
1 parent 95be32f commit 9d1b605
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/test/rbd_mirror/test_ClusterWatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion src/test/rbd_mirror/test_ImageReplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/test/rbd_mirror/test_PoolWatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"),
Expand Down
28 changes: 28 additions & 0 deletions src/test/rbd_mirror/test_fixture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand All @@ -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();
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/test/rbd_mirror/test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TestFixture : public ::testing::Test {

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,
Expand All @@ -48,11 +49,13 @@ class TestFixture : public ::testing::Test {
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
Expand Down

0 comments on commit 9d1b605

Please sign in to comment.