From: Matt Benjamin Date: Thu, 10 Dec 2015 17:43:00 +0000 (-0500) Subject: librgw: initial librgw_file_nfsns.cc test X-Git-Tag: v10.1.0~382^2~119 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=27c9a360651d4d8a4b2db50d239c7ef3a73fd30f;p=ceph.git librgw: initial librgw_file_nfsns.cc test Signed-off-by: Matt Benjamin --- diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 6f0503273a12..2be7e964fc05 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -2431,6 +2431,22 @@ target_link_libraries(test_librgw_file_gp ${CMAKE_DL_LIBS} ) +# librgw_file_nfsns (nfs namespace tests) +add_executable(test_librgw_file_nfsns + librgw_file_nfsns.cc + $ + ) +set_target_properties(test_librgw_file_nfsns PROPERTIES COMPILE_FLAGS + ${UNITTEST_CXX_FLAGS}) +target_link_libraries(test_librgw_file_nfsns + rgw + librados + ${UNITTEST_LIBS} + ${EXTRALIBS} + ${ALLOC_LIBS} + ${CMAKE_DL_LIBS} + ) + if(${HAVE_LIBFUSE}) add_executable(test_cfuse_cache_invalidate test_cfuse_cache_invalidate.cc diff --git a/src/test/librgw_file_nfsns.cc b/src/test/librgw_file_nfsns.cc new file mode 100644 index 000000000000..9cfb2d3f8373 --- /dev/null +++ b/src/test/librgw_file_nfsns.cc @@ -0,0 +1,179 @@ +// -*- 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) 2015 New Dream Network + * + * 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/rados/librgw.h" +#include "include/rados/rgw_file.h" +#include "rgw/rgw_file.h" + +#include "gtest/gtest.h" +#include "common/ceph_argparse.h" +#include "common/debug.h" +#include "global/global_init.h" + +#define dout_subsys ceph_subsys_rgw + +namespace { + + using namespace rgw; + using std::get; + using std::string; + + librgw_t rgw_h = nullptr; + string uid("testuser"); + string access_key(""); + string secret_key(""); + struct rgw_fs *fs = nullptr; + + string bucket_name = "nfsroot"; + + class obj_rec + { + public: + string name; + struct rgw_file_handle* fh; + struct rgw_file_handle* parent_fh; + RGWFileHandle* rgw_fh; // alias into fh + + obj_rec(string _name, struct rgw_file_handle* _fh, + struct rgw_file_handle* _parent_fh, RGWFileHandle* _rgw_fh) + : name(std::move(_name)), fh(_fh), parent_fh(_parent_fh), + rgw_fh(_rgw_fh) {} + }; + + std::stack obj_stack; + std::deque obj_queue; + + struct { + int argc; + char **argv; + } saved_args; +} + +TEST(LibRGW, INIT) { + int ret = librgw_create(&rgw_h, saved_args.argc, saved_args.argv); + ASSERT_EQ(ret, 0); + ASSERT_NE(rgw_h, nullptr); +} + +TEST(LibRGW, MOUNT) { + int ret = rgw_mount(rgw_h, uid.c_str(), access_key.c_str(), + secret_key.c_str(), &fs); + ASSERT_EQ(ret, 0); + ASSERT_NE(fs, nullptr); +} + +#if 0 +extern "C" { + static bool r1_cb(const char* name, void *arg, uint64_t offset) { + // don't need arg--it would point to fids1 + buckets.push_back(fid_type(name, offset, nullptr /* handle */)); + return true; /* XXX ? */ + } +} +#endif + +TEST(LibRGW, ENUMERATE1) { + int rc; + obj_stack.push(obj_rec{bucket_name, nullptr, nullptr, nullptr}); + while (! obj_stack.empty()) { + auto& elt = obj_stack.top(); + if (! elt.fh) { + struct rgw_file_handle* parent_fh = elt.parent_fh + ? elt.parent_fh : fs->root_fh; + rc = rgw_lookup(fs, parent_fh, elt.name.c_str(), &elt.fh, + RGW_LOOKUP_FLAG_NONE); + ASSERT_EQ(rc, 0); + ASSERT_NE(elt.fh, nullptr); + elt.parent_fh = parent_fh; + // what next? push? + } else { + // we have a leaf in some state in top position + // 1. finish it? + // 2. print it? + // 3. push it onto obj_queue for cleanup + } + } +} + +TEST(LibRGW, CLEANUP) { + // do nothing +} + +TEST(LibRGW, UMOUNT) { + if (! fs) + return; + + int ret = rgw_umount(fs); + ASSERT_EQ(ret, 0); +} + +TEST(LibRGW, SHUTDOWN) { + librgw_shutdown(rgw_h); +} + +int main(int argc, char *argv[]) +{ + char *v{nullptr}; + string val; + vector args; + + argv_to_vec(argc, const_cast(argv), args); + env_to_vec(args); + + v = getenv("AWS_ACCESS_KEY_ID"); + if (v) { + access_key = v; + } + + v = getenv("AWS_SECRET_ACCESS_KEY"); + if (v) { + secret_key = v; + } + + for (auto arg_iter = args.begin(); arg_iter != args.end();) { + if (ceph_argparse_witharg(args, arg_iter, &val, "--access", + (char*) nullptr)) { + access_key = val; + } else if (ceph_argparse_witharg(args, arg_iter, &val, "--secret", + (char*) nullptr)) { + secret_key = val; + } else if (ceph_argparse_witharg(args, arg_iter, &val, "--uid", + (char*) nullptr)) { + uid = val; + } else if (ceph_argparse_witharg(args, arg_iter, &val, "--bn", + (char*) nullptr)) { + bucket_name = val; + } else { + ++arg_iter; + } + } + + /* dont accidentally run as anonymous */ + if ((access_key == "") || + (secret_key == "")) { + std::cout << argv[0] << " no AWS credentials, exiting" << std::endl; + return EPERM; + } + + saved_args.argc = argc; + saved_args.argv = argv; + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}