-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvc_to_pvc_clone.py
111 lines (95 loc) · 4.03 KB
/
pvc_to_pvc_clone.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
import logging
import pytest
logger = logging.getLogger(__name__)
class TestClone(ManageTest):
"""
Tests to verify PVC to PVC clone feature
"""
@pytest.fixture(autouse=True)
def setup(self, interface_type, pvc_factory, pod_factory):
"""
create resources for the test
Args:
interface_type(str): The type of the interface
(e.g. CephBlockPool, CephFileSystem)
pvc_factory: A fixture to create new pvc
pod_factory: A fixture to create new pod
"""
self.pvc_obj = pvc_factory(
interface=interface_type, size=1, status=constants.STATUS_BOUND
)
self.pod_obj = pod_factory(
interface=interface_type, pvc=self.pvc_obj, status=constants.STATUS_RUNNING
)
def test_pvc_to_pvc_clone(self, interface_type, teardown_factory):
"""
Create a clone from an existing pvc,
verify data is preserved in the cloning.
"""
logger.info(f"Running IO on pod {self.pod_obj.name}")
file_name = self.pod_obj.name
logger.info(f"File created during IO {file_name}")
self.pod_obj.run_io(storage_type="fs", size="500M", fio_filename=file_name)
# Wait for fio to finish
self.pod_obj.get_fio_results()
logger.info(f"Io completed on pod {self.pod_obj.name}.")
# Verify presence of the file
file_path = pod.get_file_path(self.pod_obj, file_name)
logger.info(f"Actual file path on the pod {file_path}")
assert pod.check_file_existence(
self.pod_obj, file_path
), f"File {file_name} does not exist"
logger.info(f"File {file_name} exists in {self.pod_obj.name}")
# Calculate md5sum of the file.
orig_md5_sum = pod.cal_md5sum(self.pod_obj, file_name)
# Create a clone of the existing pvc.
sc_name = self.pvc_obj.backed_sc
parent_pvc = self.pvc_obj.name
clone_yaml = constants.CSI_RBD_PVC_CLONE_YAML
namespace = self.pvc_obj.namespace
if interface_type == constants.CEPHFILESYSTEM:
clone_yaml = constants.CSI_CEPHFS_PVC_CLONE_YAML
cloned_pvc_obj = pvc.create_pvc_clone(
sc_name, parent_pvc, clone_yaml, namespace
)
teardown_factory(cloned_pvc_obj)
helpers.wait_for_resource_state(cloned_pvc_obj, constants.STATUS_BOUND)
cloned_pvc_obj.reload()
# Create and attach pod to the pvc
clone_pod_obj = helpers.create_pod(
interface_type=interface_type,
pvc_name=cloned_pvc_obj.name,
namespace=cloned_pvc_obj.namespace,
pod_dict_path=constants.NGINX_POD_YAML,
)
# Confirm that the pod is running
helpers.wait_for_resource_state(
resource=clone_pod_obj, state=constants.STATUS_RUNNING
)
clone_pod_obj.reload()
teardown_factory(clone_pod_obj)
# Verify file's presence on the new pod
logger.info(
f"Checking the existence of {file_name} on cloned pod "
f"{clone_pod_obj.name}"
)
assert pod.check_file_existence(
clone_pod_obj, file_path
), f"File {file_path} does not exist"
logger.info(f"File {file_name} exists in {clone_pod_obj.name}")
# Verify Contents of a file in the cloned pvc
# by validating if md5sum matches.
logger.info(
f"Verifying that md5sum of {file_name} "
f"on pod {self.pod_obj.name} matches with md5sum "
f"of the same file on restore pod {clone_pod_obj.name}"
)
assert pod.verify_data_integrity(
clone_pod_obj, file_name, orig_md5_sum
), "Data integrity check failed"
logger.info("Data integrity check passed, md5sum are same")
logger.info("Run IO on new pod")
clone_pod_obj.run_io(storage_type="fs", size="100M", runtime=10)
# Wait for IO to finish on the new pod
clone_pod_obj.get_fio_results()
logger.info(f"IO completed on pod {clone_pod_obj.name}")