Skip to content

Commit 524d36b

Browse files
authored
[Chaos][OADP] Add case CNV-12011: Reboot the worker node during OADP Backup (RedHatQE#1678)
Signed-off-by: Qixuan Wang <qwang@redhat.com>
1 parent d8703c4 commit 524d36b

7 files changed

Lines changed: 268 additions & 120 deletions

File tree

tests/chaos/oadp/__init__.py

Whitespace-only changes.

tests/chaos/oadp/conftest.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import datetime
2+
import logging
3+
4+
import pytest
5+
6+
from utilities.constants import BACKUP_STORAGE_LOCATION, FILE_NAME_FOR_BACKUP, TEXT_TO_TEST, TIMEOUT_3MIN, TIMEOUT_10MIN
7+
from utilities.infra import ExecCommandOnPod, wait_for_node_status
8+
from utilities.oadp import VeleroBackup, create_rhel_vm
9+
from utilities.storage import write_file
10+
11+
LOGGER = logging.getLogger(__name__)
12+
13+
14+
@pytest.fixture()
15+
def rhel_vm_with_dv_running(request, admin_client, chaos_namespace, snapshot_storage_class_name_scope_module):
16+
"""
17+
Create a RHEL VM with a DataVolume.
18+
"""
19+
vm_name = request.param["vm_name"]
20+
21+
with create_rhel_vm(
22+
storage_class=snapshot_storage_class_name_scope_module,
23+
namespace=chaos_namespace.name,
24+
vm_name=vm_name,
25+
dv_name=f"dv-{vm_name}",
26+
client=admin_client,
27+
wait_running=True,
28+
rhel_image=request.param["rhel_image"],
29+
) as vm:
30+
write_file(
31+
vm=vm,
32+
filename=FILE_NAME_FOR_BACKUP,
33+
content=TEXT_TO_TEST,
34+
stop_vm=False,
35+
)
36+
yield vm
37+
38+
39+
@pytest.fixture()
40+
def oadp_backup_in_progress(admin_client, chaos_namespace, rhel_vm_with_dv_running):
41+
timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
42+
backup_name = f"backup-{timestamp}"
43+
44+
with VeleroBackup(
45+
name=backup_name,
46+
included_namespaces=[chaos_namespace.name],
47+
client=admin_client,
48+
snapshot_move_data=True,
49+
storage_location=BACKUP_STORAGE_LOCATION,
50+
wait_complete=False,
51+
) as backup:
52+
backup.wait_for_status(status=backup.Backup.Status.INPROGRESS, timeout=TIMEOUT_3MIN)
53+
yield backup
54+
55+
56+
@pytest.fixture()
57+
def rebooted_vm_source_node(rhel_vm_with_dv_running, oadp_backup_in_progress, workers_utility_pods):
58+
vm_node = rhel_vm_with_dv_running.vmi.node
59+
60+
LOGGER.info(f"Rebooting node {vm_node.name}")
61+
ExecCommandOnPod(utility_pods=workers_utility_pods, node=vm_node).exec(command="shutdown -r now", ignore_rc=True)
62+
wait_for_node_status(node=vm_node, status=False, wait_timeout=TIMEOUT_10MIN)
63+
64+
LOGGER.info(f"Waiting for node {vm_node.name} to come back online")
65+
wait_for_node_status(node=vm_node, status=True, wait_timeout=TIMEOUT_10MIN)
66+
return

tests/chaos/oadp/test_oadp.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import logging
2+
3+
import pytest
4+
5+
from tests.os_params import RHEL_LATEST
6+
from utilities.constants import TIMEOUT_10MIN
7+
8+
LOGGER = logging.getLogger(__name__)
9+
10+
11+
@pytest.mark.destructive
12+
@pytest.mark.chaos
13+
@pytest.mark.parametrize(
14+
"rhel_vm_with_dv_running",
15+
[
16+
pytest.param(
17+
{
18+
"vm_name": "vm-node-reboot-12011",
19+
"rhel_image": RHEL_LATEST["image_name"],
20+
},
21+
marks=pytest.mark.polarion("CNV-12011"),
22+
),
23+
],
24+
indirect=True,
25+
)
26+
def test_reboot_vm_node_during_backup(
27+
oadp_backup_in_progress,
28+
rebooted_vm_source_node,
29+
):
30+
"""
31+
Reboot the worker node where the VM is located during OADP backup using DataMover.
32+
Validate that backup eventually PartiallyFailed.
33+
"""
34+
35+
LOGGER.info(
36+
f"Waiting for backup to reach "
37+
f"'{oadp_backup_in_progress.Backup.Status.PARTIALLYFAILED}' status after node recovery"
38+
)
39+
oadp_backup_in_progress.wait_for_status(
40+
status=oadp_backup_in_progress.Backup.Status.PARTIALLYFAILED, timeout=TIMEOUT_10MIN
41+
)

tests/data_protection/oadp/conftest.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
from ocp_resources.namespace import Namespace
44

55
from tests.data_protection.oadp.utils import (
6+
VeleroRestore,
7+
is_storage_class_support_volume_mode,
8+
)
9+
from utilities.constants import (
10+
BACKUP_STORAGE_LOCATION,
611
FILE_NAME_FOR_BACKUP,
12+
OS_FLAVOR_RHEL,
713
TEXT_TO_TEST,
14+
TIMEOUT_8MIN,
15+
TIMEOUT_15MIN,
16+
Images,
17+
)
18+
from utilities.infra import create_ns
19+
from utilities.oadp import (
820
VeleroBackup,
9-
VeleroRestore,
1021
create_rhel_vm,
11-
is_storage_class_support_volume_mode,
1222
)
13-
from utilities.constants import OS_FLAVOR_RHEL, TIMEOUT_8MIN, TIMEOUT_15MIN, Images
14-
from utilities.infra import create_ns
1523
from utilities.storage import (
1624
check_upload_virtctl_result,
1725
create_dv,
@@ -132,7 +140,7 @@ def velero_backup_first_namespace_using_datamover(namespace_for_backup):
132140
],
133141
name="datamover-backup-ns",
134142
snapshot_move_data=True,
135-
storage_location="dpa-1",
143+
storage_location=BACKUP_STORAGE_LOCATION,
136144
) as backup:
137145
yield backup
138146

