From 8d4a5fd5d6c868aeaaaa6d4356b5da4c8c912e34 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Sun, 2 Feb 2014 14:32:13 -0800 Subject: [PATCH] test/librados: add a connect_cluster() helper This mirrors the c++ version, connect_cluster_pp(), and removes the same code from create_one_pool(). Signed-off-by: Josh Durgin --- src/test/librados/test.cc | 60 ++++++++++++++++++++++++--------------- src/test/librados/test.h | 1 + 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/test/librados/test.cc b/src/test/librados/test.cc index a1aa24c736c18..30bb5b50c80cb 100644 --- a/src/test/librados/test.cc +++ b/src/test/librados/test.cc @@ -1,3 +1,6 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -* +// vim: ts=8 sw=2 smarttab + #include "include/rados/librados.h" #include "include/rados/librados.hpp" #include "test/librados/test.h" @@ -27,29 +30,10 @@ std::string get_temp_pool_name() std::string create_one_pool(const std::string &pool_name, rados_t *cluster) { - int ret; - ret = rados_create(cluster, NULL); - if (ret) { - std::ostringstream oss; - oss << "rados_create failed with error " << ret; - return oss.str(); - } - ret = rados_conf_read_file(*cluster, NULL); - if (ret) { - rados_shutdown(*cluster); - std::ostringstream oss; - oss << "rados_conf_read_file failed with error " << ret; - return oss.str(); - } - rados_conf_parse_env(*cluster, NULL); - ret = rados_connect(*cluster); - if (ret) { - rados_shutdown(*cluster); - std::ostringstream oss; - oss << "rados_connect failed with error " << ret; - return oss.str(); - } - ret = rados_pool_create(*cluster, pool_name.c_str()); + std::string err = connect_cluster(cluster); + if (err.length()) + return err; + int ret = rados_pool_create(*cluster, pool_name.c_str()); if (ret) { rados_shutdown(*cluster); std::ostringstream oss; @@ -96,6 +80,36 @@ std::string create_one_pool_pp(const std::string &pool_name, Rados &cluster) return ""; } +std::string connect_cluster(rados_t *cluster) +{ + char *id = getenv("CEPH_CLIENT_ID"); + if (id) std::cerr << "Client id is: " << id << std::endl; + + int ret; + ret = rados_create(cluster, NULL); + if (ret) { + std::ostringstream oss; + oss << "rados_create failed with error " << ret; + return oss.str(); + } + ret = rados_conf_read_file(*cluster, NULL); + if (ret) { + rados_shutdown(*cluster); + std::ostringstream oss; + oss << "rados_conf_read_file failed with error " << ret; + return oss.str(); + } + rados_conf_parse_env(*cluster, NULL); + ret = rados_connect(*cluster); + if (ret) { + rados_shutdown(*cluster); + std::ostringstream oss; + oss << "rados_connect failed with error " << ret; + return oss.str(); + } + return ""; +} + std::string connect_cluster_pp(Rados &cluster) { char *id = getenv("CEPH_CLIENT_ID"); diff --git a/src/test/librados/test.h b/src/test/librados/test.h index df27ba0a68732..652c235972bc4 100644 --- a/src/test/librados/test.h +++ b/src/test/librados/test.h @@ -26,6 +26,7 @@ std::string get_temp_pool_name(); std::string create_one_pool(const std::string &pool_name, rados_t *cluster); std::string create_one_pool_pp(const std::string &pool_name, librados::Rados &cluster); +std::string connect_cluster(rados_t *cluster); std::string connect_cluster_pp(librados::Rados &cluster); int destroy_one_pool(const std::string &pool_name, rados_t *cluster); int destroy_one_pool_pp(const std::string &pool_name, librados::Rados &cluster); -- 2.39.5