Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / librados / TestCase.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_TEST_RADOS_TESTCASE_H
5 #define CEPH_TEST_RADOS_TESTCASE_H
6
7 #include "include/rados/librados.h"
8 #include "include/rados/librados.hpp"
9 #include "gtest/gtest.h"
10
11 #include <string>
12
13 /**
14  * These test cases create a temporary pool that lives as long as the
15  * test case.  We initially use the default namespace and assume
16  * test will whatever namespaces it wants.  After each test all objects
17  * are removed.
18  *
19  * Since pool creation and deletion is slow, this allows many tests to
20  * run faster.
21  */
22 class RadosTestNS : public ::testing::Test {
23 public:
24   RadosTestNS(bool c=false) : cleanup(c) {}
25   ~RadosTestNS() override {}
26 protected:
27   static void SetUpTestCase();
28   static void TearDownTestCase();
29   static void cleanup_all_objects(rados_ioctx_t ioctx);
30   static rados_t s_cluster;
31   static std::string pool_name;
32
33   void SetUp() override;
34   void TearDown() override;
35   rados_t cluster;
36   rados_ioctx_t ioctx;
37   bool cleanup;
38 };
39
40 struct RadosTestNSCleanup : public RadosTestNS {
41   RadosTestNSCleanup() : RadosTestNS(true) {}
42 };
43
44 class RadosTestPPNS : public ::testing::Test {
45 public:
46   RadosTestPPNS(bool c=false) : cluster(s_cluster), cleanup(c) {}
47   ~RadosTestPPNS() override {}
48 protected:
49   static void SetUpTestCase();
50   static void TearDownTestCase();
51   static void cleanup_all_objects(librados::IoCtx ioctx);
52   static librados::Rados s_cluster;
53   static std::string pool_name;
54
55   void SetUp() override;
56   void TearDown() override;
57   librados::Rados &cluster;
58   librados::IoCtx ioctx;
59   bool cleanup;
60 };
61
62 struct RadosTestPPNSCleanup : public RadosTestPPNS {
63   RadosTestPPNSCleanup() : RadosTestPPNS(true) {}
64 };
65
66 class RadosTestParamPPNS : public ::testing::TestWithParam<const char*> {
67 public:
68   RadosTestParamPPNS(bool c=false) : cluster(s_cluster), cleanup(c) {}
69   ~RadosTestParamPPNS() override {}
70   static void SetUpTestCase();
71   static void TearDownTestCase();
72 protected:
73   static void cleanup_all_objects(librados::IoCtx ioctx);
74   static librados::Rados s_cluster;
75   static std::string pool_name;
76   static std::string cache_pool_name;
77
78   void SetUp() override;
79   void TearDown() override;
80   librados::Rados &cluster;
81   librados::IoCtx ioctx;
82   bool cleanup;
83 };
84
85 class RadosTestECNS : public RadosTestNS {
86 public:
87   RadosTestECNS(bool c=false) : cleanup(c) {}
88   ~RadosTestECNS() override {}
89 protected:
90   static void SetUpTestCase();
91   static void TearDownTestCase();
92   static rados_t s_cluster;
93   static std::string pool_name;
94
95   void SetUp() override;
96   void TearDown() override;
97   rados_t cluster;
98   rados_ioctx_t ioctx;
99   uint64_t alignment;
100   bool cleanup;
101 };
102
103 struct RadosTestECNSCleanup : public RadosTestECNS {
104   RadosTestECNSCleanup() : RadosTestECNS(true) {}
105 };
106
107 class RadosTestECPPNS : public RadosTestPPNS {
108 public:
109   RadosTestECPPNS(bool c=false) : cluster(s_cluster), cleanup(c) {}
110   ~RadosTestECPPNS() override {}
111 protected:
112   static void SetUpTestCase();
113   static void TearDownTestCase();
114   static librados::Rados s_cluster;
115   static std::string pool_name;
116
117   void SetUp() override;
118   void TearDown() override;
119   librados::Rados &cluster;
120   librados::IoCtx ioctx;
121   uint64_t alignment;
122   bool cleanup;
123 };
124
125 struct RadosTestECPPNSCleanup : public RadosTestECPPNS {
126   RadosTestECPPNSCleanup() : RadosTestECPPNS(true) {}
127 };
128
129 /**
130  * These test cases create a temporary pool that lives as long as the
131  * test case.  Each test within a test case gets a new ioctx set to a
132  * unique namespace within the pool.
133  *
134  * Since pool creation and deletion is slow, this allows many tests to
135  * run faster.
136  */
137 class RadosTest : public ::testing::Test {
138 public:
139   RadosTest(bool c=false) : cleanup(c) {}
140   ~RadosTest() override {}
141 protected:
142   static void SetUpTestCase();
143   static void TearDownTestCase();
144   static void cleanup_default_namespace(rados_ioctx_t ioctx);
145   static void cleanup_namespace(rados_ioctx_t ioctx, std::string ns);
146   static rados_t s_cluster;
147   static std::string pool_name;
148
149   void SetUp() override;
150   void TearDown() override;
151   rados_t cluster;
152   rados_ioctx_t ioctx;
153   std::string nspace;
154   bool cleanup;
155 };
156
157 class RadosTestPP : public ::testing::Test {
158 public:
159   RadosTestPP(bool c=false) : cluster(s_cluster), cleanup(c) {}
160   ~RadosTestPP() override {}
161 protected:
162   static void SetUpTestCase();
163   static void TearDownTestCase();
164   static void cleanup_default_namespace(librados::IoCtx ioctx);
165   static void cleanup_namespace(librados::IoCtx ioctx, std::string ns);
166   static librados::Rados s_cluster;
167   static std::string pool_name;
168
169   void SetUp() override;
170   void TearDown() override;
171   librados::Rados &cluster;
172   librados::IoCtx ioctx;
173   bool cleanup;
174   std::string nspace;
175 };
176
177 class RadosTestParamPP : public ::testing::TestWithParam<const char*> {
178 public:
179   RadosTestParamPP(bool c=false) : cluster(s_cluster), cleanup(c) {}
180   ~RadosTestParamPP() override {}
181   static void SetUpTestCase();
182   static void TearDownTestCase();
183 protected:
184   static void cleanup_default_namespace(librados::IoCtx ioctx);
185   static void cleanup_namespace(librados::IoCtx ioctx, std::string ns);
186   static librados::Rados s_cluster;
187   static std::string pool_name;
188   static std::string cache_pool_name;
189
190   void SetUp() override;
191   void TearDown() override;
192   librados::Rados &cluster;
193   librados::IoCtx ioctx;
194   bool cleanup;
195   std::string nspace;
196 };
197
198 class RadosTestEC : public RadosTest {
199 public:
200   RadosTestEC(bool c=false) : cleanup(c) {}
201   ~RadosTestEC() override {}
202 protected:
203   static void SetUpTestCase();
204   static void TearDownTestCase();
205   static rados_t s_cluster;
206   static std::string pool_name;
207
208   void SetUp() override;
209   void TearDown() override;
210   rados_t cluster;
211   rados_ioctx_t ioctx;
212   bool cleanup;
213   std::string nspace;
214   uint64_t alignment;
215 };
216
217 class RadosTestECPP : public RadosTestPP {
218 public:
219   RadosTestECPP(bool c=false) : cluster(s_cluster), cleanup(c) {}
220   ~RadosTestECPP() override {}
221 protected:
222   static void SetUpTestCase();
223   static void TearDownTestCase();
224   static librados::Rados s_cluster;
225   static std::string pool_name;
226
227   void SetUp() override;
228   void TearDown() override;
229   librados::Rados &cluster;
230   librados::IoCtx ioctx;
231   bool cleanup;
232   std::string nspace;
233   uint64_t alignment;
234 };
235
236 /**
237  * Test case without creating a temporary pool in advance.
238  * This is necessary for scenarios such that we need to
239  * manually create a pool, start some long-runing tasks and
240  * then the related pool is suddenly gone.
241  */
242 class RadosTestNP: public ::testing::Test {
243 public:
244   RadosTestNP() {}
245   ~RadosTestNP() override {}
246 };
247
248 #endif