diff options
author | Matt Benjamin <mbenjamin@redhat.com> | 2015-10-25 22:22:43 +0100 |
---|---|---|
committer | Matt Benjamin <mbenjamin@redhat.com> | 2016-02-12 18:05:02 +0100 |
commit | fc0a895af2e9a6f8e476a0987795eb92cb2a3c28 (patch) | |
tree | 36a8b6107eb5d1db33b4a8fc47b696ea7eb4b617 /src/test/librgw_file_gp.cc | |
parent | librgw: add options for bucket name, multi create, delete (diff) | |
download | ceph-fc0a895af2e9a6f8e476a0987795eb92cb2a3c28.tar.xz ceph-fc0a895af2e9a6f8e476a0987795eb92cb2a3c28.zip |
librgw: rgw_file_handle refactor, plus get/put
Implement encapsulation of RGWFileHandle in rgw_file_handle,
so return these from rgw_lookup(), add new rgw_fh_rele() to release
internal state.
Currently the rgw_fh_rele just deletes, in future might be extended
with refcnt support.
Implement the first (atomic) stage of i/o using GET and PUT, add a
new librgw_file_gp test driver for this.
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
Diffstat (limited to 'src/test/librgw_file_gp.cc')
-rw-r--r-- | src/test/librgw_file_gp.cc | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/src/test/librgw_file_gp.cc b/src/test/librgw_file_gp.cc new file mode 100644 index 00000000000..958d79a7c08 --- /dev/null +++ b/src/test/librgw_file_gp.cc @@ -0,0 +1,158 @@ +// -*- 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 "include/rados/librgw.h" +#include "include/rados/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 { + librgw_t rgw = nullptr; + string uid("testuser"); + string access_key(""); + string secret_key(""); + struct rgw_fs *fs = nullptr; + + bool do_put = false; + bool do_get = false; + bool do_delete = false; + + string bucket_name = "sorry_dave"; + string object_name = "jocaml"; + + struct rgw_file_handle *fh = nullptr; + + struct { + int argc; + char **argv; + } saved_args; +} + +TEST(LibRGW, INIT) { + int ret = librgw_create(&rgw, nullptr, saved_args.argc, saved_args.argv); + ASSERT_EQ(ret, 0); + ASSERT_NE(rgw, nullptr); +} + +TEST(LibRGW, MOUNT) { + int ret = rgw_mount(rgw, uid.c_str(), access_key.c_str(), secret_key.c_str(), + &fs); + ASSERT_EQ(ret, 0); + ASSERT_NE(fs, nullptr); +} + +TEST(LibRGW, OBJ_OPEN) { + int ret = rgw_lookup(fs, &fs->root_fh, bucket_name.c_str(), &fh, + 0 /* flags */); + ASSERT_EQ(ret, 0); + ret = rgw_open(fs, fh, 0 /* flags */); + ASSERT_EQ(ret, 0); +} + +TEST(LibRGW, PUT_OBJECT) { + if (do_put) { + string data = "hi mom"; // fix this + int ret = rgw_write(fs, fh, 0, data.length(), (void*) data.c_str()); + ASSERT_EQ(ret, 0); + } +} + +TEST(LibRGW, GET_OBJECT) { + /* XXX soon */ +} + +TEST(LibRGW, CLEANUP) { + int ret = rgw_close(fs, fh, 0 /* flags */); + ASSERT_EQ(ret, 0); + ret = rgw_fh_rele(fs, fh, 0 /* flags */); + ASSERT_EQ(ret, 0); +} + +TEST(LibRGW, UMOUNT) { + if (! fs) + return; + + int ret = rgw_umount(fs); + ASSERT_EQ(ret, 0); +} + +TEST(LibRGW, SHUTDOWN) { + librgw_shutdown(rgw); +} + +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 if (ceph_argparse_flag(args, arg_iter, "--get", + (char*) nullptr)) { + do_get = true; + } else if (ceph_argparse_flag(args, arg_iter, "--put", + (char*) nullptr)) { + do_put = true; + } 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(); +} |