]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
7c673cae FG |
3 | |
4 | #include "rgw_common.h" | |
5 | #include "rgw_rados.h" | |
11fdf7f2 | 6 | #include "rgw_zone.h" |
7c673cae FG |
7 | #include "rgw_log.h" |
8 | #include "rgw_acl.h" | |
9 | #include "rgw_acl_s3.h" | |
10 | #include "rgw_cache.h" | |
b32b8144 FG |
11 | #include "rgw_meta_sync_status.h" |
12 | #include "rgw_data_sync.h" | |
9f95a23c | 13 | #include "rgw_multi.h" |
7c673cae FG |
14 | |
15 | #include "common/Formatter.h" | |
16 | ||
17 | static string shadow_ns = RGW_OBJ_NS_SHADOW; | |
18 | ||
19 | static void init_bucket(rgw_bucket *b, const char *t, const char *n, const char *dp, const char *ip, const char *m, const char *id) | |
20 | { | |
21 | b->tenant = t; | |
22 | b->name = n; | |
23 | b->marker = m; | |
24 | b->bucket_id = id; | |
25 | b->explicit_placement.data_pool = rgw_pool(dp); | |
26 | b->explicit_placement.index_pool = rgw_pool(ip); | |
27 | } | |
28 | ||
29 | void RGWObjManifestPart::generate_test_instances(std::list<RGWObjManifestPart*>& o) | |
30 | { | |
31 | o.push_back(new RGWObjManifestPart); | |
32 | ||
33 | RGWObjManifestPart *p = new RGWObjManifestPart; | |
34 | rgw_bucket b; | |
35 | init_bucket(&b, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12"); | |
36 | ||
37 | p->loc = rgw_obj(b, "object"); | |
38 | p->loc_ofs = 512 * 1024; | |
39 | p->size = 128 * 1024; | |
40 | o.push_back(p); | |
41 | } | |
42 | ||
7c673cae FG |
43 | void RGWObjManifest::generate_test_instances(std::list<RGWObjManifest*>& o) |
44 | { | |
45 | RGWObjManifest *m = new RGWObjManifest; | |
9f95a23c TL |
46 | map<uint64_t, RGWObjManifestPart> objs; |
47 | uint64_t total_size = 0; | |
7c673cae FG |
48 | for (int i = 0; i<10; i++) { |
49 | RGWObjManifestPart p; | |
50 | rgw_bucket b; | |
51 | init_bucket(&b, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12"); | |
52 | p.loc = rgw_obj(b, "object"); | |
53 | p.loc_ofs = 0; | |
54 | p.size = 512 * 1024; | |
9f95a23c TL |
55 | total_size += p.size; |
56 | objs[total_size] = p; | |
7c673cae | 57 | } |
9f95a23c | 58 | m->set_explicit(total_size, objs); |
7c673cae | 59 | o.push_back(m); |
7c673cae FG |
60 | o.push_back(new RGWObjManifest); |
61 | } | |
62 | ||
7c673cae FG |
63 | |
64 | void rgw_log_entry::generate_test_instances(list<rgw_log_entry*>& o) | |
65 | { | |
66 | rgw_log_entry *e = new rgw_log_entry; | |
67 | e->object_owner = "object_owner"; | |
68 | e->bucket_owner = "bucket_owner"; | |
69 | e->bucket = "bucket"; | |
70 | e->remote_addr = "1.2.3.4"; | |
71 | e->user = "user"; | |
72 | e->obj = rgw_obj_key("obj"); | |
73 | e->uri = "http://uri/bucket/obj"; | |
74 | e->http_status = "200"; | |
75 | e->error_code = "error_code"; | |
76 | e->bytes_sent = 1024; | |
77 | e->bytes_received = 512; | |
78 | e->obj_size = 2048; | |
79 | e->user_agent = "user_agent"; | |
80 | e->referrer = "referrer"; | |
81 | e->bucket_id = "10"; | |
9f95a23c | 82 | e->trans_id = "trans_id"; |
7c673cae FG |
83 | o.push_back(e); |
84 | o.push_back(new rgw_log_entry); | |
85 | } | |
86 | ||
87 | void ACLPermission::generate_test_instances(list<ACLPermission*>& o) | |
88 | { | |
89 | ACLPermission *p = new ACLPermission; | |
90 | p->set_permissions(RGW_PERM_WRITE_ACP); | |
91 | o.push_back(p); | |
92 | o.push_back(new ACLPermission); | |
93 | } | |
94 | ||
95 | void ACLGranteeType::generate_test_instances(list<ACLGranteeType*>& o) | |
96 | { | |
97 | ACLGranteeType *t = new ACLGranteeType; | |
98 | t->set(ACL_TYPE_CANON_USER); | |
99 | o.push_back(t); | |
100 | o.push_back(new ACLGranteeType); | |
101 | } | |
102 | ||
103 | /* the following is copied here from rgw_acl_s3.cc, to avoid having to have excessive linking | |
104 | with everything it needs */ | |
105 | ||
106 | #define RGW_URI_ALL_USERS "http://acs.amazonaws.com/groups/global/AllUsers" | |
107 | #define RGW_URI_AUTH_USERS "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" | |
108 | ||
109 | static string rgw_uri_all_users = RGW_URI_ALL_USERS; | |
110 | static string rgw_uri_auth_users = RGW_URI_AUTH_USERS; | |
111 | ||
112 | ACLGroupTypeEnum ACLGrant::uri_to_group(string& uri) | |
113 | { | |
114 | // this is required for backward compatibility | |
115 | return ACLGrant_S3::uri_to_group(uri); | |
116 | } | |
117 | ||
118 | ACLGroupTypeEnum ACLGrant_S3::uri_to_group(string& uri) | |
119 | { | |
120 | if (uri.compare(rgw_uri_all_users) == 0) | |
121 | return ACL_GROUP_ALL_USERS; | |
122 | else if (uri.compare(rgw_uri_auth_users) == 0) | |
123 | return ACL_GROUP_AUTHENTICATED_USERS; | |
124 | ||
125 | return ACL_GROUP_NONE; | |
126 | } | |
127 | ||
128 | void ACLGrant::generate_test_instances(list<ACLGrant*>& o) | |
129 | { | |
130 | rgw_user id("rgw"); | |
131 | string name, email; | |
132 | name = "Mr. RGW"; | |
133 | email = "r@gw"; | |
134 | ||
135 | ACLGrant *g1 = new ACLGrant; | |
136 | g1->set_canon(id, name, RGW_PERM_READ); | |
137 | g1->email = email; | |
138 | o.push_back(g1); | |
139 | ||
140 | ACLGrant *g2 = new ACLGrant; | |
141 | g1->set_group(ACL_GROUP_AUTHENTICATED_USERS, RGW_PERM_WRITE); | |
142 | o.push_back(g2); | |
143 | ||
144 | o.push_back(new ACLGrant); | |
145 | } | |
146 | ||
147 | void RGWAccessControlList::generate_test_instances(list<RGWAccessControlList*>& o) | |
148 | { | |
149 | RGWAccessControlList *acl = new RGWAccessControlList(NULL); | |
150 | ||
151 | list<ACLGrant *> glist; | |
152 | list<ACLGrant *>::iterator iter; | |
153 | ||
154 | ACLGrant::generate_test_instances(glist); | |
155 | for (iter = glist.begin(); iter != glist.end(); ++iter) { | |
156 | ACLGrant *grant = *iter; | |
157 | acl->add_grant(grant); | |
158 | ||
159 | delete grant; | |
160 | } | |
161 | o.push_back(acl); | |
162 | o.push_back(new RGWAccessControlList(NULL)); | |
163 | } | |
164 | ||
165 | void ACLOwner::generate_test_instances(list<ACLOwner*>& o) | |
166 | { | |
167 | ACLOwner *owner = new ACLOwner; | |
168 | owner->id = "rgw"; | |
169 | owner->display_name = "Mr. RGW"; | |
170 | o.push_back(owner); | |
171 | o.push_back(new ACLOwner); | |
172 | } | |
173 | ||
174 | void RGWAccessControlPolicy::generate_test_instances(list<RGWAccessControlPolicy*>& o) | |
175 | { | |
176 | list<RGWAccessControlList *> acl_list; | |
177 | list<RGWAccessControlList *>::iterator iter; | |
178 | for (iter = acl_list.begin(); iter != acl_list.end(); ++iter) { | |
179 | RGWAccessControlList::generate_test_instances(acl_list); | |
180 | iter = acl_list.begin(); | |
181 | ||
182 | RGWAccessControlPolicy *p = new RGWAccessControlPolicy(NULL); | |
183 | RGWAccessControlList *l = *iter; | |
184 | p->acl = *l; | |
185 | ||
186 | string name = "radosgw"; | |
187 | rgw_user id("rgw"); | |
188 | p->owner.set_name(name); | |
189 | p->owner.set_id(id); | |
190 | ||
191 | o.push_back(p); | |
192 | ||
193 | delete l; | |
194 | } | |
195 | ||
196 | o.push_back(new RGWAccessControlPolicy(NULL)); | |
197 | } | |
198 | ||
199 | ||
200 | void ObjectMetaInfo::generate_test_instances(list<ObjectMetaInfo*>& o) | |
201 | { | |
202 | ObjectMetaInfo *m = new ObjectMetaInfo; | |
203 | m->size = 1024 * 1024; | |
204 | o.push_back(m); | |
205 | o.push_back(new ObjectMetaInfo); | |
206 | } | |
207 | ||
208 | void ObjectCacheInfo::generate_test_instances(list<ObjectCacheInfo*>& o) | |
209 | { | |
11fdf7f2 | 210 | using ceph::encode; |
7c673cae FG |
211 | ObjectCacheInfo *i = new ObjectCacheInfo; |
212 | i->status = 0; | |
213 | i->flags = CACHE_FLAG_MODIFY_XATTRS; | |
214 | string s = "this is a string"; | |
215 | string s2 = "this is a another string"; | |
216 | bufferlist data, data2; | |
11fdf7f2 TL |
217 | encode(s, data); |
218 | encode(s2, data2); | |
7c673cae FG |
219 | i->data = data; |
220 | i->xattrs["x1"] = data; | |
221 | i->xattrs["x2"] = data2; | |
222 | i->rm_xattrs["r2"] = data2; | |
223 | i->rm_xattrs["r3"] = data; | |
224 | i->meta.size = 512 * 1024; | |
225 | o.push_back(i); | |
226 | o.push_back(new ObjectCacheInfo); | |
227 | } | |
228 | ||
229 | void RGWCacheNotifyInfo::generate_test_instances(list<RGWCacheNotifyInfo*>& o) | |
230 | { | |
231 | o.push_back(new RGWCacheNotifyInfo); | |
232 | } | |
233 | ||
234 | void RGWAccessKey::generate_test_instances(list<RGWAccessKey*>& o) | |
235 | { | |
236 | RGWAccessKey *k = new RGWAccessKey; | |
237 | k->id = "id"; | |
238 | k->key = "key"; | |
239 | k->subuser = "subuser"; | |
240 | o.push_back(k); | |
241 | o.push_back(new RGWAccessKey); | |
242 | } | |
243 | ||
244 | void RGWSubUser::generate_test_instances(list<RGWSubUser*>& o) | |
245 | { | |
246 | RGWSubUser *u = new RGWSubUser; | |
247 | u->name = "name"; | |
248 | u->perm_mask = 0xf; | |
249 | o.push_back(u); | |
250 | o.push_back(new RGWSubUser); | |
251 | } | |
252 | ||
253 | void RGWUserInfo::generate_test_instances(list<RGWUserInfo*>& o) | |
254 | { | |
255 | RGWUserInfo *i = new RGWUserInfo; | |
7c673cae FG |
256 | i->user_id = "user_id"; |
257 | i->display_name = "display_name"; | |
258 | i->user_email = "user@email"; | |
259 | RGWAccessKey k1, k2; | |
260 | k1.id = "id1"; | |
261 | k1.key = "key1"; | |
262 | k2.id = "id2"; | |
263 | k2.subuser = "subuser"; | |
264 | RGWSubUser u; | |
265 | u.name = "id2"; | |
266 | u.perm_mask = 0x1; | |
267 | i->access_keys[k1.id] = k1; | |
268 | i->swift_keys[k2.id] = k2; | |
269 | i->subusers[u.name] = u; | |
270 | o.push_back(i); | |
271 | ||
272 | o.push_back(new RGWUserInfo); | |
273 | } | |
274 | ||
275 | void rgw_bucket::generate_test_instances(list<rgw_bucket*>& o) | |
276 | { | |
277 | rgw_bucket *b = new rgw_bucket; | |
278 | init_bucket(b, "tenant", "name", "pool", ".index_pool", "marker", "123"); | |
279 | o.push_back(b); | |
280 | o.push_back(new rgw_bucket); | |
281 | } | |
282 | ||
283 | void RGWBucketInfo::generate_test_instances(list<RGWBucketInfo*>& o) | |
284 | { | |
285 | RGWBucketInfo *i = new RGWBucketInfo; | |
286 | init_bucket(&i->bucket, "tenant", "bucket", "pool", ".index_pool", "marker", "10"); | |
287 | i->owner = "owner"; | |
288 | i->flags = BUCKET_SUSPENDED; | |
289 | o.push_back(i); | |
290 | o.push_back(new RGWBucketInfo); | |
291 | } | |
292 | ||
293 | void RGWZoneGroup::generate_test_instances(list<RGWZoneGroup*>& o) | |
294 | { | |
295 | RGWZoneGroup *r = new RGWZoneGroup; | |
296 | o.push_back(r); | |
297 | o.push_back(new RGWZoneGroup); | |
298 | } | |
299 | ||
300 | void RGWZone::generate_test_instances(list<RGWZone*> &o) | |
301 | { | |
302 | RGWZone *z = new RGWZone; | |
303 | o.push_back(z); | |
304 | o.push_back(new RGWZone); | |
305 | } | |
306 | ||
11fdf7f2 TL |
307 | void RGWRealm::generate_test_instances(list<RGWRealm*> &o) |
308 | { | |
309 | RGWRealm *z = new RGWRealm; | |
310 | o.push_back(z); | |
311 | o.push_back(new RGWRealm); | |
312 | } | |
313 | ||
314 | void RGWPeriod::generate_test_instances(list<RGWPeriod*> &o) | |
315 | { | |
316 | RGWPeriod *z = new RGWPeriod; | |
317 | o.push_back(z); | |
318 | o.push_back(new RGWPeriod); | |
319 | } | |
320 | ||
9f95a23c TL |
321 | void RGWPeriodLatestEpochInfo::generate_test_instances(list<RGWPeriodLatestEpochInfo*> &o) |
322 | { | |
323 | RGWPeriodLatestEpochInfo *z = new RGWPeriodLatestEpochInfo; | |
324 | o.push_back(z); | |
325 | o.push_back(new RGWPeriodLatestEpochInfo); | |
326 | } | |
327 | ||
7c673cae FG |
328 | void RGWZoneParams::generate_test_instances(list<RGWZoneParams*> &o) |
329 | { | |
330 | o.push_back(new RGWZoneParams); | |
331 | o.push_back(new RGWZoneParams); | |
332 | } | |
333 | ||
334 | void RGWOLHInfo::generate_test_instances(list<RGWOLHInfo*> &o) | |
335 | { | |
336 | RGWOLHInfo *olh = new RGWOLHInfo; | |
337 | olh->removed = false; | |
338 | o.push_back(olh); | |
339 | o.push_back(new RGWOLHInfo); | |
340 | } | |
341 | ||
342 | void RGWBucketEnt::generate_test_instances(list<RGWBucketEnt*>& o) | |
343 | { | |
344 | RGWBucketEnt *e = new RGWBucketEnt; | |
345 | init_bucket(&e->bucket, "tenant", "bucket", "pool", ".index_pool", "marker", "10"); | |
346 | e->size = 1024; | |
347 | e->size_rounded = 4096; | |
348 | e->count = 1; | |
349 | o.push_back(e); | |
350 | o.push_back(new RGWBucketEnt); | |
351 | } | |
352 | ||
353 | void RGWUploadPartInfo::generate_test_instances(list<RGWUploadPartInfo*>& o) | |
354 | { | |
355 | RGWUploadPartInfo *i = new RGWUploadPartInfo; | |
356 | i->num = 1; | |
357 | i->size = 10 * 1024 * 1024; | |
358 | i->etag = "etag"; | |
359 | o.push_back(i); | |
360 | o.push_back(new RGWUploadPartInfo); | |
361 | } | |
362 | ||
363 | void rgw_obj::generate_test_instances(list<rgw_obj*>& o) | |
364 | { | |
365 | rgw_bucket b; | |
366 | init_bucket(&b, "tenant", "bucket", "pool", ".index_pool", "marker", "10"); | |
367 | rgw_obj *obj = new rgw_obj(b, "object"); | |
368 | o.push_back(obj); | |
369 | o.push_back(new rgw_obj); | |
370 | } | |
371 | ||
b32b8144 FG |
372 | void rgw_meta_sync_info::generate_test_instances(list<rgw_meta_sync_info*>& o) |
373 | { | |
374 | auto info = new rgw_meta_sync_info; | |
375 | info->state = rgw_meta_sync_info::StateBuildingFullSyncMaps; | |
376 | info->period = "periodid"; | |
377 | info->realm_epoch = 5; | |
378 | o.push_back(info); | |
379 | o.push_back(new rgw_meta_sync_info); | |
380 | } | |
381 | ||
382 | void rgw_meta_sync_marker::generate_test_instances(list<rgw_meta_sync_marker*>& o) | |
383 | { | |
384 | auto marker = new rgw_meta_sync_marker; | |
385 | marker->state = rgw_meta_sync_marker::IncrementalSync; | |
386 | marker->marker = "01234"; | |
387 | marker->realm_epoch = 5; | |
388 | o.push_back(marker); | |
389 | o.push_back(new rgw_meta_sync_marker); | |
390 | } | |
391 | ||
392 | void rgw_meta_sync_status::generate_test_instances(list<rgw_meta_sync_status*>& o) | |
393 | { | |
394 | o.push_back(new rgw_meta_sync_status); | |
395 | } | |
396 | ||
397 | void rgw_data_sync_info::generate_test_instances(list<rgw_data_sync_info*>& o) | |
398 | { | |
399 | auto info = new rgw_data_sync_info; | |
400 | info->state = rgw_data_sync_info::StateBuildingFullSyncMaps; | |
401 | info->num_shards = 8; | |
402 | o.push_back(info); | |
403 | o.push_back(new rgw_data_sync_info); | |
404 | } | |
405 | ||
406 | void rgw_data_sync_marker::generate_test_instances(list<rgw_data_sync_marker*>& o) | |
407 | { | |
408 | auto marker = new rgw_data_sync_marker; | |
409 | marker->state = rgw_data_sync_marker::IncrementalSync; | |
410 | marker->marker = "01234"; | |
411 | marker->pos = 5; | |
412 | o.push_back(marker); | |
413 | o.push_back(new rgw_data_sync_marker); | |
414 | } | |
415 | ||
416 | void rgw_data_sync_status::generate_test_instances(list<rgw_data_sync_status*>& o) | |
417 | { | |
418 | o.push_back(new rgw_data_sync_status); | |
419 | } | |
9f95a23c TL |
420 | |
421 | void objexp_hint_entry::generate_test_instances(list<objexp_hint_entry*>& o) | |
422 | { | |
423 | auto it = new objexp_hint_entry; | |
424 | it->tenant = "tenant1"; | |
425 | it->bucket_name = "bucket1"; | |
426 | it->bucket_id = "1234"; | |
427 | it->obj_key = rgw_obj_key("obj"); | |
428 | o.push_back(it); | |
429 | o.push_back(new objexp_hint_entry); | |
430 | } | |
431 | ||
432 | void RGWBucketEntryPoint::generate_test_instances(list<RGWBucketEntryPoint*>& o) | |
433 | { | |
434 | RGWBucketEntryPoint *bp = new RGWBucketEntryPoint(); | |
435 | init_bucket(&bp->bucket, "tenant", "bucket", "pool", ".index.pool", "marker", "10"); | |
436 | bp->owner = "owner"; | |
437 | bp->creation_time = ceph::real_clock::from_ceph_timespec({init_le32(2), init_le32(3)}); | |
438 | ||
439 | o.push_back(bp); | |
440 | o.push_back(new RGWBucketEntryPoint); | |
441 | } | |
442 | ||
443 | void rgw_user::generate_test_instances(list<rgw_user*>& o) | |
444 | { | |
445 | rgw_user *u = new rgw_user("tenant", "user"); | |
446 | ||
447 | o.push_back(u); | |
448 | o.push_back(new rgw_user); | |
449 | } | |
450 | ||
451 | void obj_version::generate_test_instances(list<obj_version*>& o) | |
452 | { | |
453 | obj_version *v = new obj_version; | |
454 | v->ver = 5; | |
455 | v->tag = "tag"; | |
456 | ||
457 | o.push_back(v); | |
458 | o.push_back(new obj_version); | |
459 | } |