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) {
}
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));
}
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;
_image_number = 0;
ASSERT_EQ("", connect_cluster(&_cluster));
ASSERT_EQ("", connect_cluster_pp(_rados));
+
+ create_optional_data_pool();
}
static void TearDownTestCase() {
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;
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;
+}
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)) { \