def deploy_workload(self): """ Deployment specific to busybox workload """ self._deploy_prereqs() # load drpc.yaml drpc_yaml_data = templating.load_yaml(self.drpc_yaml_file) drpc_yaml_data["spec"][ "preferredCluster"] = self.preferred_primary_cluster templating.dump_to_temp_yaml(drpc_yaml_data, self.drpc_yaml_file) # TODO # drpc_yaml_file needs to be committed back to the repo # because ACM would refetch from repo directly # Create the resources on Hub cluster config.switch_acm_ctx() workload_subscription_dir = os.path.join( os.path.join(self.target_clone_dir, constants.DR_WORKLOAD_REPO_BASE_DIR), "subscription", ) run_cmd(f"oc create -k {workload_subscription_dir}") run_cmd( f"oc create -k {workload_subscription_dir}/{self.workload_name}")
def relocate(preferred_cluster, drpc_name, namespace): """ Initiates Relocate action to the specified cluster Args: preferred_cluster (str): Cluster name to which the workload should be relocated drpc_name (str): Name of the DRPC resource to apply the patch namespace (str): Name of the namespace to use """ prev_index = config.cur_index config.switch_acm_ctx() relocate_params = ( f'{{"spec":{{"action":"Relocate","preferredCluster":"{preferred_cluster}"}}}}' ) drpc_obj = ocp.OCP( kind=constants.DRPC, namespace=namespace, resource_name=drpc_name ) drpc_obj._has_phase = True logger.info(f"Initiating relocate action to {preferred_cluster}") assert drpc_obj.patch( params=relocate_params, format_type="merge" ), f"Failed to patch {constants.DRPC}: {drpc_name}" logger.info( f"Wait for {constants.DRPC}: {drpc_name} to reach {constants.STATUS_RELOCATED} phase" ) drpc_obj.wait_for_phase(constants.STATUS_RELOCATED) config.switch_ctx(prev_index)
def failover(failover_cluster, drpc_name, namespace): """ Initiates Failover action to the specified cluster Args: failover_cluster (str): Cluster name to which the workload should be failed over drpc_name (str): Name of the DRPC resource to apply the patch namespace (str): Name of the namespace to use """ prev_index = config.cur_index config.switch_acm_ctx() failover_params = ( f'{{"spec":{{"action":"Failover","failoverCluster":"{failover_cluster}"}}}}' ) drpc_obj = ocp.OCP( kind=constants.DRPC, namespace=namespace, resource_name=drpc_name ) drpc_obj._has_phase = True logger.info(f"Initiating failover action to {failover_cluster}") assert drpc_obj.patch( params=failover_params, format_type="merge" ), f"Failed to patch {constants.DRPC}: {drpc_name}" logger.info( f"Wait for {constants.DRPC}: {drpc_name} to reach {constants.STATUS_FAILEDOVER} phase" ) drpc_obj.wait_for_phase(constants.STATUS_FAILEDOVER) config.switch_ctx(prev_index)
def deploy_workload(self): """ Deployment specific to busybox workload """ self._deploy_prereqs() self.workload_namespace = self._get_workload_namespace() # load drpc.yaml drpc_yaml_data = templating.load_yaml(self.drpc_yaml_file) drpc_yaml_data["spec"][ "preferredCluster"] = self.preferred_primary_cluster templating.dump_data_to_temp_yaml(drpc_yaml_data, self.drpc_yaml_file) # TODO # drpc_yaml_file needs to be committed back to the repo # because ACM would refetch from repo directly # Create the resources on Hub cluster config.switch_acm_ctx() run_cmd(f"oc create -k {self.workload_subscription_dir}") run_cmd( f"oc create -k {self.workload_subscription_dir}/{self.workload_name}" ) self.verify_workload_deployment()
def get_drpc_name(namespace): """ Get the DRPC resource name in the given namespace Args: namespace (str): Name of the namespace Returns: str: DRPC resource name """ config.switch_acm_ctx() drpc_obj = OCP(kind=constants.DRPC, namespace=namespace).get()["items"][0] return drpc_obj["metadata"]["name"]
def delete_workload(self): """ Delete busybox workload """ primary_cluster_name = dr_helpers.get_primary_cluster_name( self.workload_namespace) config.switch_acm_ctx() run_cmd( f"oc delete -k {self.workload_subscription_dir}/{self.workload_name}" ) run_cmd(f"oc delete -k {self.workload_subscription_dir}") config.switch_to_cluster_by_name(primary_cluster_name) dr_helpers.wait_for_workload_resource_deletion(self.workload_namespace)
def relocate(preferred_cluster, namespace): """ Initiates Relocate action to the specified cluster Args: preferred_cluster (str): Cluster name to which the workload should be relocated namespace (str): Namespace where workload is running """ restore_index = config.cur_index config.switch_acm_ctx() relocate_params = f'{{"spec":{{"action":"{constants.ACTION_RELOCATE}","preferredCluster":"{preferred_cluster}"}}}}' drpc_obj = DRPC(namespace=namespace) drpc_obj.wait_for_peer_ready_status() logger.info(f"Initiating Relocate action with preferredCluster:{preferred_cluster}") assert drpc_obj.patch( params=relocate_params, format_type="merge" ), f"Failed to patch {constants.DRPC}: {drpc_obj.resource_name}" logger.info( f"Wait for {constants.DRPC}: {drpc_obj.resource_name} to reach {constants.STATUS_RELOCATED} phase" ) drpc_obj.wait_for_phase(constants.STATUS_RELOCATED) config.switch_ctx(restore_index)
def failover(failover_cluster, namespace): """ Initiates Failover action to the specified cluster Args: failover_cluster (str): Cluster name to which the workload should be failed over namespace (str): Namespace where workload is running """ restore_index = config.cur_index config.switch_acm_ctx() failover_params = f'{{"spec":{{"action":"{constants.ACTION_FAILOVER}","failoverCluster":"{failover_cluster}"}}}}' drpc_obj = DRPC(namespace=namespace) drpc_obj.wait_for_peer_ready_status() logger.info(f"Initiating Failover action with failoverCluster:{failover_cluster}") assert drpc_obj.patch( params=failover_params, format_type="merge" ), f"Failed to patch {constants.DRPC}: {drpc_obj.resource_name}" logger.info( f"Wait for {constants.DRPC}: {drpc_obj.resource_name} to reach {constants.STATUS_FAILEDOVER} phase" ) drpc_obj.wait_for_phase(constants.STATUS_FAILEDOVER) config.switch_ctx(restore_index)