]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: initial librgw_file_nfsns.cc test
authorMatt Benjamin <mbenjamin@redhat.com>
Thu, 10 Dec 2015 17:43:00 +0000 (12:43 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:06:29 +0000 (12:06 -0500)
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/test/CMakeLists.txt
src/test/librgw_file_nfsns.cc [new file with mode: 0644]

index 6f0503273a129d64669ca40c0547790f9d3cf809..2be7e964fc052d95248c68d670574fc5417d9905 100644 (file)
@@ -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
+  $<TARGET_OBJECTS:heap_profiler_objs>
+  )
+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 (file)
index 0000000..9cfb2d3
--- /dev/null
@@ -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 <stdint.h>
+#include <tuple>
+#include <iostream>
+#include <stack>
+
+#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_rec> obj_stack;
+  std::deque<obj_rec> 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<const char*> args;
+
+  argv_to_vec(argc, const_cast<const char**>(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();
+}