@@ -226,7 +234,7 @@ def velero_backup_second_namespace_using_datamover(namespace_for_backup2):
226234
],
227235
name="datamover-backup-ns2",
228236
snapshot_move_data=True,
229-
storage_location="dpa-1",
237+
storage_location=BACKUP_STORAGE_LOCATION,
230238
) as backup:
231239
yield backup
232240

tests/data_protection/oadp/utils.py

Lines changed: 4 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,26 @@
11
import logging
2-
import shlex
3-
from contextlib import contextmanager
42

5-
from ocp_resources.backup import Backup
6-
from ocp_resources.datavolume import DataVolume
73
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
84
from ocp_resources.restore import Restore
95
from ocp_resources.storage_profile import StorageProfile
10-
from ocp_resources.virtual_machine import VirtualMachine
116

127
from utilities import console
138
from utilities.constants import (
9+
ADP_NAMESPACE,
10+
FILE_NAME_FOR_BACKUP,
1411
LS_COMMAND,
15-
OS_FLAVOR_RHEL,
12+
TEXT_TO_TEST,
1613
TIMEOUT_5MIN,
1714
TIMEOUT_10SEC,
1815
TIMEOUT_15SEC,
1916
TIMEOUT_20SEC,
20-
Images,
2117
)
2218
from utilities.infra import (
23-
cleanup_artifactory_secret_and_config_map,
24-
get_artifactory_config_map,
25-
get_artifactory_secret,
26-
get_http_image_url,
27-
get_pod_by_name_prefix,
2819
unique_name,
2920
)
30-
from utilities.virt import VirtualMachineForTests, running_vm
21+
from utilities.oadp import delete_velero_resource
3122

