]>
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 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(&rgw
, saved_args
.argc
, saved_args
.argv
);
54 ASSERT_NE(rgw
, nullptr);
58 int ret
= rgw_mount2(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 bool 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 bool 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
)
176 extern bool global_stop
;
178 TEST(LibRGW
, GETATTR_OBJECTS
) {
186 for (auto& fid_row
: bucket_matrix
) {
187 auto& fid
= get
<0>(fid_row
); // bucket
188 std::vector
<fid_type
>& obj_vector
= get
<1>(fid_row
); // objects in bucket
189 struct rgw_file_handle
*bucket_fh
= get
<2>(fid
);
191 for (auto& obj
: obj_vector
) {
192 struct rgw_file_handle
*obj_fh
= nullptr;
193 std::string object_name
= get
<0>(obj
);
194 ret
= rgw_lookup(fs
, bucket_fh
, get
<0>(obj
).c_str(), &obj_fh
,
195 nullptr /* stat */, 0 /* mask */, 0 /* flags */);
197 get
<2>(obj
) = obj_fh
; // stash obj_fh for cleanup
198 ASSERT_NE(get
<2>(obj
), nullptr);
199 ret
= rgw_getattr(fs
, obj_fh
, &st
,
200 RGW_GETATTR_FLAG_NONE
); // now, getattr
207 TEST(LibRGW
, CLEANUP
) {
211 /* release file handles */
212 for (auto& fid_row
: bucket_matrix
) {
213 auto& bucket
= get
<0>(fid_row
); // bucket
214 std::vector
<fid_type
>& obj_vector
= get
<1>(fid_row
); // objects in bucket
215 for (auto& obj
: obj_vector
) {
216 struct rgw_file_handle
*obj_fh
= get
<2>(obj
);
218 ret
= rgw_fh_rele(fs
, obj_fh
, 0 /* flags */);
223 struct rgw_file_handle
*bucket_fh
= get
<2>(bucket
);
225 ret
= rgw_fh_rele(fs
, bucket_fh
, 0 /* flags */);
231 TEST(LibRGW
, UMOUNT
) {
235 int ret
= rgw_umount(fs
, RGW_UMOUNT_FLAG_NONE
);
239 TEST(LibRGW
, SHUTDOWN
) {
240 librgw_shutdown(rgw
);
243 int main(int argc
, char *argv
[])
245 auto args
= argv_to_vec(argc
, argv
);
248 char* v
= getenv("AWS_ACCESS_KEY_ID");
253 v
= getenv("AWS_SECRET_ACCESS_KEY");
259 for (auto arg_iter
= args
.begin(); arg_iter
!= args
.end();) {
260 if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--access",
263 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--secret",
266 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--uid",
269 } else if (ceph_argparse_flag(args
, arg_iter
, "--getattr",
277 /* don't accidentally run as anonymous */
278 if ((access_key
== "") ||
279 (secret_key
== "")) {
280 std::cout
<< argv
[0] << " no AWS credentials, exiting" << std::endl
;
284 saved_args
.argc
= argc
;
285 saved_args
.argv
= argv
;
287 ::testing::InitGoogleTest(&argc
, argv
);
288 return RUN_ALL_TESTS();