]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/librgw_file_cd.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
30 librgw_t rgw
= nullptr;
31 string
userid("testuser");
32 string
access_key("");
33 string
secret_key("");
34 struct rgw_fs
*fs
= nullptr;
36 uint32_t owner_uid
= 867;
37 uint32_t owner_gid
= 5309;
38 uint32_t create_mask
= RGW_SETATTR_UID
| RGW_SETATTR_GID
| RGW_SETATTR_MODE
;
40 bool do_create
= false;
41 bool do_delete
= false;
42 bool do_multi
= false;
45 string bucket_name
= "sorry_dave";
54 int ret
= librgw_create(&rgw
, saved_args
.argc
, saved_args
.argv
);
56 ASSERT_NE(rgw
, nullptr);
60 int ret
= rgw_mount2(rgw
, userid
.c_str(), access_key
.c_str(),
61 secret_key
.c_str(), "/", &fs
, RGW_MOUNT_FLAG_NONE
);
63 ASSERT_NE(fs
, nullptr);
66 TEST(LibRGW
, CREATE_BUCKET
) {
69 struct rgw_file_handle
*fh
;
71 st
.st_uid
= owner_uid
;
72 st
.st_gid
= owner_gid
;
75 int ret
= rgw_mkdir(fs
, fs
->root_fh
, bucket_name
.c_str(), &st
, create_mask
,
76 &fh
, RGW_MKDIR_FLAG_NONE
);
81 TEST(LibRGW
, DELETE_BUCKET
) {
83 int ret
= rgw_unlink(fs
, fs
->root_fh
, bucket_name
.c_str(),
84 RGW_UNLINK_FLAG_NONE
);
89 TEST(LibRGW
, CREATE_BUCKET_MULTI
) {
93 struct rgw_file_handle
*fh
;
95 st
.st_uid
= owner_uid
;
96 st
.st_gid
= owner_gid
;
99 for (int ix
= 0; ix
< multi_cnt
; ++ix
) {
100 string bn
= bucket_name
;
102 ret
= rgw_mkdir(fs
, fs
->root_fh
, bn
.c_str(), &st
, create_mask
, &fh
,
103 RGW_MKDIR_FLAG_NONE
);
105 std::cout
<< "created: " << bn
<< std::endl
;
110 TEST(LibRGW
, DELETE_BUCKET_MULTI
) {
112 for (int ix
= 0; ix
< multi_cnt
; ++ix
) {
113 string bn
= bucket_name
;
115 int ret
= rgw_unlink(fs
, fs
->root_fh
, bn
.c_str(),
116 RGW_UNLINK_FLAG_NONE
);
122 TEST(LibRGW
, CLEANUP
) {
126 TEST(LibRGW
, UMOUNT
) {
130 int ret
= rgw_umount(fs
, RGW_UMOUNT_FLAG_NONE
);
134 TEST(LibRGW
, SHUTDOWN
) {
135 librgw_shutdown(rgw
);
138 int main(int argc
, char *argv
[])
142 vector
<const char*> args
;
144 argv_to_vec(argc
, const_cast<const char**>(argv
), args
);
147 v
= getenv("AWS_ACCESS_KEY_ID");
152 v
= getenv("AWS_SECRET_ACCESS_KEY");
157 for (auto arg_iter
= args
.begin(); arg_iter
!= args
.end();) {
158 if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--access",
161 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--secret",
164 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--userid",
167 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--bn",
170 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--uid",
172 owner_uid
= std::stoi(val
);
173 } else if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--gid",
175 owner_gid
= std::stoi(val
);
176 } else if (ceph_argparse_flag(args
, arg_iter
, "--create",
179 } else if (ceph_argparse_flag(args
, arg_iter
, "--delete",
182 } else if (ceph_argparse_flag(args
, arg_iter
, "--multi",
190 /* dont accidentally run as anonymous */
191 if ((access_key
== "") ||
192 (secret_key
== "")) {
193 std::cout
<< argv
[0] << " no AWS credentials, exiting" << std::endl
;
197 saved_args
.argc
= argc
;
198 saved_args
.argv
= argv
;
200 ::testing::InitGoogleTest(&argc
, argv
);
201 return RUN_ALL_TESTS();