Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arrow cls tests #73

Merged
merged 29 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .popper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ steps:
mkdir -p build/
cd build/
cmake ..
make
make VERBOSE=1
ivotron marked this conversation as resolved.
Show resolved Hide resolved

- id: test
uses: ./docker/builder
runs: [bash, -euxc]
args:
- |
cp build/lib/libcls_cls_sdk.so* /usr/lib64/rados-classes/
scripts/micro-osd.sh test-cluster /etc/ceph
build/bin/cls_sdk_test
33 changes: 33 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -e

echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
source /etc/profile

if [ -d "ceph/" ]; then
echo "Using ceph/ as folder as source folder"
CEPH_SRC_DIR="ceph"
else
echo "No CEPH_SRC_DIR variable defined, using current directory"
CEPH_SRC_DIR="./"
fi

cd "$CEPH_SRC_DIR"

if [ "$CMAKE_CLEAN" == "true" ] || [ "$CMAKE_CLEAN" == "1" ]; then
rm -rf ./build
fi

mkdir -p ./build

cd build/

if [ -z "$(ls -A ./)" ] || [ "$CMAKE_RECONFIGURE" == "true" ] || [ "$CMAKE_RECONFIGURE" == "1" ]; then
cmake3 $CMAKE_FLAGS ..
fi

if [ -z "$BUILD_THREADS" ] ; then
BUILD_THREADS=`grep processor /proc/cpuinfo | wc -l`
fi

make -j$BUILD_THREADS
76 changes: 76 additions & 0 deletions scripts/micro-osd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
set -e
set -u
set -x

TEST_DIR=$1
CONF_DIR=$2
echo "TEST_DIR=${TEST_DIR}"
echo "CONF_DIR=${CONF_DIR}"
echo "pwd="`pwd`

# get rid of process and directories leftovers
pkill ceph-mon || true
pkill ceph-osd || true
rm -fr $TEST_DIR

# cluster wide parameters
mkdir -p ${TEST_DIR}/log
cat >> $CONF_DIR/ceph.conf <<EOF
[global]
fsid = $(uuidgen)
osd crush chooseleaf type = 0
run dir = ${TEST_DIR}/run
auth cluster required = none
auth service required = none
auth client required = none
osd pool default size = 1
EOF
export CEPH_ARGS="--conf ${CONF_DIR}/ceph.conf"

# single monitor
MON_DATA=${TEST_DIR}/mon
mkdir -p $MON_DATA

cat >> $CONF_DIR/ceph.conf <<EOF
[mon.0]
log file = ${TEST_DIR}/log/mon.log
chdir = ""
mon cluster log file = ${TEST_DIR}/log/mon-cluster.log
mon data = ${MON_DATA}
mon addr = 127.0.0.1
# this was added to enable pool deletion within method delete_one_pool_pp()
mon_allow_pool_delete = true
kingwind94 marked this conversation as resolved.
Show resolved Hide resolved
EOF

ceph-mon --id 0 --mkfs --keyring /dev/null
touch ${MON_DATA}/keyring
ceph-mon --id 0

# single osd
OSD_DATA=${TEST_DIR}/osd
mkdir ${OSD_DATA}

cat >> $CONF_DIR/ceph.conf <<EOF
[osd.0]
log file = ${TEST_DIR}/log/osd.log
chdir = ""
osd data = ${OSD_DATA}
osd journal = ${OSD_DATA}.journal
osd journal size = 100
osd objectstore = memstore
osd class load list = lock log numops refcount replica_log statelog timeindex user version cls_sdk
EOF

OSD_ID=$(ceph osd create)
ceph osd crush add osd.${OSD_ID} 1 root=default host=localhost
ceph-osd --id ${OSD_ID} --mkjournal --mkfs
ceph-osd --id ${OSD_ID}

# check that it works
ceph osd pool create rbd 8 8
rados --pool rbd put group /etc/group
rados --pool rbd get group ${TEST_DIR}/group
diff /etc/group ${TEST_DIR}/group
ceph osd tree

export CEPH_CONF="${CONF_DIR}/ceph.conf"
29 changes: 25 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
set(cls_dir ${CMAKE_INSTALL_LIBDIR}/rados-classes)

# cls_sdk
add_library(cls_sdk SHARED cls_sdk.cc)
set_target_properties(cls_sdk PROPERTIES
add_library(cls_cls_sdk SHARED cls_sdk.cc)
set_target_properties(cls_cls_sdk PROPERTIES
VERSION "1.0.0"
SOVERSION "1"
INSTALL_RPATH ""
CXX_VISIBILITY_PRESET hidden)
install(TARGETS cls_sdk DESTINATION ${cls_dir})
CXX_VISIBILITY_PRESET hidden
)

install(TARGETS cls_cls_sdk DESTINATION ${cls_dir})

# cls_sdk_test
add_executable(cls_sdk_test
cls_sdk_test.cc
test_utils.cc
)

