Skip to content

Commit

Permalink
test/neorados: Rounding out test coverage, part 1
Browse files Browse the repository at this point in the history
This includes cls, cmd, and read_operations.

Signed-off-by: Adam Emerson <[email protected]>
  • Loading branch information
adamemerson committed Dec 7, 2023
1 parent 3775d7e commit ef49105
Show file tree
Hide file tree
Showing 4 changed files with 1,009 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/neorados/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,51 @@ target_link_libraries(ceph_test_neorados_handler_error
install(TARGETS
ceph_test_neorados_handler_error
DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(ceph_test_neorados_cls
cls.cc
)
target_link_libraries(ceph_test_neorados_cls
libneorados
${BLKID_LIBRARIES}
${CMAKE_DL_LIBS}
${CRYPTO_LIBS}
${EXTRALIBS}
neoradostest-support
${UNITTEST_LIBS}
)
install(TARGETS
ceph_test_neorados_cls
DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(ceph_test_neorados_cmd
cmd.cc
)
target_link_libraries(ceph_test_neorados_cmd
libneorados
${BLKID_LIBRARIES}
${CMAKE_DL_LIBS}
${CRYPTO_LIBS}
${EXTRALIBS}
neoradostest-support
${UNITTEST_LIBS}
)
install(TARGETS
ceph_test_neorados_cmd
DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(ceph_test_neorados_read_operations
read_operations.cc
)
target_link_libraries(ceph_test_neorados_read_operations
libneorados
${BLKID_LIBRARIES}
${CMAKE_DL_LIBS}
${CRYPTO_LIBS}
${EXTRALIBS}
neoradostest-support
${UNITTEST_LIBS}
)
install(TARGETS
ceph_test_neorados_read_operations
DESTINATION ${CMAKE_INSTALL_BINDIR})
97 changes: 97 additions & 0 deletions src/test/neorados/cls.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// -*- 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) 2023 IBM
*
* See file COPYING for license information.
*
*/

#include <array>
#include <coroutine>
#include <memory>
#include <string_view>
#include <utility>

#include <boost/asio/use_awaitable.hpp>

#include <boost/system/errc.hpp>

#include "include/neorados/RADOS.hpp"

#include "common/ceph_json.h"

#include "test/neorados/common_tests.h"

#include "gtest/gtest.h"

namespace asio = boost::asio;
namespace sys = boost::system;

using namespace std::literals;

using neorados::ReadOp;
using neorados::WriteOp;

CORO_TEST_F(NeoRadosCls, DNE, NeoRadosTest)
{
std::string_view oid = "obj";
co_await execute(oid, WriteOp{}.create(true));
// Call a bogus class
co_await expect_error_code(
execute(oid, ReadOp{}.exec("doesnotexistasdfasdf", "method", {})),
sys::errc::operation_not_supported);

// Call a bogus method on an existent class
co_await expect_error_code(
execute(oid, ReadOp{}.exec("lock", "doesnotexistasdfasdfasdf", {})),
sys::errc::operation_not_supported);
co_return;
}

CORO_TEST_F(NeoRadosCls, RemoteReads, NeoRadosTest)
{
static constexpr std::size_t object_size = 4096;
static constexpr std::array oids{"src_object.1"sv, "src_object.2"sv,
"src_object.3"sv};

std::array<char, object_size> buf;
buf.fill(1);

for (const auto& oid : oids) {
buffer::list in;
in.append(buf.data(), buf.size());
co_await execute(oid, WriteOp{}.write_full(std::move(in)));
}

// Construct JSON request passed to "test_gather" method, and in
// turn, to "test_read" method
buffer::list in;
{
auto formatter = std::make_unique<JSONFormatter>(true);
formatter->open_object_section("foo");
encode_json("src_objects", oids, formatter.get());
encode_json("cls", "test_remote_reads", formatter.get());
encode_json("method", "test_read", formatter.get());
encode_json("pool", pool_name(), formatter.get());
formatter->close_section();
formatter->flush(in);
}

static const auto target = "tgt_object"s;

// Create target object by combining data gathered from source
// objects using "test_read" method
co_await execute(target,
WriteOp{}.exec("test_remote_reads", "test_gather", in));


// Read target object and check its size.
buffer::list out;
co_await execute(target, ReadOp{}.read(0, 0, &out));
EXPECT_EQ(3 * object_size, out.length());

co_return;
}
116 changes: 116 additions & 0 deletions src/test/neorados/cmd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// -*- 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) 2023 IBM
*
* See file COPYING for license information.
*
*/

#include <array>
#include <coroutine>

#include <fmt/format.h>

#include <boost/asio/as_tuple.hpp>
#include <boost/asio/use_awaitable.hpp>

#include <boost/system/errc.hpp>

#include "include/neorados/RADOS.hpp"

#include "include/stringify.h"

#include "test/neorados/common_tests.h"

#include "gtest/gtest.h"

namespace asio = boost::asio;
namespace sys = boost::system;
namespace buffer = ceph::buffer;

using neorados::ReadOp;

using namespace std::literals;

CORO_TEST_F(NeoRadosCmd, MonDescribe, NeoRadosTest) {
std::string outs;
buffer::list outbl;
std::vector arg({R"({"prefix": "get_command_descriptions"})"s});
co_await rados().mon_command(std::move(arg), {}, &outs, &outbl,
asio::use_awaitable);
EXPECT_LT(0u, outbl.length());
EXPECT_LE(0u, outs.length());
co_return;
}

CORO_TEST_F(NeoRadosCmd, OSDCmd, NeoRadosTest) {
{
std::vector arg({R"(asdfasdf)"s});
co_await expect_error_code(
rados().osd_command(0, std::move(arg),
{}, asio::use_awaitable),
sys::errc::invalid_argument, sys::errc::no_such_device_or_address);
}

{
std::vector arg({R"(version)"s});
co_await expect_error_code(
rados().osd_command(0, std::move(arg),
{}, asio::use_awaitable),
sys::errc::invalid_argument, sys::errc::no_such_device_or_address);
}

{
std::vector arg({R"({"prefix":"version"})"s});
auto [ec, outs, outbl] = co_await
rados().osd_command(0, std::move(arg), {},
asio::as_tuple(asio::use_awaitable));

EXPECT_TRUE((!ec && outbl.length() > 0) ||
(ec == sys::errc::no_such_device_or_address &&
outbl.length() == 0));

}
co_return;
}

CORO_TEST_F(NeoRadosCmd, PGCmd, NeoRadosTest) {
const neorados::PG pgid{uint64_t(pool().get_pool()), 0};

{
std::vector arg({R"(asdfasdf)"s});
// note: tolerate NXIO here in case the cluster is thrashing out underneath us.
co_await expect_error_code(
rados().pg_command(pgid, std::move(arg),
{}, asio::use_awaitable),
sys::errc::invalid_argument, sys::errc::no_such_device_or_address);
}

// make sure the pg exists on the osd before we query it
for (auto i = 0; i < 100; ++i) {
co_await expect_error_code(
rados().execute(fmt::format("obj{}", i), pool(),
ReadOp{}.assert_exists(), nullptr,
asio::use_awaitable),
sys::errc::no_such_file_or_directory);
}

{
std::vector arg({fmt::format(R"({{"prefix":"pg", "cmd":"query", "pgid":"{}.{}"}})",
pgid.pool, pgid.seed)});
// Working around a bug in GCC.
auto coro = rados().pg_command(pgid, std::move(arg),
{}, asio::as_tuple(asio::use_awaitable));
auto [ec, outs, outbl] = co_await std::move(coro);

EXPECT_TRUE(!ec || ec == sys::errc::no_such_file_or_directory ||
ec == sys::errc::no_such_device_or_address);

EXPECT_LT(0u, outbl.length());
}

co_return;
}
Loading

0 comments on commit ef49105

Please sign in to comment.