Skip to content

Commit

Permalink
tests: librbd API test cannot use private md_config_t struct
Browse files Browse the repository at this point in the history
Remove all depencencies on md_config_t and instead use librados API
methods to get/set configuration values.

Fixes: #12479
Backport: hammer
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed Jul 30, 2015
1 parent 4d03c66 commit 2c51aad
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
3 changes: 1 addition & 2 deletions src/test/Makefile-client.am
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ ceph_test_librbd_api_SOURCES = \
test/librbd/test_main.cc
ceph_test_librbd_api_CXXFLAGS = $(UNITTEST_CXXFLAGS)
ceph_test_librbd_api_LDADD = \
$(LIBRBD) $(LIBRADOS) $(UNITTEST_LDADD) \
$(CEPH_GLOBAL) $(RADOS_TEST_LDADD)
$(LIBRBD) $(LIBRADOS) $(LIBCOMMON) $(UNITTEST_LDADD) $(RADOS_TEST_LDADD)
bin_DEBUGPROGRAMS += ceph_test_librbd_api

if WITH_LTTNG
Expand Down
46 changes: 26 additions & 20 deletions src/test/librbd/test_librbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#include "include/rbd/librbd.h"
#include "include/rbd/librbd.hpp"

#include "global/global_context.h"
#include "global/global_init.h"
#include "common/ceph_argparse.h"
#include "common/config.h"
#include "common/Thread.h"

#include "gtest/gtest.h"
Expand Down Expand Up @@ -85,9 +81,11 @@ static int create_image_full(rados_ioctx_t ioctx, const char *name,
{
if (old_format) {
// ensure old-format tests actually use the old format
CephContext *cct = reinterpret_cast<CephContext*>(rados_ioctx_cct(ioctx));
cct->_conf->set_val_or_die("rbd_default_format", "1");

int r = rados_conf_set(rados_ioctx_get_cluster(ioctx),
"rbd_default_format", "1");
if (r < 0) {
return r;
}
return rbd_create(ioctx, name, size, order);
} else if ((features & RBD_FEATURE_STRIPINGV2) != 0) {
return rbd_create3(ioctx, name, size, features, order, 65536, 16);
Expand Down Expand Up @@ -118,10 +116,11 @@ static int create_image_pp(librbd::RBD &rbd,
if (r < 0)
return r;
if (old_format) {
// ensure old-format tests actually use the old format
CephContext *cct = reinterpret_cast<CephContext*>(ioctx.cct());
cct->_conf->set_val_or_die("rbd_default_format", "1");

librados::Rados rados(ioctx);
int r = rados.conf_set("rbd_default_format", "1");
if (r < 0) {
return r;
}
return rbd.create(ioctx, name, size, order);
} else {
return rbd.create2(ioctx, name, size, features, order);
Expand Down Expand Up @@ -1450,7 +1449,9 @@ TEST_F(TestLibRBD, TestClone2)

TEST_F(TestLibRBD, TestCoR)
{
if (!g_conf->rbd_clone_copy_on_read) {
std::string config_value;
ASSERT_EQ(0, _rados.conf_get("rbd_clone_copy_on_read", config_value));
if (config_value == "false") {
std::cout << "SKIPPING due to disabled rbd_copy_on_read" << std::endl;
return;
}
Expand Down Expand Up @@ -2479,25 +2480,31 @@ TEST_F(TestLibRBD, ZeroLengthRead)

TEST_F(TestLibRBD, LargeCacheRead)
{
if (!g_conf->rbd_cache) {
std::string config_value;
ASSERT_EQ(0, _rados.conf_get("rbd_cache", config_value));
if (config_value == "false") {
std::cout << "SKIPPING due to disabled cache" << std::endl;
return;
}

rados_ioctx_t ioctx;
rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx);

uint64_t orig_cache_size = g_conf->rbd_cache_size;
g_conf->set_val("rbd_cache_size", "16777216");
uint32_t new_cache_size = 16777216;
std::string orig_cache_size;
ASSERT_EQ(0, _rados.conf_get("rbd_cache_size", orig_cache_size));
ASSERT_EQ(0, _rados.conf_set("rbd_cache_size",
stringify(new_cache_size).c_str()));
ASSERT_EQ(0, _rados.conf_get("rbd_cache_size", config_value));
ASSERT_EQ(stringify(new_cache_size), config_value);
BOOST_SCOPE_EXIT( (orig_cache_size) ) {
g_conf->set_val("rbd_cache_size", stringify(orig_cache_size).c_str());
ASSERT_EQ(0, _rados.conf_set("rbd_cache_size", orig_cache_size.c_str()));
} BOOST_SCOPE_EXIT_END;
ASSERT_EQ(16777216, g_conf->rbd_cache_size);

rbd_image_t image;
int order = 0;
const char *name = "testimg";
uint64_t size = g_conf->rbd_cache_size + 1;
uint64_t size = new_cache_size + 1;

ASSERT_EQ(0, create_image(ioctx, name, size, &order));
ASSERT_EQ(0, rbd_open(ioctx, name, &image, NULL));
Expand Down Expand Up @@ -3006,8 +3013,7 @@ TEST_F(TestLibRBD, BlockingAIO)
int order = 18;
ASSERT_EQ(0, create_image_pp(rbd, ioctx, name.c_str(), size, &order));

CephContext *cct = reinterpret_cast<CephContext*>(ioctx.cct());
cct->_conf->set_val_or_die("rbd_non_blocking_aio", "0");
ASSERT_EQ(0, _rados.conf_set("rbd_non_blocking_aio", "0"));

librbd::Image image;
ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), NULL));
Expand Down
33 changes: 20 additions & 13 deletions src/test/librbd/test_main.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "gtest/gtest.h"
#include "common/ceph_argparse.h"
#include "common/config.h"
#include "include/rados/librados.hpp"
#include "global/global_context.h"
#include "global/global_init.h"
#include <vector>
#include "test/librados/test.h"
#include "gtest/gtest.h"
#include <iostream>
#include <string>

extern void register_test_librbd();
#ifdef TEST_LIBRBD_INTERNALS
Expand All @@ -26,14 +26,21 @@ int main(int argc, char **argv)

::testing::InitGoogleTest(&argc, argv);

vector<const char*> args;
argv_to_vec(argc, (const char **)argv, args);
librados::Rados rados;
std::string result = connect_cluster_pp(rados);
if (result != "" ) {
std::cerr << result << std::endl;
return 1;
}

global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
g_conf->set_val("lockdep", "true");
common_init_finish(g_ceph_context);
#ifdef TEST_LIBRBD_INTERNALS
g_ceph_context = reinterpret_cast<CephContext*>(rados.cct());
#endif // TEST_LIBRBD_INTERNALS

int r = RUN_ALL_TESTS();
g_ceph_context->put();
return r;
int r = rados.conf_set("lockdep", "true");
if (r < 0) {
std::cerr << "failed to enable lockdep" << std::endl;
return -r;
}
return RUN_ALL_TESTS();
}

0 comments on commit 2c51aad

Please sign in to comment.