forked from red-hat-storage/ocs-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.py
341 lines (274 loc) · 9.03 KB
/
fixtures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
import pytest
from ocs_ci.ocs.resources.pod import delete_deploymentconfig_pods
from ocs_ci.helpers import helpers
from ocs_ci.ocs import constants, ocp
@pytest.fixture()
def create_rbd_secret(request):
"""
Create an RBD secret
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the RBD secret
"""
if hasattr(class_instance, "rbd_secret_obj"):
class_instance.rbd_secret_obj.delete()
class_instance.rbd_secret_obj.ocp.wait_for_delete(
class_instance.rbd_secret_obj.name
)
request.addfinalizer(finalizer)
class_instance.rbd_secret_obj = helpers.create_secret(
interface_type=constants.CEPHBLOCKPOOL
)
assert class_instance.rbd_secret_obj, "Failed to create secret"
@pytest.fixture()
def create_cephfs_secret(request):
"""
Create a CephFS secret
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the FS secret
"""
if hasattr(class_instance, "cephfs_secret_obj"):
class_instance.cephfs_secret_obj.delete()
class_instance.cephfs_secret_obj.ocp.wait_for_delete(
class_instance.cephfs_secret_obj.name
)
request.addfinalizer(finalizer)
class_instance.cephfs_secret_obj = helpers.create_secret(
interface_type=constants.CEPHFILESYSTEM
)
assert class_instance.cephfs_secret_obj, "Failed to create secret"
@pytest.fixture()
def create_ceph_block_pool(request):
"""
Create a Ceph block pool
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the Ceph block pool
"""
if hasattr(class_instance, "cbp_obj"):
class_instance.cbp_obj.delete()
request.addfinalizer(finalizer)
class_instance.cbp_obj = helpers.create_ceph_block_pool()
assert class_instance.cbp_obj, "Failed to create block pool"
@pytest.fixture()
def create_rbd_storageclass(request):
"""
Create an RBD storage class
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the RBD storage class
"""
if class_instance.sc_obj.get():
class_instance.sc_obj.delete()
class_instance.sc_obj.ocp.wait_for_delete(class_instance.sc_obj.name)
request.addfinalizer(finalizer)
if not hasattr(class_instance, "reclaim_policy"):
class_instance.reclaim_policy = constants.RECLAIM_POLICY_DELETE
class_instance.sc_obj = helpers.create_storage_class(
interface_type=constants.CEPHBLOCKPOOL,
interface_name=class_instance.cbp_obj.name,
secret_name=class_instance.rbd_secret_obj.name,
reclaim_policy=class_instance.reclaim_policy,
)
assert class_instance.sc_obj, "Failed to create storage class"
@pytest.fixture()
def create_cephfs_storageclass(request):
"""
Create a CephFS storage class
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the CephFS storage class
"""
if class_instance.sc_obj.get():
class_instance.sc_obj.delete()
class_instance.sc_obj.ocp.wait_for_delete(class_instance.sc_obj.name)
request.addfinalizer(finalizer)
class_instance.sc_obj = helpers.create_storage_class(
interface_type=constants.CEPHFILESYSTEM,
interface_name=helpers.get_cephfs_data_pool_name(),
secret_name=class_instance.cephfs_secret_obj.name,
)
assert class_instance.sc_obj, "Failed to create storage class"
@pytest.fixture()
def create_project(request):
"""
Create a new project
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the project
"""
ocp.switch_to_default_rook_cluster_project()
class_instance.project_obj.delete(resource_name=class_instance.namespace)
class_instance.project_obj.wait_for_delete(class_instance.namespace)
request.addfinalizer(finalizer)
class_instance.project_obj = helpers.create_project()
class_instance.namespace = class_instance.project_obj.namespace
@pytest.fixture()
def create_pvc(request):
"""
Create a persistent Volume Claim
"""
class_instance = request.node.cls
class_instance.pvc_obj = helpers.create_pvc(
sc_name=class_instance.sc_obj.name, namespace=class_instance.namespace
)
helpers.wait_for_resource_state(class_instance.pvc_obj, constants.STATUS_BOUND)
class_instance.pvc_obj.reload()
@pytest.fixture()
def delete_pvc(request):
"""
Delete a persistent Volume Claim
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the PVC
"""
if hasattr(class_instance, "pvc_obj"):
class_instance.pvc_obj.delete()
request.addfinalizer(finalizer)
@pytest.fixture()
def create_rbd_pod(request):
"""
Create a pod
"""
class_instance = request.node.cls
class_instance.pod_obj = helpers.create_pod(
interface_type=constants.CEPHBLOCKPOOL,
pvc_name=class_instance.pvc_obj.name,
namespace=class_instance.namespace,
)
helpers.wait_for_resource_state(class_instance.pod_obj, constants.STATUS_RUNNING)
class_instance.pod_obj.reload()
@pytest.fixture()
def delete_pod(request):
"""
Delete a pod
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the pod
"""
if hasattr(class_instance, "pod_obj"):
class_instance.pod_obj.delete()
request.addfinalizer(finalizer)
@pytest.fixture()
def create_pvcs(request):
"""
Create multiple PVCs
"""
class_instance = request.node.cls
def finalizer():
"""
Delete multiple PVCs
"""
if hasattr(class_instance, "pvc_objs"):
for pvc_obj in class_instance.pvc_objs:
pvc_obj.reload()
backed_pv_name = pvc_obj.backed_pv
pvc_obj.delete()
for pvc_obj in class_instance.pvc_objs:
pvc_obj.ocp.wait_for_delete(pvc_obj.name)
helpers.validate_pv_delete(backed_pv_name)
request.addfinalizer(finalizer)
class_instance.pvc_objs, _ = helpers.create_multiple_pvcs(
sc_name=class_instance.sc_obj.name,
number_of_pvc=class_instance.num_of_pvcs,
size=class_instance.pvc_size,
namespace=class_instance.namespace,
)
for pvc_obj in class_instance.pvc_objs:
helpers.wait_for_resource_state(pvc_obj, constants.STATUS_BOUND)
pvc_obj.reload()
@pytest.fixture()
def create_pods(request):
"""
Create multiple pods
"""
class_instance = request.node.cls
def finalizer():
"""
Delete multiple pods
"""
if hasattr(class_instance, "pod_objs"):
for pod in class_instance.pod_objs:
pod.delete()
request.addfinalizer(finalizer)
class_instance.pod_objs = list()
for pvc_obj in class_instance.pvc_objs:
class_instance.pod_objs.append(
helpers.create_pod(
interface_type=class_instance.interface,
pvc_name=pvc_obj.name,
do_reload=False,
namespace=class_instance.namespace,
)
)
for pod in class_instance.pod_objs:
helpers.wait_for_resource_state(pod, constants.STATUS_RUNNING)
@pytest.fixture()
def create_dc_pods(request):
"""
Create multiple deploymentconfig pods
"""
class_instance = request.node.cls
def finalizer():
"""
Delete multiple dc pods
"""
if hasattr(class_instance, "dc_pod_objs"):
for pod in class_instance.dc_pod_objs:
delete_deploymentconfig_pods(pod_obj=pod)
request.addfinalizer(finalizer)
class_instance.dc_pod_objs = [
helpers.create_pod(
interface_type=class_instance.interface,
pvc_name=pvc_obj.name,
do_reload=False,
namespace=class_instance.namespace,
sa_name=class_instance.sa_obj.name,
dc_deployment=True,
replica_count=class_instance.replica_count,
)
for pvc_obj in class_instance.pvc_objs
]
for pod in class_instance.dc_pod_objs:
helpers.wait_for_resource_state(pod, constants.STATUS_RUNNING, timeout=180)
@pytest.fixture()
def create_serviceaccount(request):
"""
Create a service account
"""
class_instance = request.node.cls
def finalizer():
"""
Delete the service account
"""
helpers.remove_scc_policy(
sa_name=class_instance.sa_obj.name,
namespace=class_instance.project_obj.namespace,
)
class_instance.sa_obj.delete()
request.addfinalizer(finalizer)
class_instance.sa_obj = helpers.create_serviceaccount(
namespace=class_instance.project_obj.namespace,
)
helpers.add_scc_policy(
sa_name=class_instance.sa_obj.name,
namespace=class_instance.project_obj.namespace,
)
assert class_instance.sa_obj, "Failed to create serviceaccount"