forked from hpe-storage/hpe3par_test_automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_virtual_copy.py
325 lines (266 loc) · 16.7 KB
/
test_virtual_copy.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
import hpe_3par_kubernetes_manager as manager
from hpe3parclient.exceptions import HTTPBadRequest
from hpe3parclient.exceptions import HTTPForbidden
from hpe3parclient.exceptions import HTTPConflict
from hpe3parclient.exceptions import HTTPNotFound
import time
import yaml
import pytest
import globals
import logging
timeout = globals.status_check_timeout
def test_virtual_copyOf_tpvv_vol():
base_yml = '%s/virtual-copy/virtual-copy-base-vol.yml' % globals.yaml_dir
snap_yml = '%s/virtual-copy/virtual-copy-snap-vol.yml' % globals.yaml_dir
create_virtual_copyOf(base_yml,snap_yml)
@pytest.mark.skip_array("3par")
def test_virtual_copyOf_reduce_vol():
base_yml = '%s/virtual-copy/virtual-copy-base-vol-tc2.yml' % globals.yaml_dir
snap_yml = '%s/virtual-copy/virtual-copy-snap-vol-tc2.yml' % globals.yaml_dir
create_virtual_copyOf(base_yml,snap_yml)
@pytest.mark.skip_array("primera")
def test_virtual_copyOf_tdvv_vol():
base_yml = '%s/virtual-copy/virtual-copy-base-vol-tc3.yml' % globals.yaml_dir
snap_yml = '%s/virtual-copy/virtual-copy-snap-vol-tc3.yml' % globals.yaml_dir
create_virtual_copyOf(base_yml,snap_yml)
@pytest.mark.skip_array("primera")
def test_virtual_copyOf_tdvv_compr_vol():
base_yml = '%s/virtual-copy/virtual-copy-base-vol-tc4.yml' % globals.yaml_dir
snap_yml = '%s/virtual-copy/virtual-copy-snap-vol-tc4.yml' % globals.yaml_dir
create_virtual_copyOf(base_yml,snap_yml)
def create_virtual_copyOf(base_yml,snap_yml):
#base_yml = '%s/virtual-copy/virtual-copy-base-vol.yml' % globals.yaml_dir
#snap_yml = '%s/virtual-copy/virtual-copy-snap-vol.yml' % globals.yaml_dir
pvc_snap = None
sc_snap = None
snap_pod = None
sc = None
pvc = None
pod = None
isPresent = False
isValid = False
try:
with open(base_yml, "r") as ymlfile:
elements = list(yaml.safe_load_all(ymlfile))
for el in elements:
if str(el.get('kind')) == "StorageClass":
cpg = el['parameters']['cpg']
snapCPG = el['parameters']['snapCpg']
provisioningType = el['parameters']['provisioning_type']
compression = el['parameters']['compression']
break
#array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(base_yml)
# Creating base volume now in CSI
sc = manager.create_sc(base_yml)
pvc = manager.create_pvc(base_yml)
logging.getLogger().info("Check in events if volume is created...")
flag, base_pvc_obj = manager.check_status(30, pvc.metadata.name, kind='pvc', status='Bound',
namespace=pvc.metadata.namespace)
assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % base_pvc_obj.metadata.name
# Export base volume
pod = manager.create_pod(base_yml)
flag, base_pod_obj = manager.check_status(timeout, pod.metadata.name, kind='pod', status='Running',
namespace=pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % pod.metadata.name
time.sleep(20)
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(pod.metadata.name, command)
if any("mydata.txt" in x for x in data.split('\n')):
isPresent = True
assert isPresent is True, "File not present in base volume"
# Creating snap volume in CSI
sc_snap = manager.create_sc(snap_yml)
pvc_snap = manager.create_pvc(snap_yml)
logging.getLogger().info("Check in events if volume is created...")
flag, snap_pvc_obj = manager.check_status(30, pvc_snap.metadata.name, kind='pvc', status='Bound',
namespace=pvc_snap.metadata.namespace)
assert flag is True, "Snapshot PVC %s status check timed out, not in Bound state yet..." % snap_pvc_obj.metadata.name
#Export snapshot volume
snap_pod = manager.create_pod(snap_yml)
flag, snap_pod_obj = manager.check_status(timeout, snap_pod.metadata.name, kind='pod', status='Running',
namespace=snap_pod.metadata.namespace)
assert flag is True, "Snapshot volume pod mount %s status check timed out, not in Running state yet..." % snap_pod.metadata.name
logging.getLogger().info("Checking snapshot volume data")
time.sleep(20)
# Validating data on snapshot volume
isPresent = False
command = ['/bin/sh', '-c', 'ls -l /export']
snap_data = manager.hpe_connect_pod_container(snap_pod.metadata.name, command)
if any("mydata.txt" in x for x in snap_data.split('\n')):
isPresent = True
assert isPresent is True, "File on base volume not found in snap volume"
isPresent = False
if any("mysnapdata.txt" in x for x in snap_data.split('\n')):
isPresent = True
assert isPresent is True, "File not present in snap volume"
logging.getLogger().info("snapshot volume data check successfull")
time.sleep(10)
#Validate snapshot pvc crd
pvc_crd = manager.get_pvc_crd("pvc-"+snap_pvc_obj.metadata.uid)
assert pvc_crd['spec']['record']['BaseSnapshotId'] == "pvc-"+snap_pvc_obj.metadata.uid, "Base snapshot id is incorrect %s" % pvc_crd['spec']['record']['BaseSnapshotId']
assert pvc_crd['spec']['record']['ParentVolumeId'] == "pvc-"+base_pvc_obj.metadata.uid, "Parent id is incorrect %s" % pvc_crd['spec']['record']['ParentVolumeId']
logging.getLogger().info("Volume crd check successfull")
#Validating base volume properties
#hpe3par_cli = manager.get_3par_cli_client(base_yml)
base_volume = manager.get_volume_from_array(globals.hpe3par_cli, pvc_crd['spec']['record']['ParentBackendName'])
if int(globals.hpe3par_version.split(".")[0]) < 4:
isValid = manager.verify_volume_properties_3par(base_volume, cpg = cpg, provisioning = provisioningType, compression = compression)
assert isValid[0] is True, "Validation of base volume failed"
else:
isValid = manager.verify_volume_properties_primera(base_volume, cpg = cpg, provisioning = provisioningType, compression = compression)
assert isValid is True, "Validation of base volume failed"
logging.getLogger().info("base volume check on the array successfull")
#Validating snapshot volume properties
#hpe3par_cli = manager.get_3par_cli_client(snap_yml)
snap_volume = manager.get_volume_from_array(globals.hpe3par_cli, pvc_crd['spec']['record']['Name'])
isValid = manager.verify_volume_properties(snap_volume , name = pvc_crd['spec']['record']['Name'], copyOf = pvc_crd['spec']['record']['ParentBackendName'], snapCPG = snapCPG)
assert isValid is True, "Validation of snapshot volume failed"
logging.getLogger().info("snapshot volume check on the array successfull")
time.sleep(20)
# Deleting created resources
manager.hpe_delete_pod_object_by_name(snap_pod.metadata.name, snap_pod.metadata.namespace)
flag = manager.check_if_deleted(180, snap_pod.metadata.name, "Pod", namespace=snap_pod.metadata.namespace)
assert flag is True, "POD %s delete status check timedout..." % snap_pod.metadata.name
manager.delete_pvc(snap_pvc_obj.metadata.name)
flag = manager.check_if_deleted(2, snap_pvc_obj.metadata.name, "PVC", namespace=snap_pvc_obj.metadata.namespace)
assert flag is True, "PVC %s delete status check timedout..." % snap_pvc_obj.metadata.name
manager.delete_sc(sc_snap.metadata.name)
flag = manager.check_if_deleted(2, sc_snap.metadata.name, "SC", None)
assert flag is True, "SC %s delete status check timedout..." % sc_snap.metadata.name
manager.hpe_delete_pod_object_by_name(base_pod_obj.metadata.name, base_pod_obj.metadata.namespace)
flag = manager.check_if_deleted(180, base_pod_obj.metadata.name, "Pod", namespace=base_pod_obj.metadata.namespace)
assert flag is True, "POD %s delete status check timedout..." % base_pod_obj.metadata.name
manager.delete_pvc(base_pvc_obj.metadata.name)
flag = manager.check_if_deleted(2, base_pvc_obj.metadata.name, "Pod", namespace=base_pvc_obj.metadata.namespace)
assert flag is True, "PVC %s delete status check timedout..." % base_pvc_obj.metadata.name
manager.delete_sc(sc.metadata.name)
flag = manager.check_if_deleted(2, sc.metadata.name, "SC", None)
assert flag is True, "SC %s delete status check timedout..." % sc.metadata.name
#manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(sc_snap, pvc_snap, snap_pod)
cleanup(sc, pvc, pod)
'''def create_virtual_copyOf_tdvv_vol():
base_yml = 'YAML/virtual-copy/virtual-copy-base-vol-tc2.yml'
snap_yml = 'YAML/virtual-copy/virtual-copy-snap-vol-tc2.yml'
hpe3par_cli = None
snap_pvc = None
clone_pod_obj = None
timeout = 900
secret = None
sc = None
pvc = None
pod = None
isPresent = False
isValid = False
try:
with open('YAML/virtual-copy/testcase2_base_sc.yml', "r") as ymlfile:
cfg = yaml.load(ymlfile)
array_ip, array_uname, array_pwd, protocol = manager.read_array_prop(base_yml)
# Creating base volume now in CSI
secret = manager.create_secret(base_yml)
sc = manager.create_sc(base_yml)
pvc = manager.create_pvc(base_yml)
print("Check in events if volume is created...")
flag, base_pvc_obj = manager.check_status(30, pvc.metadata.name, kind='pvc', status='Bound',
namespace=pvc.metadata.namespace)
assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % base_pvc_obj.metadata.name
try:
# Export base volume
base_pod = manager.create_pod(base_yml)
flag, base_pod_obj = manager.check_status(timeout, base_pod.metadata.name, kind='pod', status='Running',
namespace=base_pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % base_pod.metadata.name
# Checking base volume data
command = ['/bin/sh', '-c', 'ls -l /export']
data = manager.hpe_connect_pod_container(base_pod.metadata.name, command)
if any("mydata.txt" in x for x in data.split('\n')):
isPresent = True
assert isPresent is True, "File not present in base volume"
time.sleep(20)
except Exception as e:
cleanup(secret,sc,pvc,base_pod)
raise e
# Creating snap volume in CSI
sc_snap = manager.create_sc(snap_yml)
pvc_snap = manager.create_pvc(snap_yml)
print("Check in events if volume is created...")
flag, snap_pvc_obj = manager.check_status(30, pvc_snap.metadata.name, kind='pvc', status='Bound',
namespace=pvc_snap.metadata.namespace)
assert flag is True, "PVC %s status check timed out, not in Bound state yet..." % snap_pvc_obj.metadata.name
try:
#Export snapshot volume
snap_pod = manager.create_pod(snap_yml)
flag, snap_pod_obj = manager.check_status(timeout, snap_pod.metadata.name, kind='pod', status='Running',
namespace=snap_pod.metadata.namespace)
assert flag is True, "Pod %s status check timed out, not in Running state yet..." % snap_pod.metadata.name
# Validating data on snapshot volume
isPresent = False
command = ['/bin/sh', '-c', 'ls -l /export']
snap_data = manager.hpe_connect_pod_container(snap_pod.metadata.name, command)
if any("mydata.txt" in x for x in snap_data.split('\n')):
isPresent = True
assert isPresent is True, "File on base volume not found in snap volume"
isPresent = False
if any("mysnapdata.txt" in x for x in snap_data.split('\n')):
isPresent = True
assert isPresent is True, "File not present in snap volume"
except Exception as e:
cleanup(None, sc_snap, snap_pvc_obj, snap_pod_obj)
cleanup(secret, sc, base_pvc_obj, base_pod_obj)
raise e
#Validate snapshot pvc crd
pvc_crd = manager.get_pvc_crd("pvc-"+snap_pvc_obj.metadata.uid)
assert pvc_crd['spec']['record']['BaseSnapshotId'] == "pvc-"+snap_pvc_obj.metadata.uid, "Base snapshot id is incorrect %s" % pvc_crd['spec']['record']['BaseSnapshotId']
assert pvc_crd['spec']['record']['ParentVolumeId'] == "pvc-"+base_pvc_obj.metadata.uid, "Parent id is incorrect %s" % pvc_crd['spec']['record']['ParentVolumeId']
#Validating base volume properties
hpe3par_cli = manager.get_3par_cli_client(base_yml)
base_volume = manager.get_volume_from_array(hpe3par_cli, pvc_crd['spec']['record']['ParentBackendName'])
isValid = manager.verify_volume_properties_primera(base_volume , cpg = cfg['parameters']['cpg'], provisioning = 'dedup')
assert isValid is True, "Validation of snapshot volume failed"
#Validating snapshot volume properties
#hpe3par_cli = manager.get_3par_cli_client(snap_yml)
snap_volume = manager.get_volume_from_array(hpe3par_cli, pvc_crd['spec']['record']['Name'])
isValid = manager.verify_volume_properties(snap_volume , name = pvc_crd['spec']['record']['Name'], copyOf = pvc_crd['spec']['record']['ParentBackendName'])
assert isValid is True, "Validation of snapshot volume failed"
# Deleting created resources
manager.hpe_delete_pod_object_by_name(snap_pod.metadata.name, snap_pod.metadata.namespace)
flag = manager.check_if_deleted(180, snap_pod.metadata.name, "Pod", namespace=snap_pod.metadata.namespace)
assert flag is True, "POD %s delete status check timedout..." % snap_pod.metadata.name
manager.delete_pvc(snap_pvc_obj.metadata.name)
flag = manager.check_if_deleted(2, snap_pvc_obj.metadata.name, "PVC", namespace=snap_pvc_obj.metadata.namespace)
assert flag is True, "PVC %s delete status check timedout..." % snap_pvc_obj.metadata.name
manager.delete_sc(sc_snap.metadata.name)
flag = manager.check_if_deleted(2, sc_snap.metadata.name, "SC")
assert flag is True, "SC %s delete status check timedout..." % sc_snap.metadata.name
manager.hpe_delete_pod_object_by_name(base_pod_obj.metadata.name, base_pod_obj.metadata.namespace)
flag = manager.check_if_deleted(180, base_pod_obj.metadata.name, "Pod", namespace=base_pod_obj.metadata.namespace)
assert flag is True, "POD %s delete status check timedout..." % base_pod_obj.metadata.name
manager.delete_pvc(base_pvc_obj.metadata.name)
flag = manager.check_if_deleted(2, base_pvc_obj.metadata.name, "Pod", namespace=base_pvc_obj.metadata.namespace)
assert flag is True, "PVC %s delete status check timedout..." % base_pvc_obj.metadata.name
manager.delete_sc(sc.metadata.name)
flag = manager.check_if_deleted(2, sc.metadata.name, "SC")
assert flag is True, "SC %s delete status check timedout..." % sc.metadata.name
manager.delete_secret(secret.metadata.name, secret.metadata.namespace)
finally:
# Now cleanup secret, sc, pv, pvc, pod
cleanup(None, sc_snap, snap_pvc_obj, snap_pod_obj)
cleanup(secret, sc, base_pvc_obj, base_pod_obj)
if hpe3par_cli is not None:
hpe3par_cli.logout()'''
def cleanup(sc, pvc, pod):
print("====== cleanup :START =========")
#logging.info("====== cleanup after failure:START =========")
if pod is not None and manager.check_if_deleted(2, pod.metadata.name, "Pod", namespace=pod.metadata.namespace) is False:
manager.delete_pod(pod.metadata.name, pod.metadata.namespace)
if pvc is not None and manager.check_if_deleted(2, pvc.metadata.name, "PVC", namespace=pvc.metadata.namespace) is False:
manager.delete_pvc(pvc.metadata.name)
assert manager.check_if_crd_deleted(pvc.spec.volume_name, "hpevolumeinfos") is True, \
"CRD %s of %s is not deleted yet. Taking longer..." % (pvc.spec.volume_name, 'hpevolumeinfos')
if sc is not None and manager.check_if_deleted(2, sc.metadata.name, "SC", None) is False:
manager.delete_sc(sc.metadata.name)
print("====== cleanup :END =========")
#logging.info("====== cleanup after failure:END =========")