Skip to content

Commit

Permalink
ceph_test_rados_io_pp: Add cxx test for append zero test
Browse files Browse the repository at this point in the history
1. adding allow_ec_overwrite option for cxx test
2. adding new test for crc failuer check with append zero length

Fixes: https://tracker.ceph.com/issues/53240
Signed-off-by: Nitzan Mordechai <[email protected]>
  • Loading branch information
NitzanMordhai committed May 19, 2024
1 parent 6662e6b commit 06e4c6f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/test/librados/io_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,18 @@ TEST_F(LibRadosIoPP, XattrListPP) {
}
}

TEST_F(LibRadosIoPP, CrcZeroWrite) {
char buf[128];
bufferlist bl;

ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0));
ASSERT_EQ(0, ioctx.write("foo", bl, 0, sizeof(buf)));

ObjectReadOperation read;
read.read(0, bl.length(), NULL, NULL);
ASSERT_EQ(0, ioctx.operate("foo", &read, &bl));
}

TEST_F(LibRadosIoECPP, SimpleWritePP) {
SKIP_IF_CRIMSON();
char buf[128];
Expand Down Expand Up @@ -865,6 +877,22 @@ TEST_F(LibRadosIoECPP, RmXattrPP) {
ASSERT_EQ(-ENOENT, ioctx.rmxattr("foo_rmxattr", attr2));
}

TEST_F(LibRadosIoECPP, CrcZeroWrite) {
SKIP_IF_CRIMSON();
set_allow_ec_overwrites(pool_name, true);
char buf[128];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;

ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0));
ASSERT_EQ(0, ioctx.write("foo", bl, 0, sizeof(buf)));

ObjectReadOperation read;
read.read(0, bl.length(), NULL, NULL);
ASSERT_EQ(0, ioctx.operate("foo", &read, &bl));
recreate_pool();
}

TEST_F(LibRadosIoECPP, XattrListPP) {
SKIP_IF_CRIMSON();
char buf[128];
Expand Down
15 changes: 15 additions & 0 deletions src/test/librados/test_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ std::string create_one_ec_pool_pp(const std::string &pool_name, Rados &cluster)
return "";
}

std::string set_allow_ec_overwrites_pp(const std::string &pool_name, Rados &cluster, bool allow)
{
std::ostringstream oss;
bufferlist inbl;
int ret = cluster.mon_command(
"{\"prefix\": \"osd pool set\", \"pool\": \"" + pool_name + "\", \"var\": \"allow_ec_overwrites\", \"val\": \"" + (allow ? "true" : "false") + "\"}",
inbl, NULL, NULL);
if (ret) {
cluster.shutdown();
oss << "mon_command osd pool set pool:" << pool_name << " pool_type:erasure allow_ec_overwrites true failed with error " << ret;
return oss.str();
}
return "";
}

std::string connect_cluster_pp(librados::Rados &cluster)
{
return connect_cluster_pp(cluster, {});
Expand Down
2 changes: 2 additions & 0 deletions src/test/librados/test_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ std::string create_one_pool_pp(const std::string &pool_name,
const std::map<std::string, std::string> &config);
std::string create_one_ec_pool_pp(const std::string &pool_name,
librados::Rados &cluster);
std::string set_allow_ec_overwrites_pp(const std::string &pool_name,
librados::Rados &cluster, bool allow);
std::string connect_cluster_pp(librados::Rados &cluster);
std::string connect_cluster_pp(librados::Rados &cluster,
const std::map<std::string, std::string> &config);
Expand Down
13 changes: 12 additions & 1 deletion src/test/librados/testcase_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ Rados RadosTestPP::s_cluster;
void RadosTestPP::SetUpTestCase()
{
init_rand();

auto pool_prefix = fmt::format("{}_", ::testing::UnitTest::GetInstance()->current_test_case()->name());
pool_name = get_temp_pool_name(pool_prefix);
ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster));
Expand Down Expand Up @@ -405,3 +404,15 @@ void RadosTestECPP::TearDown()
ioctx.close();
}

void RadosTestECPP::recreate_pool()
{
SKIP_IF_CRIMSON();
ASSERT_EQ(0, destroy_one_ec_pool_pp(pool_name, s_cluster));
ASSERT_EQ("", create_one_ec_pool_pp(pool_name, s_cluster));
SetUp();
}

void RadosTestECPP::set_allow_ec_overwrites(std::string pool, bool allow)
{
ASSERT_EQ("", set_allow_ec_overwrites_pp(pool, cluster, allow));
}
2 changes: 2 additions & 0 deletions src/test/librados/testcase_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class RadosTestECPP : public RadosTestPP {
protected:
static void SetUpTestCase();
static void TearDownTestCase();
void recreate_pool();
void set_allow_ec_overwrites(std::string pool, bool allow=true);
static librados::Rados s_cluster;
static std::string pool_name;

Expand Down

0 comments on commit 06e4c6f

Please sign in to comment.