]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/librgw_file.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 Red Hat, Inc.
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
19 #include "include/rados/librgw.h"
20 #include "include/rados/rgw_file.h"
22 #include "gtest/gtest.h"
23 #include "common/ceph_argparse.h"
24 #include "common/debug.h"
25 #include "global/global_init.h"
27 #define dout_subsys ceph_subsys_rgw
32 librgw_t h_rgw
= nullptr;
33 string
uid("testuser");
34 string
access_key("");
35 string
secret_key("");
36 struct rgw_fs
*fs
= nullptr;
37 typedef std::tuple
<string
, uint64_t, struct rgw_file_handle
*> fid_type
; //in c++2014 can alias...
38 typedef std::tuple
<fid_type
, std::vector
<fid_type
>> bucket_type
;
40 std::vector
<fid_type
> fids1
;
41 std::vector
<bucket_type
> bucket_matrix
;
43 bool do_getattr
= false;
52 int ret
= librgw_create(&h_rgw
, saved_args
.argc
, saved_args
.argv
);
54 ASSERT_NE(h_rgw
, nullptr);
58 int ret
= rgw_mount2(h_rgw
, uid
.c_str(), access_key
.c_str(), secret_key
.c_str(),
59 "/", &fs
, RGW_MOUNT_FLAG_NONE
);
61 ASSERT_NE(fs
, nullptr);
64 TEST(LibRGW
, GETATTR_ROOT
) {
70 int ret
= rgw_getattr(fs
, fs
->root_fh
, &st
, RGW_GETATTR_FLAG_NONE
);
76 static int r1_cb(const char* name
, void *arg
, uint64_t offset
,
77 struct stat
* st
, uint32_t st_mask
,
79 // don't need arg--it would point to fids1
80 fids1
.push_back(fid_type(name
, offset
, nullptr /* handle */));
81 return true; /* XXX ? */
85 TEST(LibRGW
, LIST_BUCKETS
) {
86 /* list buckets via readdir in fs root */
94 int ret
= rgw_readdir(fs
, fs
->root_fh
, &offset
, r1_cb
, &fids1
, &eof
,
95 RGW_READDIR_FLAG_NONE
);
96 for (auto& fid
: fids1
) {
97 std::cout
<< "fname: " << get
<0>(fid
) << " fid: " << get
<1>(fid
)
99 /* push row for bucket into bucket_matrix */
100 bucket_matrix
.push_back(bucket_type(fid
, std::vector
<fid_type
>()));
105 TEST(LibRGW
, LOOKUP_BUCKETS
) {
111 for (auto& fid_row
: bucket_matrix
) {
112 auto& fid
= get
<0>(fid_row
);
113 // auto& obj_vector = get<1>(fid_row);
114 struct rgw_file_handle
*rgw_fh
= nullptr;
115 ASSERT_EQ(0, rgw_lookup(fs
, fs
->root_fh
, get
<0>(fid
).c_str(), &rgw_fh
,
116 nullptr /* stat */, 0 /* mask */, 0 /* flags */));
117 get
<2>(fid
) = rgw_fh
;
118 ASSERT_NE(get
<2>(fid
), nullptr);
122 TEST(LibRGW
, GETATTR_BUCKETS
) {
131 for (auto& fid_row
: bucket_matrix
) {
132 auto& fid
= get
<0>(fid_row
);
133 struct rgw_file_handle
*rgw_fh
= get
<2>(fid
);
134 ASSERT_EQ(0, rgw_getattr(fs
, rgw_fh
, &st
, RGW_GETATTR_FLAG_NONE
));
140 static int r2_cb(const char* name
, void *arg
, uint64_t offset
,
141 struct stat
* st
, uint32_t st_mask
,
143 std::vector
<fid_type
>& obj_vector
= *(static_cast<std::vector
<fid_type
>*>(arg
));
144 obj_vector
.push_back(fid_type(name
, offset
, nullptr));
145 return true; /* XXX ? */
149 TEST(LibRGW
, LIST_OBJECTS
) {
150 /* list objects via readdir, bucketwise */
156 for (auto& fid_row
: bucket_matrix
) {
157 auto& fid
= get
<0>(fid_row
); // bucket
158 std::vector
<fid_type
>& obj_vector
= get
<1>(fid_row
); // objects in bucket
159 struct rgw_file_handle
*bucket_fh
= get
<2>(fid
);
161 ldout(g_ceph_context
, 0) << __func__
<< " readdir on bucket " << get
<0>(fid
)
166 int ret
= rgw_readdir(fs
, bucket_fh
, &offset
, r2_cb
, &obj_vector
, &eof
,
167 RGW_READDIR_FLAG_NONE
);
168 for (auto& obj
: obj_vector
) {
169 std::cout
<< "fname: " << get
<0>(obj
) << " fid: " << get
<1>(obj
)
177 extern bool global_stop
;
180 TEST(LibRGW
, GETATTR_OBJECTS
) {
186 rgw::global_stop
= true;
188 for (auto& fid_row
: bucket_matrix
) {
189 auto& fid
= get
<0>(fid_row
); // bucket
190 std::vector
<fid_type
>& obj_vector
= get
<1>(fid_row
); // objects in bucket
191 struct rgw_file_handle
*bucket_fh
= get
<2>(fid
);
193 for (auto& obj
: obj_vector
) {
194 struct rgw_file_handle
*obj_fh
= nullptr;
195 std::string object_name
= get
<0>(obj
);
196 ret
= rgw_lookup(fs
, bucket_fh
, get
<0>(obj
).c_str(), &obj_fh
,
197 nullptr /* stat */, 0 /* mask */, 0 /* flags */);
199 get
<2>(obj
) = obj_fh
; // stash obj_fh for cleanup
200 ASSERT_NE(get
<2>(obj
), nullptr);
201 ret
= rgw_getattr(fs
, obj_fh
, &st
,
202 RGW_GETATTR_FLAG_NONE
); // now, getattr
209 TEST(LibRGW
, CLEANUP
) {
213 /* release file handles */
214 for (auto& fid_row
: bucket_matrix
) {
215 auto& bucket
= get
<0>(fid_row
); // bucket
216 std::vector
<fid_type
>& obj_vector
= get
<1>(fid_row
); // objects in bucket
217 for (auto& obj
: obj_vector
) {
218 struct rgw_file_handle
*obj_fh
= get
<2>(obj
);
220 ret
= rgw_fh_rele(fs
, obj_fh
, 0 /* flags */);
225 struct rgw_file_handle
*bucket_fh
= get
<2>(bucket
);
227 ret
= rgw_fh_rele(fs
, bucket_fh
, 0 /* flags */);
233 TEST(LibRGW
, UMOUNT
) {
237 int ret
= rgw_umount(fs
, RGW_UMOUNT_FLAG_NONE
);
241 TEST(LibRGW
, SHUTDOWN
) {
242 librgw_shutdown(h_rgw
);
245 int main(int argc
, char *argv
[])
247 auto args
= argv_to_vec(argc
, argv
);
250 char* v
= getenv("AWS_ACCESS_KEY_ID");
255 v
= getenv("AWS_SECRET_ACCESS_KEY");
261 for (auto arg_iter
= args
.begin(); arg_iter
!= args
.end();) {
262 if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--access",
265 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--secret",
268 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--uid",
271 } else if (ceph_argparse_flag(args
, arg_iter
, "--getattr",
279 /* don't accidentally run as anonymous */
280 if ((access_key
== "") ||
281 (secret_key
== "")) {
282 std::cout
<< argv
[0] << " no AWS credentials, exiting" << std::endl
;
286 saved_args
.argc
= argc
;
287 saved_args
.argv
= argv
;
289 ::testing::InitGoogleTest(&argc
, argv
);
290 return RUN_ALL_TESTS();