]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
neorados: Testing helpers
authorAdam C. Emerson <aemerson@redhat.com>
Sat, 22 Feb 2020 07:51:37 +0000 (02:51 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 15 May 2020 14:55:10 +0000 (10:55 -0400)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/test/neorados/CMakeLists.txt
src/test/neorados/common_tests.cc [new file with mode: 0644]
src/test/neorados/common_tests.h [new file with mode: 0644]

index 14760ab6e8c8d8b1b72b70348811582f493b3572..3466e85af3ab635601c2b23285ce40d5ef32f054 100644 (file)
@@ -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 (file)
index 0000000..4e4b6c0
--- /dev/null
@@ -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 <aemerson@redhat.com>
+ *
+ * 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 <cstring>
+#include <string>
+#include <string_view>
+
+#include <boost/asio/ip/host_name.hpp>
+
+#include <fmt/format.h>
+
+#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 (file)
index 0000000..0d672f0
--- /dev/null
@@ -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 <aemerson@redhat.com>
+ *
+ * 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 <string>
+#include <string_view>
+
+#include "include/neorados/RADOS.hpp"
+
+std::string get_temp_pool_name(std::string_view prefix = {});
+
+template<typename CompletionToken>
+auto create_pool(neorados::RADOS& r, std::string_view pname,
+                CompletionToken&& token)
+{
+  boost::asio::async_completion<CompletionToken,
+                               void(boost::system::error_code,
+                                    std::int64_t)> 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();
+}