target_link_libraries(cls_sdk_test
${LIBRADOS_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
${GTEST_INCLUDE_DIRS}
${GTEST_LIBRARIES}
)

install(TARGETS
cls_sdk_test
RUNTIME DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
52 changes: 27 additions & 25 deletions src/cls_sdk.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* This is an example RADOS object class built using only the Ceph SDK interface.
* This is an example RADOS object class built using only the Ceph SDK
* interface.
*/
#include "rados/objclass.h"

CLS_VER(1,0)
CLS_NAME(sdk)
CLS_VER(1, 0)
CLS_NAME(cls_sdk)

cls_handle_t h_class;
cls_method_handle_t h_test_coverage_write;
Expand All @@ -16,12 +17,13 @@ cls_method_handle_t h_test_coverage_replay;
* This method modifies the object by making multiple write calls (write,
* setxattr and set_val).
*/
static int test_coverage_write(cls_method_context_t hctx, ceph::buffer::list *in, ceph::buffer::list *out)
{
static int test_coverage_write(cls_method_context_t hctx,
ceph::buffer::list *in,
ceph::buffer::list *out) {
// create the object
int ret = cls_cxx_create(hctx, false);
if (ret < 0) {
CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__, ret);
CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__, ret);
return ret;
}

Expand All @@ -30,7 +32,7 @@ static int test_coverage_write(cls_method_context_t hctx, ceph::buffer::list *in
ret = cls_cxx_stat(hctx, &size, NULL);
if (ret < 0)
return ret;

std::string c = "test";
ceph::buffer::list bl;
bl.append(c);
Expand All @@ -39,7 +41,7 @@ static int test_coverage_write(cls_method_context_t hctx, ceph::buffer::list *in
ret = cls_cxx_write(hctx, 0, bl.length(), &bl);
if (ret < 0)
return ret;

uint64_t new_size;
// get the new size of the object
ret = cls_cxx_stat(hctx, &new_size, NULL);
Expand All @@ -62,29 +64,30 @@ static int test_coverage_write(cls_method_context_t hctx, ceph::buffer::list *in
/**
* test_coverage_replay - a "read" method to retrieve previously written data
*
* This method reads the object by making multiple read calls (read, getxattr
* This method reads the object by making multiple read calls (read, getxattr
* and get_val). It also removes the object after reading.
*/

static int test_coverage_replay(cls_method_context_t hctx, ceph::buffer::list *in, ceph::buffer::list *out)
{
static int test_coverage_replay(cls_method_context_t hctx,
ceph::buffer::list *in,
ceph::buffer::list *out) {
CLS_LOG(0, "reading already written object");
uint64_t size;
// get the size of the object
int ret = cls_cxx_stat(hctx, &size, NULL);
if (ret < 0)
return ret;

ceph::buffer::list bl;
// read the object entry
ret = cls_cxx_read(hctx, 0, size, &bl);
if (ret < 0)
return ret;

// if the size is incorrect
// if the size is incorrect
if (bl.length() != size)
return -EIO;

bl.clear();

// read xattr entry
Expand All @@ -95,7 +98,7 @@ static int test_coverage_replay(cls_method_context_t hctx, ceph::buffer::list *i
// if the size is incorrect
if (bl.length() != size)
return -EIO;

bl.clear();

// read omap entry
Expand All @@ -111,21 +114,20 @@ static int test_coverage_replay(cls_method_context_t hctx, ceph::buffer::list *i
ret = cls_cxx_remove(hctx);
if (ret < 0)
return ret;

return 0;
}

CLS_INIT(sdk)
{
CLS_LOG(0, "loading cls_sdk");
CLS_INIT(cls_sdk) {
CLS_LOG(20, "loading cls_sdk class");

cls_register("sdk", &h_class);
cls_register("cls_sdk", &h_class);

cls_register_cxx_method(h_class, "test_coverage_write",
CLS_METHOD_RD|CLS_METHOD_WR,
test_coverage_write, &h_test_coverage_write);
CLS_METHOD_RD | CLS_METHOD_WR, test_coverage_write,
&h_test_coverage_write);

cls_register_cxx_method(h_class, "test_coverage_replay",
CLS_METHOD_RD|CLS_METHOD_WR,
test_coverage_replay, &h_test_coverage_replay);
CLS_METHOD_RD | CLS_METHOD_WR, test_coverage_replay,
&h_test_coverage_replay);
}
35 changes: 35 additions & 0 deletions src/cls_sdk_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <errno.h>

#include "test_utils.h"
#include "gtest/gtest.h"

using namespace librados;


TEST(ClsSDK, TestSDKCoverageWrite) {
Rados cluster;
std::string pool_name = get_temp_pool_name();
ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
IoCtx ioctx;
cluster.ioctx_create(pool_name.c_str(), ioctx);

bufferlist in, out;
ASSERT_EQ(0, ioctx.exec("test_object", "cls_sdk", "test_coverage_write", in, out));

ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}

TEST(ClsSDK, TestSDKCoverageReplay) {
Rados cluster;
std::string pool_name = get_temp_pool_name();
ASSERT_EQ("", create_one_pool_pp(pool_name, cluster));
IoCtx ioctx;
cluster.ioctx_create(pool_name.c_str(), ioctx);

bufferlist in, out;
ASSERT_EQ(0, ioctx.exec("test_object", "cls_sdk", "test_coverage_write", in, out));
ASSERT_EQ(0, ioctx.exec("test_object", "cls_sdk", "test_coverage_replay", in, out));

ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
}
Loading