# sg_persist
# Before use sg_persist ocft test case you have to prepare to make pacemaker 
# can be started successfully because sg_persist RA needs to use the result of
# `crm_node -i` as sg_persist register key.

CONFIG
	Agent sg_persist
	AgentRoot /usr/lib/ocf/resource.d/heartbeat
	InstallPackage sg3_utils
	HangTimeout 20

VARIABLE
	
	# Please set the disk you want to test
	#OCFT_DEVS="/dev/disk/by-id/scsi-14945540000000000844965720e6e555176b19461345d68d5"
	OCFT_DEVS=

	# please set the IP addrees of the other server.
	IP_2=
	
SETUP-AGENT
	# start pacemaker to get node_id through crm_node -i
	systemctl start pacemaker

CLEANUP-AGENT

CASE-BLOCK required_args
	Env HA_SBIN_DIR=""
	Env OCF_RESKEY_devs="$OCFT_DEVS"
	Env OCF_RESKEY_reservation_type=1
	Env OCF_RESKEY_CRM_meta_notify=true
	Env OCF_RESKEY_CRM_meta_master_max=1

CASE-BLOCK required_args_error
	Env HA_SBIN_DIR=""
	Env OCF_RESKEY_devs="$OCFT_DEVS"
	Env OCF_RESKEY_reservation_type=1
	Env OCF_RESKEY_CRM_meta_notify=true
	Env OCF_RESKEY_CRM_meta_master_max=2

CASE-BLOCK required_args_type_5
	Env HA_SBIN_DIR=""
	Env OCF_RESKEY_devs="$OCFT_DEVS"
	Env OCF_RESKEY_reservation_type=5
	Env OCF_RESKEY_CRM_meta_notify=true
	Env OCF_RESKEY_CRM_meta_master_max=1

CASE-BLOCK required_args_type_7
	Env HA_SBIN_DIR=""
	Env OCF_RESKEY_devs="$OCFT_DEVS"
	Env OCF_RESKEY_reservation_type=7
	Env OCF_RESKEY_CRM_meta_notify=true
	Env OCF_RESKEY_CRM_meta_master_max=2

CASE-BLOCK default_status
	AgentRun stop

CASE-BLOCK prepare
	Include required_args
	Include default_status

CASE-BLOCK prepare_type_5
	Include required_args_type_5
	Include default_status

CASE-BLOCK prepare_type_7
	Include required_args_type_7
	Include default_status

CASE "check base env"
	Include prepare
	AgentRun start OCF_SUCCESS

CASE "check base env: unset 'OCF_RESKEY_sg_persist_devs'"
	Include prepare
	Unenv OCF_RESKEY_devs
	AgentRun start OCF_ERR_INSTALLED

CASE "validate all"
	Include required_args
	AgentRun validate-all OCF_SUCCESS

CASE "validate all--type:5"
	Include required_args_type_5
	AgentRun validate-all OCF_SUCCESS

CASE "validate all--type:7"
	Include required_args_type_7
	AgentRun validate-all OCF_SUCCESS

CASE "validate all--error configured"
	Include required_args_error
	AgentRun validate-all OCF_ERR_CONFIGURED

CASE "normal start"
	Include prepare
	AgentRun start OCF_SUCCESS

CASE "normal stop"
	Include prepare
	AgentRun start
	AgentRun stop OCF_SUCCESS

CASE "double start"
	Include prepare
	AgentRun start
	AgentRun start OCF_SUCCESS

CASE "double stop"
	Include prepare
	AgentRun stop
	AgentRun stop OCF_SUCCESS

CASE "monitor when running"
	Include prepare
	AgentRun start
	AgentRun monitor OCF_SUCCESS

CASE "monitor when not running"
	Include prepare
	AgentRun stop
	AgentRun monitor OCF_NOT_RUNNING

CASE "Primary/Secondary monitor"
	Include prepare
	AgentRun start
	AgentRun promote
	AgentRun monitor OCF_RUNNING_MASTER
	AgentRun demote
	AgentRun monitor OCF_SUCCESS
	AgentRun stop

CASE "promote/demote test in single-primary mode"
	Include prepare
	Include@$IP_2 prepare

    # start 
	AgentRun start
	AgentRun@$IP_2 start

	# promote local first
	AgentRun promote OCF_SUCCESS

    # demote local prepare for remote promote
	AgentRun demote
    
    # remote promote
	AgentRun@$IP_2 promote OCF_SUCCESS
	AgentRun@$IP_2 monitor OCF_RUNNING_MASTER
	AgentRun monitor OCF_SUCCESS
	
     # promote local then promote(by preempt) remote, which will cause local OCF_NOT_RUNNING
	AgentRun promote OCF_SUCCESS
	AgentRun monitor OCF_RUNNING_MASTER
	AgentRun@$IP_2 monitor OCF_NOT_RUNNING

    # remove all reservation registration
	AgentRun demote
	AgentRun stop 
	AgentRun@$IP_2 stop


CASE "normal start--type 5"
	Include prepare_type_5
	Include@$IP_2 prepare_type_5
	AgentRun start OCF_SUCCESS
	AgentRun@$IP_2 start OCF_SUCCESS

CASE "promote/demote test in single-primary mode"
	Include prepare_type_5
	Include@$IP_2 prepare_type_5

    # start 
	AgentRun start
	AgentRun@$IP_2 start

    # promote local first
	AgentRun promote OCF_SUCCESS
	AgentRun monitor OCF_RUNNING_MASTER

    # demote local prepare for remote promote
	AgentRun demote
	# remote promote
	AgentRun@$IP_2 promote OCF_SUCCESS
	AgentRun@$IP_2 monitor OCF_RUNNING_MASTER
	AgentRun monitor OCF_SUCCESS
	
     # promote local then promote(by preempt) remote, which will cause local OCF_NOT_RUNNING
	AgentRun promote OCF_SUCCESS
	AgentRun monitor OCF_RUNNING_MASTER
	AgentRun@$IP_2 monitor OCF_NOT_RUNNING

    # remove all reservation registration
	AgentRun demote
	AgentRun stop 
	AgentRun@$IP_2 stop

CASE "normal start--type 7: 2 masters"
	Include prepare_type_7
	Include@$IP_2 prepare_type_7
	AgentRun start OCF_SUCCESS
	AgentRun@$IP_2 start OCF_SUCCESS


CASE "Primary/Primary monitor--type 7"
	Include prepare_type_7
	Include@$IP_2 prepare_type_7
	
	AgentRun start OCF_SUCCESS
	AgentRun@$IP_2 start OCF_SUCCESS

	AgentRun promote OCF_SUCCESS
	AgentRun monitor OCF_RUNNING_MASTER

	AgentRun@$IP_2 promote OCF_SUCCESS
	AgentRun monitor OCF_RUNNING_MASTER
	AgentRun@$IP_2 monitor OCF_RUNNING_MASTER
	
	AgentRun demote OCF_SUCCESS
	AgentRun monitor OCF_NOT_RUNNING
	AgentRun@$IP_2 demote OCF_SUCCESS
	AgentRun@$IP_2 monitor OCF_NOT_RUNNING
	
	AgentRun stop 
	AgentRun@$IP_2 stop