32-
ADP_NAMESPACE = "openshift-adp"
33-
FILE_NAME_FOR_BACKUP = "file_before_backup.txt"
3423
LOGGER = logging.getLogger(__name__)
35-
TEXT_TO_TEST = "text"
36-
37-
38-
def delete_velero_resource(resource, client):
39-
velero_pod = get_pod_by_name_prefix(dyn_client=client, pod_prefix="velero", namespace=ADP_NAMESPACE)
40-
velero_pod.execute(
41-
command=shlex.split(f"bash -c 'echo Y | ./velero delete {resource.kind.lower()} {resource.name}'")
42-
)
43-
44-
45-
class VeleroBackup(Backup):
46-
def __init__(
47-
self,
48-
name,
49-
namespace=ADP_NAMESPACE,
50-
included_namespaces=None,
51-
client=None,
52-
teardown=False,
53-
yaml_file=None,
54-
excluded_resources=None,
55-
wait_complete=True,
56-
snapshot_move_data=False,
57-
storage_location=None,
58-
timeout=TIMEOUT_5MIN,
59-
**kwargs,
60-
):
61-
super().__init__(
62-
name=unique_name(name=name),
63-
namespace=namespace,
64-
included_namespaces=included_namespaces,
65-
client=client,
66-
teardown=teardown,
67-
yaml_file=yaml_file,
68-
excluded_resources=excluded_resources,
69-
storage_location=storage_location,
70-
snapshot_move_data=snapshot_move_data,
71-
**kwargs,
72-
)
73-
self.wait_complete = wait_complete
74-
self.timeout = timeout
75-
76-
def __enter__(self):
77-
super().__enter__()
78-
if self.wait_complete:
79-
self.wait_for_status(
80-
status=self.Status.COMPLETED,
81-
timeout=self.timeout,
82-
)
83-
return self
84-
85-
def __exit__(self, exception_type, exception_value, traceback):
86-
delete_velero_resource(resource=self, client=self.client)
8724

8825

8926
class VeleroRestore(Restore):
@@ -126,53 +63,6 @@ def __exit__(self, exception_type, exception_value, traceback):
12663
delete_velero_resource(resource=self, client=self.client)
12764

12865

129-
@contextmanager
130-
def create_rhel_vm(
131-
storage_class,
132-
namespace,
133-
dv_name,
134-
vm_name,
135-
rhel_image,
136-
client=None,
137-
wait_running=True,
138-
volume_mode=None,
139-
):
140-
artifactory_secret = get_artifactory_secret(namespace=namespace)
141-
artifactory_config_map = get_artifactory_config_map(namespace=namespace)
142-
dv = DataVolume(
143-
name=dv_name,
144-
namespace=namespace,
145-
source="http",
146-
url=get_http_image_url(
147-
image_directory=Images.Rhel.DIR,
148-
image_name=rhel_image,
149-
),
150-
storage_class=storage_class,
151-
size=Images.Rhel.DEFAULT_DV_SIZE,
152-
api_name="storage",
153-
volume_mode=volume_mode,
154-
secret=artifactory_secret,
155-
cert_configmap=artifactory_config_map.name,
156-
)
157-
dv.to_dict()
158-
dv_metadata = dv.res["metadata"]
159-
with VirtualMachineForTests(
160-
client=client,
161-
name=vm_name,
162-
namespace=dv_metadata["namespace"],
163-
os_flavor=OS_FLAVOR_RHEL,
164-
memory_guest=Images.Rhel.DEFAULT_MEMORY_SIZE,
165-
data_volume_template={"metadata": dv_metadata, "spec": dv.res["spec"]},
166-
run_strategy=VirtualMachine.RunStrategy.ALWAYS,
167-
) as vm:
168-
if wait_running:
169-
running_vm(vm=vm, wait_for_interfaces=True)
170-
yield vm
171-
cleanup_artifactory_secret_and_config_map(
172-
artifactory_secret=artifactory_secret, artifactory_config_map=artifactory_config_map
173-
)
174-
175-
17666
def check_file_in_vm(vm):
17767
with console.Console(vm=vm) as vm_console:
17868
vm_console.sendline(LS_COMMAND)

utilities/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,3 +902,9 @@ class NamespacesNames:
902902
LATEST_RELEASE_STR = "latest_released"
903903
OS_VERSION_STR = "os_version"
904904
DATA_SOURCE_STR = "data_source"
905+
906+
# OADP
907+
ADP_NAMESPACE = "openshift-adp"
908+
FILE_NAME_FOR_BACKUP = "file_before_backup.txt"
909+
TEXT_TO_TEST = "text"
910+
BACKUP_STORAGE_LOCATION = "dpa-1"

0 commit comments

Comments
 (0)