From: Adam C. Emerson Date: Sat, 22 Feb 2020 07:51:37 +0000 (-0500) Subject: neorados: Testing helpers X-Git-Tag: v17.0.0~2298^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0ed4843b24f35855a14430e166d5350188859cae;p=ceph.git neorados: Testing helpers Signed-off-by: Adam C. Emerson --- diff --git a/src/test/neorados/CMakeLists.txt b/src/test/neorados/CMakeLists.txt index 14760ab6e8c8d..3466e85af3ab6 100644 --- a/src/test/neorados/CMakeLists.txt +++ b/src/test/neorados/CMakeLists.txt @@ -8,3 +8,7 @@ target_link_libraries(ceph_test_neorados_completions Boost::system pthread add_executable(ceph_test_neorados_op_speed op_speed.cc) target_link_libraries(ceph_test_neorados_op_speed libneorados fmt::fmt ${unittest_libs}) + +add_library(neoradostest-support common_tests.cc) +target_link_libraries(neoradostest-support + libneorados fmt::fmt) diff --git a/src/test/neorados/common_tests.cc b/src/test/neorados/common_tests.cc new file mode 100644 index 0000000000000..4e4b6c0af14c8 --- /dev/null +++ b/src/test/neorados/common_tests.cc @@ -0,0 +1,34 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2020 Red Hat, Inc. + * Author: Adam C. Emerson + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#include +#include +#include + +#include + +#include + +#include "common_tests.h" +#include "include/neorados/RADOS.hpp" + +namespace ba = boost::asio; +namespace R = neorados; + +std::string get_temp_pool_name(std::string_view prefix) +{ + static auto hostname = ba::ip::host_name(); + static auto num = 1ull; + return fmt::format("{}{}-{}-{}", prefix, hostname, getpid(), num++); +} diff --git a/src/test/neorados/common_tests.h b/src/test/neorados/common_tests.h new file mode 100644 index 0000000000000..0d672f02f813b --- /dev/null +++ b/src/test/neorados/common_tests.h @@ -0,0 +1,41 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2020 Red Hat, Inc. + * Author: Adam C. Emerson + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + */ + +#include +#include + +#include "include/neorados/RADOS.hpp" + +std::string get_temp_pool_name(std::string_view prefix = {}); + +template +auto create_pool(neorados::RADOS& r, std::string_view pname, + CompletionToken&& token) +{ + boost::asio::async_completion init(token); + r.create_pool(pname, std::nullopt, + [&r, pname = std::string(pname), + h = std::move(init.completion_handler)] + (boost::system::error_code ec) mutable { + r.lookup_pool( + pname, + [&r, h = std::move(h)] + (boost::system::error_code ec, std::int64_t pool) mutable { + std::move(h)(ec, pool); + }); + }); + return init.result.get(); +}