Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve vrg discovered app #11406

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 49 additions & 16 deletions ocs_ci/helpers/dr_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def relocate(
old_primary=old_primary,
workload_namespace=workload_instance.workload_namespace,
workload_dir=workload_instance.workload_dir,
vrg_name=workload_instance.discovered_apps_placement_name,
)
config.switch_ctx(restore_index)

Expand Down Expand Up @@ -488,16 +489,23 @@ def check_vr_state(state, namespace):
return False


def check_vrg_existence(namespace):
def check_vrg_existence(namespace, vrg_name=None):
"""
Check if VRG resource exists in the given namespace

Args:
namespace (str): the namespace of the VRG resource
vrg_name (str): Name of VRG

"""
if not vrg_name:
vrg_name = ""
vrg_list = (
ocp.OCP(kind=constants.VOLUME_REPLICATION_GROUP, namespace=namespace)
ocp.OCP(
kind=constants.VOLUME_REPLICATION_GROUP,
namespace=namespace,
resource_name=vrg_name,
)
.get()
.get("items")
)
Expand All @@ -507,20 +515,30 @@ def check_vrg_existence(namespace):
return False


def check_vrg_state(state, namespace):
def check_vrg_state(state, namespace, resource_name=None):
"""
Check if VRG in the given namespace is in expected state

Args:
state (str): The VRG state to check for (e.g. 'primary', 'secondary')
namespace (str): the namespace of the VRG resources
resource_name (str): Name of VRG resource

Returns:
bool: True if VRG is in expected state or was deleted, False otherwise

"""
vrg_obj = ocp.OCP(kind=constants.VOLUME_REPLICATION_GROUP, namespace=namespace)
vrg_list = vrg_obj.get().get("items")

vrg_obj = ocp.OCP(
kind=constants.VOLUME_REPLICATION_GROUP,
namespace=namespace,
)
if resource_name:
vrg_list = vrg_obj.get(resource_name=resource_name)
vrg_list_index = vrg_list
else:
vrg_list_zero_index = vrg_list = vrg_obj.get().get("items")
vrg_list_index = vrg_list_zero_index[0]

# Skip state check if resource was deleted
if len(vrg_list) == 0 and state.lower() == "secondary":
Expand All @@ -531,10 +549,9 @@ def check_vrg_state(state, namespace):
else:
logger.info("VRG resource not found")
return False

vrg_name = vrg_list[0]["metadata"]["name"]
desired_state = vrg_list[0]["spec"]["replicationState"]
current_state = vrg_list[0]["status"]["state"]
vrg_name = vrg_list_index["metadata"]["name"]
desired_state = vrg_list_index["spec"]["replicationState"]
current_state = vrg_list_index["status"]["state"]
logger.info(
f"VRG: {vrg_name} desired state is {desired_state}, current state is {current_state}"
)
Expand All @@ -549,7 +566,7 @@ def check_vrg_state(state, namespace):


