Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / rgw / test_rgw_common.cc
1 #include "test_rgw_common.h"
2
3 void test_rgw_add_placement(RGWZoneGroup *zonegroup, RGWZoneParams *zone_params, const std::string& name, bool is_default)
4 {
5   zonegroup->placement_targets[name] = { name };
6
7   RGWZonePlacementInfo& pinfo = zone_params->placement_pools[name];
8   pinfo.index_pool = rgw_pool(name + ".index").to_str();
9   pinfo.data_pool = rgw_pool(name + ".data").to_str();
10   pinfo.data_extra_pool = rgw_pool(name + ".extra").to_str();
11   
12   if (is_default) {
13     zonegroup->default_placement = name;
14   }
15 }
16
17 void test_rgw_init_env(RGWZoneGroup *zonegroup, RGWZoneParams *zone_params)
18 {
19   test_rgw_add_placement(zonegroup, zone_params, "default-placement", true);
20
21 }
22
23 void test_rgw_populate_explicit_placement_bucket(rgw_bucket *b, const char *t, const char *n, const char *dp, const char *ip, const char *m, const char *id)
24 {
25   b->tenant = t;
26   b->name = n;
27   b->marker = m;
28   b->bucket_id = id;
29   b->explicit_placement.data_pool = rgw_pool(dp);
30   b->explicit_placement.index_pool = rgw_pool(ip);
31 }
32
33 void test_rgw_populate_old_bucket(old_rgw_bucket *b, const char *t, const char *n, const char *dp, const char *ip, const char *m, const char *id)
34 {
35   b->tenant = t;
36   b->name = n;
37   b->marker = m;
38   b->bucket_id = id;
39   b->data_pool = dp;
40   b->index_pool = ip;
41 }
42
43 std::string test_rgw_get_obj_oid(const rgw_obj& obj)
44 {
45   std::string oid;
46   std::string loc;
47
48   get_obj_bucket_and_oid_loc(obj, oid, loc);
49   return oid;
50 }
51
52 void test_rgw_init_explicit_placement_bucket(rgw_bucket *bucket, const char *name)
53 {
54   test_rgw_populate_explicit_placement_bucket(bucket, "", name, ".data-pool", ".index-pool", "marker", "bucket-id");
55 }
56
57 void test_rgw_init_old_bucket(old_rgw_bucket *bucket, const char *name)
58 {
59   test_rgw_populate_old_bucket(bucket, "", name, ".data-pool", ".index-pool", "marker", "bucket-id");
60 }
61
62 void test_rgw_populate_bucket(rgw_bucket *b, const char *t, const char *n, const char *m, const char *id)
63 {
64   b->tenant = t;
65   b->name = n;
66   b->marker = m;
67   b->bucket_id = id;
68 }
69
70 void test_rgw_init_bucket(rgw_bucket *bucket, const char *name)
71 {
72   test_rgw_populate_bucket(bucket, "", name, "marker", "bucket-id");
73 }
74
75 rgw_obj test_rgw_create_obj(const rgw_bucket& bucket, const std::string& name, const std::string& instance, const std::string& ns)
76 {
77   rgw_obj obj(bucket, name);
78   if (!instance.empty()) {
79     obj.key.set_instance(instance);
80   }
81   if (!ns.empty()) {
82     obj.key.ns = ns;
83   }
84   obj.bucket = bucket;
85
86   return obj;
87 }
88
89