def wait_for_replication_resources_creation(
vr_count, namespace, timeout, discovered_apps=False
vr_count, namespace, timeout, discovered_apps=False, vrg_name=None
):
"""
Wait for replication resources to be created
Expand All @@ -560,6 +577,7 @@ def wait_for_replication_resources_creation(
timeout (int): time in seconds to wait for VR or ReplicationSource resources to be created
or reach expected state
discovered_apps (bool): If true then deployed workload is discovered_apps
vrg_name (str): Name of VRG

Raises:
TimeoutExpiredError: In case replication resources not created
Expand Down Expand Up @@ -615,6 +633,7 @@ def wait_for_replication_resources_creation(
func=check_vrg_state,
state="primary",
namespace=vrg_namespace,
resource_name=vrg_name,
)
if not sample.wait_for_func_status(result=True):
error_msg = "VRG hasn't reached expected state primary within the time limit."
Expand All @@ -623,7 +642,7 @@ def wait_for_replication_resources_creation(


def wait_for_replication_resources_deletion(
namespace, timeout, check_state=True, discovered_apps=False
namespace, timeout, check_state=True, discovered_apps=False, vrg_name=None
):
"""
Wait for replication resources to be deleted
Expand All @@ -634,6 +653,7 @@ def wait_for_replication_resources_deletion(
state or deleted
check_state (bool): True for checking resources state before deletion, False otherwise
discovered_apps (bool): If true then deployed workload is discovered_apps
vrg_name (str): Name of VRG

Raises:
TimeoutExpiredError: In case replication resources not deleted
Expand Down Expand Up @@ -670,6 +690,7 @@ def wait_for_replication_resources_deletion(
func=check_vrg_state,
state="secondary",
namespace=vrg_namespace,
resource_name=vrg_name,
)
if not sample.wait_for_func_status(result=True):
error_msg = (
Expand All @@ -684,7 +705,11 @@ def wait_for_replication_resources_deletion(
):
logger.info("Waiting for VRG to be deleted")
sample = TimeoutSampler(
timeout=timeout, sleep=5, func=check_vrg_existence, namespace=vrg_namespace
timeout=timeout,
sleep=5,
func=check_vrg_existence,
namespace=vrg_namespace,
vrg_name=vrg_name,
)
if not sample.wait_for_func_status(result=False):
error_msg = "VRG resource not deleted"
Expand All @@ -709,6 +734,7 @@ def wait_for_all_resources_creation(
timeout=900,
skip_replication_resources=False,
discovered_apps=False,
vrg_name=None,
):
"""
Wait for workload and replication resources to be created
Expand All @@ -720,6 +746,7 @@ def wait_for_all_resources_creation(
timeout (int): time in seconds to wait for resource creation
skip_replication_resources (bool): if true vr status wont't be check
discovered_apps (bool): If true then deployed workload is discovered_apps
vrg_name (str): Name of VRG


"""
Expand All @@ -741,7 +768,7 @@ def wait_for_all_resources_creation(
)
if not skip_replication_resources:
wait_for_replication_resources_creation(
pvc_count, namespace, timeout, discovered_apps
pvc_count, namespace, timeout, discovered_apps, vrg_name
)


Expand All @@ -750,6 +777,7 @@ def wait_for_all_resources_deletion(
check_replication_resources_state=True,
timeout=1000,
discovered_apps=False,
vrg_name=None,
):
"""
Wait for workload and replication resources to be deleted
Expand All @@ -759,6 +787,7 @@ def wait_for_all_resources_deletion(
check_replication_resources_state (bool): True for checking replication resources state, False otherwise
timeout (int): time in seconds to wait for resource deletion
discovered_apps (bool): If true then deployed workload is discovered_apps
vrg_name (str): Name of VRG

"""
logger.info("Waiting for all pods to be deleted")
Expand All @@ -770,7 +799,7 @@ def wait_for_all_resources_deletion(
)

wait_for_replication_resources_deletion(
namespace, timeout, check_replication_resources_state, discovered_apps
namespace, timeout, check_replication_resources_state, discovered_apps, vrg_name
)

if not (
Expand Down Expand Up @@ -1636,7 +1665,7 @@ def replace_cluster(workload, primary_cluster_name, secondary_cluster_name):


def do_discovered_apps_cleanup(
drpc_name, old_primary, workload_namespace, workload_dir
drpc_name, old_primary, workload_namespace, workload_dir, vrg_name
):
"""
Function to clean up Resources
Expand All @@ -1646,6 +1675,8 @@ def do_discovered_apps_cleanup(
old_primary (str): Name of old primary where cleanup will happen
workload_namespace (str): Workload namespace
workload_dir (str): Dir location of workload
vrg_name (str): Name of VRG

"""
restore_index = config.cur_index
config.switch_acm_ctx()
Expand All @@ -1654,7 +1685,9 @@ def do_discovered_apps_cleanup(
config.switch_to_cluster_by_name(old_primary)
workload_path = constants.DR_WORKLOAD_REPO_BASE_DIR + "/" + workload_dir
run_cmd(f"oc delete -k {workload_path} -n {workload_namespace} --wait=false")
wait_for_all_resources_deletion(namespace=workload_namespace, discovered_apps=True)
wait_for_all_resources_deletion(
namespace=workload_namespace, discovered_apps=True, vrg_name=vrg_name
)
config.switch_acm_ctx()
drpc_obj.wait_for_progression_status(status=constants.STATUS_COMPLETED)
config.switch_ctx(restore_index)
Expand Down
1 change: 1 addition & 0 deletions ocs_ci/ocs/dr/dr_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ def verify_workload_deployment(self):
self.workload_pod_count,
self.workload_namespace,
discovered_apps=True,
vrg_name=self.discovered_apps_placement_name,
)

def create_placement(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_cnv_failover_and_relocate_discovered_apps(
old_primary=primary_cluster_name_before_failover,
workload_namespace=cnv_workloads[0].workload_namespace,
workload_dir=cnv_workloads[0].workload_dir,
vrg_name=cnv_workloads[0].discovered_apps_placement_name,
)

# Verify resources creation on secondary cluster (failoverCluster)
Expand All @@ -99,6 +100,7 @@ def test_cnv_failover_and_relocate_discovered_apps(
cnv_workloads[0].workload_pod_count,
cnv_workloads[0].workload_namespace,
discovered_apps=True,
vrg_name=cnv_workloads[0].discovered_apps_placement_name,
)
dr_helpers.wait_for_cnv_workload(
vm_name=cnv_workloads[0].vm_name,
Expand Down Expand Up @@ -161,6 +163,7 @@ def test_cnv_failover_and_relocate_discovered_apps(
cnv_workloads[0].workload_pod_count,
cnv_workloads[0].workload_namespace,
discovered_apps=True,
vrg_name=cnv_workloads[0].discovered_apps_placement_name,
)
dr_helpers.wait_for_cnv_workload(
vm_name=cnv_workloads[0].vm_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_failover_and_relocate_discovered_apps(self, discovered_apps_dr_workload
old_primary=primary_cluster_name_before_failover,
workload_namespace=rdr_workload.workload_namespace,
workload_dir=rdr_workload.workload_dir,
vrg_name=rdr_workload.discovered_apps_placement_name,
)

# Verify resources creation on secondary cluster (failoverCluster)
Expand All @@ -79,6 +80,7 @@ def test_failover_and_relocate_discovered_apps(self, discovered_apps_dr_workload
rdr_workload.workload_pod_count,
rdr_workload.workload_namespace,
discovered_apps=True,
vrg_name=rdr_workload.discovered_apps_placement_name,
)

# Doing Relocate
Expand Down