Exemplo n.º 1
0
/*
 * Smoke test. Better to turn off coredump ;) This has no time limit, just restart process
 * when it dies.
 */
static int test3 (void) {
	cs_error_t error;
	unsigned int instance_id;

	qb_log (LOG_INFO, "initialize");
	error = sam_initialize (0, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", error);
		return 1;
	}
	qb_log (LOG_INFO, "register");
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't register. Error %d", error);
		return 1;
	}

	if (instance_id < 100) {
		qb_log (LOG_INFO, "iid %d: start", instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: Sending signal", instance_id);
		kill(getpid(), SIGSEGV);
		return 1;
	}

	return 0;

}
Exemplo n.º 2
0
static int setup_hc (void)
{
	cs_error_t err;
	unsigned int instance_id;

	err = sam_initialize (1000, SAM_RECOVERY_POLICY_QUIT | SAM_RECOVERY_POLICY_CMAP);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", err);
		return 2;
	}

	qb_log (LOG_INFO, " register");
	err = sam_register (&instance_id);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Can't register. Error %d", err);
		return 2;
	}
	err = sam_hc_callback_register (hc_allways_respond_cb);

	qb_log (LOG_INFO, "instance id %d: start", instance_id);
	err = sam_start ();
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Can't start hc. Error %d", err);
		return 2;
	}

	return (0);
}
Exemplo n.º 3
0
/*
 * Test event driven healtchecking.
 */
static int test5 (void)
{
	cs_error_t error;
	unsigned int instance_id;
	int hc_cb_count;

	qb_log (LOG_INFO, " initialize");
	error = sam_initialize (100, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", error);
		return 1;
	}
	qb_log (LOG_INFO, " register");
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't register. Error %d", error);
		return 1;
	}

	if (instance_id == 1) {
		qb_log (LOG_INFO, "iid %d: hc callback register", instance_id);
		error = sam_hc_callback_register (test5_hc_cb);
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't register hc cb. Error %d", error);
			return 1;
		}


		qb_log (LOG_INFO, "iid %d: start", instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}

		sleep (2);

		qb_log (LOG_INFO, "iid %d: Failed. Wasn't killed.", instance_id);
		return 1;
	}

	if (instance_id == 2) {
		error = sam_data_restore (&hc_cb_count, sizeof (hc_cb_count));
		if (error != CS_OK) {
			qb_log (LOG_ERR, "sam_data_restore should return CS_OK. Error returned %d", error);
			return 1;
		}

		if (hc_cb_count != 11) {
			qb_log (LOG_ERR, "iid %d: Premature killed. hc_cb_count should be 11 and it is %d",
				__FUNCTION__, instance_id - 1, hc_cb_count);
			return 1;

		}
		return 0;
	}

	return 1;
}
Exemplo n.º 4
0
/*
 * Test event driven healtchecking.
 */
static int test5 (void)
{
	cs_error_t error;
	unsigned int instance_id;
	int hc_cb_count;

	printf ("%s: initialize\n", __FUNCTION__);
	error = sam_initialize (100, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		fprintf (stderr, "Can't initialize SAM API. Error %d\n", error);
		return 1;
	}
	printf ("%s: register\n", __FUNCTION__);
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		fprintf (stderr, "Can't register. Error %d\n", error);
		return 1;
	}

	if (instance_id == 1) {
		printf ("%s iid %d: hc callback register\n", __FUNCTION__, instance_id);
		error = sam_hc_callback_register (test5_hc_cb);
		if (error != CS_OK) {
			fprintf (stderr, "Can't register hc cb. Error %d\n", error);
			return 1;
		}


		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}

		sleep (2);

		printf ("%s iid %d: Failed. Wasn't killed.\n", __FUNCTION__, instance_id);
		return 1;
	}

	if (instance_id == 2) {
		error = sam_data_restore (&hc_cb_count, sizeof (hc_cb_count));
		if (error != CS_OK) {
			fprintf (stderr, "sam_data_restore should return CS_OK. Error returned %d\n", error);
			return 1;
		}

		if (hc_cb_count != 11) {
			fprintf (stderr, "%s iid %d: Premature killed. hc_cb_count should be 11 and it is %d\n",
				__FUNCTION__, instance_id - 1, hc_cb_count);
			return 1;

		}
		return 0;
	}

	return 1;
}
Exemplo n.º 5
0
/*
 * This tests recovery policy quit and callback.
 */
static int test2 (void) {
	cs_error_t error;
	unsigned int instance_id;

	qb_enter();
	error = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", error);
		return 1;
	}
	qb_log (LOG_INFO, "register");
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't register. Error %d", error);
		return 1;
	}

	if (instance_id == 1) {
		signal (SIGTERM, test2_signal);

		qb_log (LOG_INFO, "iid %d: start", instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sleep 1", instance_id);
		sleep (1);

		qb_log (LOG_INFO, "iid %d: hc send", instance_id);
		error = sam_hc_send ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't send hc. Error %d", error);
			return 1;
		}


		qb_log (LOG_INFO, "iid %d: wait for delivery of signal", instance_id);
		while (!test2_sig_delivered) {
			sleep (1);
		}

		qb_log (LOG_INFO, "iid %d: wait for real kill", instance_id);

		sleep (3);
	}

	return 1;

}
Exemplo n.º 6
0
/*
 * This tests recovery policy quit and callback.
 */
static int test2 (void) {
	cs_error_t error;
	unsigned int instance_id;

	printf ("%s: initialize\n", __FUNCTION__);
	error = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT);
	if (error != CS_OK) {
		fprintf (stderr, "Can't initialize SAM API. Error %d\n", error);
		return 1;
	}
	printf ("%s: register\n", __FUNCTION__);
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		fprintf (stderr, "Can't register. Error %d\n", error);
		return 1;
	}

	if (instance_id == 1) {
		signal (SIGTERM, test2_signal);

		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}

		printf ("%s iid %d: sleep 1\n", __FUNCTION__, instance_id);
		sleep (1);

		printf ("%s iid %d: hc send\n", __FUNCTION__, instance_id);
		error = sam_hc_send ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't send hc. Error %d\n", error);
			return 1;
		}


		printf ("%s iid %d: wait for delivery of signal\n", __FUNCTION__, instance_id);
		while (!test2_sig_delivered) {
			sleep (1);
		}

		printf ("%s iid %d: wait for real kill\n", __FUNCTION__, instance_id);

		sleep (3);
	}

	return 1;

}
Exemplo n.º 7
0
/*
 * Smoke test. Better to turn off coredump ;) This has no time limit, just restart process
 * when it dies.
 */
static int test3 (void) {
	cs_error_t error;
	unsigned int instance_id;
	int tmp1, tmp2, tmp3;

	printf ("%s: initialize\n", __FUNCTION__);
	error = sam_initialize (0, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		fprintf (stderr, "Can't initialize SAM API. Error %d\n", error);
		return 1;
	}
	printf ("%s: register\n", __FUNCTION__);
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		fprintf (stderr, "Can't register. Error %d\n", error);
		return 1;
	}

	if (instance_id < 100) {
		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}

		printf ("%s iid %d: divide by zero\n", __FUNCTION__, instance_id);
		tmp2 = rand ();
		tmp3 = 0;
		tmp1 = tmp2 / tmp3;

		return 1;
	}

	return 0;

}
Exemplo n.º 8
0
/*
 * Test cmap integration + quit policy
 */
static int test8 (pid_t pid, pid_t old_pid, int test_n) {
	cmap_handle_t cmap_handle;
	cs_error_t err;
	uint64_t tstamp1, tstamp2;
	int32_t msec_diff;
	unsigned int instance_id;
	char key_name[CMAP_KEYNAME_MAXLEN];
	char *str;

	err = cmap_initialize (&cmap_handle);
	if (err != CS_OK) {
		qb_log (LOG_INFO, "Could not initialize Cluster Map API instance error %d. Test skipped", err);
		return (1);
	}

	qb_log (LOG_INFO, "test %d", test_n);

	if (test_n == 2) {
		/*
		 * Object should not exist
		 */
		qb_log (LOG_INFO, "Testing if object exists (it shouldn't)");

		snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err == CS_OK) {
			qb_log (LOG_INFO, "Could find key \"%s\": %d.", key_name, err);
			free(str);
			return (2);
		}
	}

	if (test_n == 1 || test_n == 2) {
		qb_log (LOG_INFO, " initialize");
		err = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT | SAM_RECOVERY_POLICY_CMAP);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", err);
			return 2;
		}

		qb_log (LOG_INFO, " register");
		err = sam_register (&instance_id);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't register. Error %d", err);
			return 2;
		}

		snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.recovery", pid);
		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"recovery\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "quit") != 0) {
			qb_log (LOG_INFO, "Recovery key \"%s\" is not \"quit\".", key_name);
			return (2);
		}
		free(str);

		snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "stopped") != 0) {
			qb_log (LOG_INFO, "State key is not \"stopped\".");
			return (2);
		}
		free(str);

		qb_log (LOG_INFO, "iid %d: start", instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", err);
			return 2;
		}

		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "running") != 0) {
			qb_log (LOG_INFO, "State key is not \"running\".");
			return (2);
		}
		free(str);

		qb_log (LOG_INFO, "iid %d: stop", instance_id);
		err = sam_stop ();
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't stop hc. Error %d", err);
			return 2;
		}

		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "stopped") != 0) {
			qb_log (LOG_INFO, "State key is not \"stopped\".");
			return (2);
		}
		free(str);

		qb_log (LOG_INFO, "iid %d: sleeping 5", instance_id);
		sleep (5);

		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "stopped") != 0) {
			qb_log (LOG_INFO, "State key is not \"stopped\".");
			return (2);
		}
		free(str);

		qb_log (LOG_INFO, "iid %d: start 2", instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", err);
			return 2;
		}

		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "running") != 0) {
			qb_log (LOG_INFO, "State key is not \"running\".");
			return (2);
		}
		free(str);

		if (test_n == 2) {
			qb_log (LOG_INFO, "iid %d: sleeping 5. Should be killed", instance_id);
			sleep (5);

			return (2);
		} else {
			qb_log (LOG_INFO, "iid %d: Test HC", instance_id);
			err = sam_hc_send ();
			if (err != CS_OK) {
				qb_log (LOG_ERR, "Can't send hc. Error %d", err);
				return 2;
			}

			snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.last_updated", pid);
			err = cmap_get_uint64(cmap_handle, key_name, &tstamp1);
			if (err != CS_OK) {
				qb_log (LOG_INFO, "Could not get \"last_updated\" key: %d.", err);
				return (2);
			}
			qb_log (LOG_INFO, "iid %d: Sleep 1", instance_id);
			sleep (1);
			err = sam_hc_send ();
			if (err != CS_OK) {
				qb_log (LOG_ERR, "Can't send hc. Error %d", err);
				return 2;
			}
			sleep (1);
			err = cmap_get_uint64(cmap_handle, key_name, &tstamp2);
			if (err != CS_OK) {
				qb_log (LOG_INFO, "Could not get \"last_updated\" key: %d.", err);
				return (2);
			}
			msec_diff = (tstamp2 - tstamp1)/CS_TIME_NS_IN_MSEC;

			if (msec_diff < 500 || msec_diff > 2000) {
				qb_log (LOG_INFO, "Difference %d is not within <500, 2000> interval.", msec_diff);
				return (2);
			}

			qb_log (LOG_INFO, "iid %d: stop 2", instance_id);
			err = sam_stop ();
			if (err != CS_OK) {
				qb_log (LOG_ERR, "Can't stop hc. Error %d", err);
				return 2;
			}

			snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
			err = cmap_get_string(cmap_handle, key_name, &str);
			if (err != CS_OK) {
				qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
				return (2);
			}

			if (strcmp(str, "stopped") != 0) {
				qb_log (LOG_INFO, "State key is not \"stopped\".");
				return (2);
			}
			free(str);

			qb_log (LOG_INFO, "iid %d: exiting", instance_id);
			return (0);
		}
	}

	if (test_n == 3) {
		qb_log (LOG_INFO, "Testing if status is failed");

		/*
		 * Previous should be FAILED
		 */

		snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "failed") != 0) {
			qb_log (LOG_INFO, "State key is not \"failed\".");
			return (2);
		}

		return (0);
	}

	return (2);
}
Exemplo n.º 9
0
/*
 * Test warn signal set.
 */
static int test6 (void) {
	cs_error_t error;
	unsigned int instance_id;
	int test6_sig_del;

	qb_log (LOG_INFO, " initialize");
	error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", error);
		return 1;
	}
	qb_log (LOG_INFO, " register");
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't register. Error %d", error);
		return 1;
	}

	if (instance_id == 1) {
		error = sam_warn_signal_set (SIGUSR1);
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't set warn signal. Error %d", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		qb_log (LOG_INFO, " iid %d: start", instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sleep 1", instance_id);
		sleep (1);

		qb_log (LOG_INFO, "iid %d: hc send", instance_id);
		error = sam_hc_send ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't send hc. Error %d", error);
			return 1;
		}


		qb_log (LOG_INFO, "iid %d: wait for delivery of signal", instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		qb_log (LOG_INFO, "iid %d: wait for real kill", instance_id);

		sleep (3);

		qb_log (LOG_INFO, "iid %d: wasn't killed", instance_id);
		return (1);
	}

	if (instance_id == 2) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't restore data. Error %d", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			qb_log (LOG_ERR, "Previous test failed. Signal was not delivered");
			return 1;
		}

		error = sam_warn_signal_set (SIGKILL);
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't set warn signal. Error %d", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		qb_log (LOG_INFO, "iid %d: start", instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sleep 1", instance_id);
		sleep (1);

		qb_log (LOG_INFO, "iid %d: hc send", instance_id);
		error = sam_hc_send ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't send hc. Error %d", error);
			return 1;
		}


		qb_log (LOG_INFO, "iid %d: wait for delivery of signal", instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		qb_log (LOG_INFO, "iid %d: wasn't killed", instance_id);
		return (1);
	}

	if (instance_id == 3) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't restore data. Error %d", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			qb_log (LOG_ERR, "Previous test failed. Signal WAS delivered");
			return 1;
		}

		return (0);
	}

	return 1;
}
Exemplo n.º 10
0
/*
 * Test sam_data_store, sam_data_restore and sam_data_getsize
 */
static int test4 (void)
{
	size_t size;
	cs_error_t err;
	int i;
	unsigned int instance_id;
	char saved_data[128];
	char saved_data2[128];

	qb_log (LOG_INFO, "sam_data_getsize 1");
	err = sam_data_getsize (&size);
	if (err != CS_ERR_BAD_HANDLE) {
		qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, "sam_data_getsize 2");
	err = sam_data_getsize (NULL);
	if (err != CS_ERR_INVALID_PARAM) {
		qb_log (LOG_ERR, "Test should return CS_ERR_INVALID_PARAM. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, "sam_data_store 1");
	err = sam_data_store (NULL, 0);
	if (err != CS_ERR_BAD_HANDLE) {
		qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, "sam_data_restore 1");
	err = sam_data_restore (saved_data, sizeof (saved_data));
	if (err != CS_ERR_BAD_HANDLE) {
		qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, "sam_initialize");
	err = sam_initialize (0, SAM_RECOVERY_POLICY_RESTART);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", err);
		return 1;
	}

	qb_log (LOG_INFO, "sam_data_getsize 3");
	err = sam_data_getsize (&size);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Test should return CS_ERR_BAD_HANDLE. Error returned %d", err);
		return 1;
	}
	if (size != 0) {
		qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size);
		return 1;
	}

	qb_log (LOG_INFO, "sam_data_restore 2");
	err = sam_data_restore (NULL, sizeof (saved_data));
	if (err != CS_ERR_INVALID_PARAM) {
		qb_log (LOG_ERR, "Test should return CS_ERR_INVALID_PARAM. Error returned %d", err);
		return 1;
	}

	/*
	 * Store some real data
	 */
	for (i = 0; i < sizeof (saved_data); i++) {
		saved_data[i] = (char)(i + 5);
	}

	qb_log (LOG_INFO, "sam_data_store 2");
	err = sam_data_store (saved_data, sizeof (saved_data));
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, " sam_data_getsize 4");
	err = sam_data_getsize (&size);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
		return 1;
	}
	if (size != sizeof (saved_data)) {
		qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size);
		return 1;
	}

	qb_log (LOG_INFO, " sam_data_restore 3");
	err = sam_data_restore (saved_data2, sizeof (saved_data2) - 1);
	if (err != CS_ERR_INVALID_PARAM) {
		qb_log (LOG_ERR, "Test should return CS_ERR_INVALID_PARAM. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, " sam_data_restore 4");
	err = sam_data_restore (saved_data2, sizeof (saved_data2));
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
		return 1;
	}

	if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) {
		qb_log (LOG_ERR, "Retored data are not same");
		return 1;
	}

	memset (saved_data2, 0, sizeof (saved_data2));

	qb_log (LOG_INFO, " sam_data_store 3");
	err = sam_data_store (NULL, 1);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, " sam_data_getsize 5");
	err = sam_data_getsize (&size);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
		return 1;
	}
	if (size != 0) {
		qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size);
		return 1;
	}

	qb_log (LOG_INFO, " sam_data_store 4");
	err = sam_data_store (saved_data, sizeof (saved_data));
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
		return 1;
	}

	qb_log (LOG_INFO, " register");
	err = sam_register (&instance_id);
	if (err != CS_OK) {
		qb_log (LOG_ERR, "Can't register. Error %d", err);
		return 1;
	}

	if (instance_id == 1) {
		qb_log (LOG_INFO, "iid %d: sam_start", instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", err);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sam_data_getsize 6", instance_id);
		err = sam_data_getsize (&size);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
			return 1;
		}
		if (size != sizeof (saved_data2)) {
			qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sam_data_restore 5", instance_id);
		err = sam_data_restore (saved_data2, sizeof (saved_data2));
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
			return 1;
		}

		if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) {
			qb_log (LOG_ERR, "Retored data are not same");
			return 1;
		}

		for (i = 0; i < sizeof (saved_data); i++) {
			saved_data[i] = (char)(i - 5);
		}

		qb_log (LOG_INFO, "iid %d: sam_data_store 5", instance_id);
		err = sam_data_store (saved_data, sizeof (saved_data) - 7);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
			return 1;
		}

		exit (1);
	}

	if (instance_id == 2) {
		qb_log (LOG_INFO, "iid %d: sam_start", instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", err);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sam_data_getsize 7", instance_id);
		err = sam_data_getsize (&size);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
			return 1;
		}
		if (size != sizeof (saved_data2) - 7) {
			qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sam_data_restore 6", instance_id);
		err = sam_data_restore (saved_data2, sizeof (saved_data2));
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
			return 1;
		}

		for (i = 0; i < sizeof (saved_data); i++) {
			saved_data[i] = (char)(i - 5);
		}

		if (memcmp (saved_data, saved_data2, sizeof (saved_data2) - 7) != 0) {
			qb_log (LOG_ERR, "Retored data are not same");
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sam_data_store 6", instance_id);
		err = sam_data_store (NULL, 0);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
			return 1;
		}

		exit (1);
	}

	if (instance_id == 3) {
		qb_log (LOG_INFO, "iid %d: sam_data_getsize 8", instance_id);
		err = sam_data_getsize (&size);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Test should return CS_OK. Error returned %d", err);
			return 1;
		}
		if (size != 0) {
			qb_log (LOG_ERR, "Test should return size of 0. Returned %zx", size);
			return 1;
		}
	}

	return (0);
}
Exemplo n.º 11
0
/*
 * Test warn signal set.
 */
static int
sam_test6 (void) {
	cs_error_t error;
	unsigned int instance_id;
	int test6_sig_del;

	setlinebuf(stdout);
	printf ("%s: initialize\n", __FUNCTION__);
	error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		fprintf (stderr, "Can't initialize SAM API. Error %d\n", error);
		return 1;
	}
	printf ("%s: register\n", __FUNCTION__);
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		fprintf (stderr, "Can't register. Error %d\n", error);
		return 1;
	}

	if (instance_id == 1) {
		error = sam_warn_signal_set (SIGUSR1);
		if (error != CS_OK) {
			fprintf (stderr, "Can't set warn signal. Error %d\n", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}

		printf ("%s iid %d: sleep 1\n", __FUNCTION__, instance_id);
		sleep (1);

		printf ("%s iid %d: hc send\n", __FUNCTION__, instance_id);
		error = sam_hc_send ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't send hc. Error %d\n", error);
			return 1;
		}


		printf ("%s iid %d: wait for delivery of signal\n", __FUNCTION__, instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		printf ("%s iid %d: wait for real kill\n", __FUNCTION__, instance_id);

		sleep (3);

		printf ("%s iid %d: wasn't killed\n", __FUNCTION__, instance_id);
		return (1);
	}

	if (instance_id == 2) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			fprintf (stderr, "Can't restore data. Error %d\n", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			fprintf (stderr, "Previous test failed. Signal was not delivered\n");
			return 1;
		}

		error = sam_warn_signal_set (SIGKILL);
		if (error != CS_OK) {
			fprintf (stderr, "Can't set warn signal. Error %d\n", error);
			return 1;
		}

		signal (SIGUSR1, test6_signal);

		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}

		printf ("%s iid %d: sleep 1\n", __FUNCTION__, instance_id);
		sleep (1);

		printf ("%s iid %d: hc send\n", __FUNCTION__, instance_id);
		error = sam_hc_send ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't send hc. Error %d\n", error);
			return 1;
		}


		printf ("%s iid %d: wait for delivery of signal\n", __FUNCTION__, instance_id);
		while (!test6_sig_delivered) {
			sleep (1);
		}

		printf ("%s iid %d: wasn't killed\n", __FUNCTION__, instance_id);
		return (1);
	}

	if (instance_id == 3) {
		error = sam_data_restore (&test6_sig_del, sizeof (test6_sig_del));
		if (error != CS_OK) {
			fprintf (stderr, "Can't restore data. Error %d\n", error);
			return 1;
		}

		if (test6_sig_del != 1) {
			fprintf (stderr, "Previous test failed. Signal WAS delivered\n");
			return 1;
		}

		return (0);
	}

	return 1;
}
Exemplo n.º 12
0
/*
 * Test sam_data_store, sam_data_restore and sam_data_getsize
 */
static int
sam_test4 (void)
{
	size_t size;
	cs_error_t err;
	int i;
	unsigned int instance_id;
	char saved_data[128];
	char saved_data2[128];

	setlinebuf(stdout);
	printf ("%s: sam_data_getsize 1\n", __FUNCTION__);
	err = sam_data_getsize (&size);
	if (err != CS_ERR_BAD_HANDLE) {
		fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: sam_data_getsize 2\n", __FUNCTION__);
	err = sam_data_getsize (NULL);
	if (err != CS_ERR_INVALID_PARAM) {
		fprintf (stderr, "Test should return CS_ERR_INVALID_PARAM. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: sam_data_store 1\n", __FUNCTION__);
	err = sam_data_store (NULL, 0);
	if (err != CS_ERR_BAD_HANDLE) {
		fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: sam_data_restore 1\n", __FUNCTION__);
	err = sam_data_restore (saved_data, sizeof (saved_data));
	if (err != CS_ERR_BAD_HANDLE) {
		fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: sam_initialize\n", __FUNCTION__);
	err = sam_initialize (0, SAM_RECOVERY_POLICY_RESTART);
	if (err != CS_OK) {
		fprintf (stderr, "Can't initialize SAM API. Error %d\n", err);
		return 1;
	}

	printf ("%s: sam_data_getsize 3\n", __FUNCTION__);
	err = sam_data_getsize (&size);
	if (err != CS_OK) {
		fprintf (stderr, "Test should return CS_ERR_BAD_HANDLE. Error returned %d\n", err);
		return 1;
	}
	if (size != 0) {
		fprintf (stderr, "Test should return size of 0. Returned %zx\n", size);
		return 1;
	}

	printf ("%s: sam_data_restore 2\n", __FUNCTION__);
	err = sam_data_restore (NULL, sizeof (saved_data));
	if (err != CS_ERR_INVALID_PARAM) {
		fprintf (stderr, "Test should return CS_ERR_INVALID_PARAM. Error returned %d\n", err);
		return 1;
	}

	/*
	 * Store some real data
	 */
	for (i = 0; i < sizeof (saved_data); i++) {
		saved_data[i] = (char)(i + 5);
	}

	printf ("%s: sam_data_store 2\n", __FUNCTION__);
	err = sam_data_store (saved_data, sizeof (saved_data));
	if (err != CS_OK) {
		fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: sam_data_getsize 4\n", __FUNCTION__);
	err = sam_data_getsize (&size);
	if (err != CS_OK) {
		fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
		return 1;
	}
	if (size != sizeof (saved_data)) {
		fprintf (stderr, "Test should return size of 0. Returned %zx\n", size);
		return 1;
	}

	printf ("%s: sam_data_restore 3\n", __FUNCTION__);
	err = sam_data_restore (saved_data2, sizeof (saved_data2) - 1);
	if (err != CS_ERR_INVALID_PARAM) {
		fprintf (stderr, "Test should return CS_ERR_INVALID_PARAM. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: sam_data_restore 4\n", __FUNCTION__);
	err = sam_data_restore (saved_data2, sizeof (saved_data2));
	if (err != CS_OK) {
		fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
		return 1;
	}

	if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) {
		fprintf (stderr, "Retored data are not same\n");
		return 1;
	}

	memset (saved_data2, 0, sizeof (saved_data2));

	printf ("%s: sam_data_store 3\n", __FUNCTION__);
	err = sam_data_store (NULL, 1);
	if (err != CS_OK) {
		fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: sam_data_getsize 5\n", __FUNCTION__);
	err = sam_data_getsize (&size);
	if (err != CS_OK) {
		fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
		return 1;
	}
	if (size != 0) {
		fprintf (stderr, "Test should return size of 0. Returned %zx\n", size);
		return 1;
	}

	printf ("%s: sam_data_store 4\n", __FUNCTION__);
	err = sam_data_store (saved_data, sizeof (saved_data));
	if (err != CS_OK) {
		fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
		return 1;
	}

	printf ("%s: register\n", __FUNCTION__);
	err = sam_register (&instance_id);
	if (err != CS_OK) {
		fprintf (stderr, "Can't register. Error %d\n", err);
		return 1;
	}

	if (instance_id == 1) {
		printf ("%s iid %d: sam_start\n", __FUNCTION__, instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", err);
			return 1;
		}

		printf ("%s iid %d: sam_data_getsize 6\n", __FUNCTION__, instance_id);
		err = sam_data_getsize (&size);
		if (err != CS_OK) {
			fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
			return 1;
		}
		if (size != sizeof (saved_data2)) {
			fprintf (stderr, "Test should return size of 0. Returned %zx\n", size);
			return 1;
		}

		printf ("%s iid %d: sam_data_restore 5\n", __FUNCTION__, instance_id);
		err = sam_data_restore (saved_data2, sizeof (saved_data2));
		if (err != CS_OK) {
			fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
			return 1;
		}

		if (memcmp (saved_data, saved_data2, sizeof (saved_data2)) != 0) {
			fprintf (stderr, "Retored data are not same\n");
			return 1;
		}

		for (i = 0; i < sizeof (saved_data); i++) {
			saved_data[i] = (char)(i - 5);
		}

		printf ("%s iid %d: sam_data_store 5\n", __FUNCTION__, instance_id);
		err = sam_data_store (saved_data, sizeof (saved_data) - 7);
		if (err != CS_OK) {
			fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
			return 1;
		}

		exit (1);
	}

	if (instance_id == 2) {
		printf ("%s iid %d: sam_start\n", __FUNCTION__, instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", err);
			return 1;
		}

		printf ("%s iid %d: sam_data_getsize 7\n", __FUNCTION__, instance_id);
		err = sam_data_getsize (&size);
		if (err != CS_OK) {
			fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
			return 1;
		}
		if (size != sizeof (saved_data2) - 7) {
			fprintf (stderr, "Test should return size of 0. Returned %zx\n", size);
			return 1;
		}

		printf ("%s iid %d: sam_data_restore 6\n", __FUNCTION__, instance_id);
		err = sam_data_restore (saved_data2, sizeof (saved_data2));
		if (err != CS_OK) {
			fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
			return 1;
		}

		for (i = 0; i < sizeof (saved_data); i++) {
			saved_data[i] = (char)(i - 5);
		}

		if (memcmp (saved_data, saved_data2, sizeof (saved_data2) - 7) != 0) {
			fprintf (stderr, "Retored data are not same\n");
			return 1;
		}

		printf ("%s iid %d: sam_data_store 6\n", __FUNCTION__, instance_id);
		err = sam_data_store (NULL, 0);
		if (err != CS_OK) {
			fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
			return 1;
		}

		exit (1);
	}

	if (instance_id == 3) {
		printf ("%s iid %d: sam_data_getsize 8\n", __FUNCTION__, instance_id);
		err = sam_data_getsize (&size);
		if (err != CS_OK) {
			fprintf (stderr, "Test should return CS_OK. Error returned %d\n", err);
			return 1;
		}
		if (size != 0) {
			fprintf (stderr, "Test should return size of 0. Returned %zx\n", size);
			return 1;
		}
	}

	return (0);
}
Exemplo n.º 13
0
/*
 * Test confdb integration + quit policy
 */
static int test8 (pid_t pid, pid_t old_pid, int test_n) {
	confdb_handle_t cdb_handle;
	cs_error_t err;
	hdb_handle_t res_handle, proc_handle, pid_handle;
	size_t value_len;
	uint64_t tstamp1, tstamp2;
	int32_t msec_diff;
	char key_value[256];
	unsigned int instance_id;
	char tmp_obj[PATH_MAX];
	confdb_value_types_t cdbtype;

	err = confdb_initialize (&cdb_handle, NULL);
	if (err != CS_OK) {
		printf ("Could not initialize Cluster Configuration Database API instance error %d. Test skipped\n", err);
		return (1);
	}

	printf ("%s test %d\n", __FUNCTION__, test_n);

	if (test_n == 2) {
		/*
		 * Object should not exist
		 */
		printf ("%s Testing if object exists (it shouldn't)\n", __FUNCTION__);

		err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"), &res_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"resources\": %d.\n", err);
			return (2);
		}

		err = confdb_object_find_start(cdb_handle, res_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"process\": %d.\n", err);
			return (2);
		}

		if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) {
			snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid);
		}

		err = confdb_object_find_start(cdb_handle, proc_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle);
		if (err == CS_OK) {
			printf ("Could find object \"%s\": %d.\n", tmp_obj, err);
			return (2);
		}
	}

	if (test_n == 1 || test_n == 2) {
		printf ("%s: initialize\n", __FUNCTION__);
		err = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT | SAM_RECOVERY_POLICY_CONFDB);
		if (err != CS_OK) {
			fprintf (stderr, "Can't initialize SAM API. Error %d\n", err);
			return 2;
		}

		printf ("%s: register\n", __FUNCTION__);
		err = sam_register (&instance_id);
		if (err != CS_OK) {
			fprintf (stderr, "Can't register. Error %d\n", err);
			return 2;
		}

		err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"), &res_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"resources\": %d.\n", err);
			return (2);
		}

		err = confdb_object_find_start(cdb_handle, res_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"process\": %d.\n", err);
			return (2);
		}

		if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) {
			snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid);
		}

		err = confdb_object_find_start(cdb_handle, proc_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"%s\": %d.\n", tmp_obj, err);
			return (2);
		}

		err = confdb_key_get(cdb_handle, pid_handle, "recovery", strlen("recovery"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"recovery\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("quit") || memcmp (key_value, "quit", value_len) != 0) {
			printf ("Recovery key \"%s\" is not \"watchdog\".\n", key_value);
			return (2);
		}

		err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"state\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) {
			printf ("State key is not \"stopped\".\n");
			return (2);
		}

		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", err);
			return 2;
		}

		err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"state\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("running") || memcmp (key_value, "running", value_len) != 0) {
			printf ("State key is not \"running\".\n");
			return (2);
		}

		printf ("%s iid %d: stop\n", __FUNCTION__, instance_id);
		err = sam_stop ();
		if (err != CS_OK) {
			fprintf (stderr, "Can't stop hc. Error %d\n", err);
			return 2;
		}

		err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"state\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) {
			printf ("State key is not \"stopped\".\n");
			return (2);
		}

		printf ("%s iid %d: sleeping 5\n", __FUNCTION__, instance_id);
		sleep (5);

		err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"state\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) {
			printf ("State key is not \"stopped\".\n");
			return (2);
		}

		printf ("%s iid %d: start 2\n", __FUNCTION__, instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", err);
			return 2;
		}

		err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"state\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("running") || memcmp (key_value, "running", value_len) != 0) {
			printf ("State key is not \"running\".\n");
			return (2);
		}

		if (test_n == 2) {
			printf ("%s iid %d: sleeping 5. Should be killed\n", __FUNCTION__, instance_id);
			sleep (5);

			return (2);
		} else {
			printf ("%s iid %d: Test HC\n", __FUNCTION__, instance_id);
			err = sam_hc_send ();
			if (err != CS_OK) {
				fprintf (stderr, "Can't send hc. Error %d\n", err);
				return 2;
			}
			err = confdb_key_get_typed (cdb_handle, pid_handle, "last_updated", &tstamp1, &value_len, &cdbtype);
			if (err != CS_OK) {
				printf ("Could not get \"state\" key: %d.\n", err);
				return (2);
			}
			printf ("%s iid %d: Sleep 1\n", __FUNCTION__, instance_id);
			sleep (1);
			err = sam_hc_send ();
			if (err != CS_OK) {
				fprintf (stderr, "Can't send hc. Error %d\n", err);
				return 2;
			}
			sleep (1);
			err = confdb_key_get_typed (cdb_handle, pid_handle, "last_updated", &tstamp2, &value_len, &cdbtype);
			if (err != CS_OK) {
				printf ("Could not get \"state\" key: %d.\n", err);
				return (2);
			}
			msec_diff = (tstamp2 - tstamp1)/CS_TIME_NS_IN_MSEC;

			if (msec_diff < 500 || msec_diff > 2000) {
				printf ("Difference %d is not within <500, 2000> interval.\n", msec_diff);
				return (2);
			}

			printf ("%s iid %d: stop 2\n", __FUNCTION__, instance_id);
			err = sam_stop ();
			if (err != CS_OK) {
				fprintf (stderr, "Can't stop hc. Error %d\n", err);
				return 2;
			}

			err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
			if (err != CS_OK) {
				printf ("Could not get \"state\" key: %d.\n", err);
				return (2);
			}

			if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) {
				printf ("State key is not \"stopped\".\n");
				return (2);
			}

			printf ("%s iid %d: exiting\n", __FUNCTION__, instance_id);
			return (0);
		}
	}

	if (test_n == 3) {
		printf ("%s Testing if status is failed\n", __FUNCTION__);

		/*
		 * Previous should be FAILED
		 */
		err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"), &res_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"resources\": %d.\n", err);
			return (2);
		}

		err = confdb_object_find_start(cdb_handle, res_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"process\": %d.\n", err);
			return (2);
		}

		if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) {
			snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid);
		}

		err = confdb_object_find_start(cdb_handle, proc_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"%s\": %d.\n", tmp_obj, err);
			return (2);
		}

		err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"state\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("failed") || memcmp (key_value, "failed", value_len) != 0) {
			printf ("State key is not \"failed\".\n");
			return (2);
		}

		return (0);
	}

	return (2);
}
Exemplo n.º 14
0
/*
 * Test quorum
 */
static int test7 (void) {
	confdb_handle_t cdb_handle;
	cs_error_t err;
	hdb_handle_t quorum_handle;
	size_t value_len;
	char key_value[256];
	unsigned int instance_id;
	pthread_t kill_thread;

	err = confdb_initialize (&cdb_handle, NULL);
	if (err != CS_OK) {
		printf ("Could not initialize Cluster Configuration Database API instance error %d. Test skipped\n", err);
		return (1);
	}

	err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE);
	if (err != CS_OK) {
		printf ("Could not start object_find %d. Test skipped\n", err);
		return (1);
        }

	err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "quorum", strlen("quorum"), &quorum_handle);
	if (err != CS_OK) {
		printf ("Could not object_find \"quorum\": %d. Test skipped\n", err);
		return (1);
	}

	err = confdb_key_get(cdb_handle, quorum_handle, "provider", strlen("provider"), key_value, &value_len);
	if (err != CS_OK) {
		printf ("Could not get \"provider\" key: %d. Test skipped\n", err);
		return (1);
	}

        if (!(value_len - 1 == strlen ("testquorum") && memcmp (key_value, "testquorum", value_len - 1) == 0)) {
		printf ("Provider is not testquorum. Test skipped\n");
		return (1);
        }

	/*
	 * Set to not quorate
	 */
	err = confdb_key_create(cdb_handle, quorum_handle, "quorate", strlen("quorate"), "0", strlen("0"));
	if (err != CS_OK) {
		printf ("Can't create confdb key. Error %d\n", err);
		return (2);
	}

	printf ("%s: initialize\n", __FUNCTION__);
	err = sam_initialize (2000, SAM_RECOVERY_POLICY_QUORUM_RESTART);
	if (err != CS_OK) {
		fprintf (stderr, "Can't initialize SAM API. Error %d\n", err);
		return 2;
	}

	printf ("%s: register\n", __FUNCTION__);
	err = sam_register (&instance_id);
	if (err != CS_OK) {
		fprintf (stderr, "Can't register. Error %d\n", err);
		return 2;
	}

	if (instance_id == 1) {
		/*
		 * Sam start should block forever, but 10s for us should be enough
		 */
		pthread_create (&kill_thread, NULL, test7_thread, NULL);

		printf ("%s iid %d: start - should block forever (waiting 5s)\n", __FUNCTION__, instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", err);
			return 2;
		}

		printf ("%s iid %d: wasn't killed\n", __FUNCTION__, instance_id);
		return (2);
	}

	if (instance_id == 2) {
		/*
		 * Set to quorate
		 */
		err = confdb_key_create(cdb_handle, quorum_handle, "quorate", strlen("quorate"), "1", strlen("1"));
		if (err != CS_OK) {
			printf ("Can't create confdb key. Error %d\n", err);
			return (2);
		}

		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		err = sam_start ();
		if (err != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", err);
			return 2;
		}

		/*
		 * Set corosync unquorate
		 */
		err = confdb_key_create(cdb_handle, quorum_handle, "quorate", strlen("quorate"), "0", strlen("0"));
		if (err != CS_OK) {
			printf ("Can't create confdb key. Error %d\n", err);
			return (2);
		}

		printf ("%s iid %d: sleep 3\n", __FUNCTION__, instance_id);
		sleep (3);

		printf ("%s iid %d: wasn't killed\n", __FUNCTION__, instance_id);
		return (2);
	}

	if (instance_id == 3) {
		return (0);
	}

	return (2);
}
Exemplo n.º 15
0
/*
 * First test will just register SAM, with policy restart. First instance will
 * sleep one second, send hc and sleep another 3 seconds. This should force restart.
 * Second instance will sleep one second, send hc, stop hc and sleep 3 seconds.
 * Then start hc again and sleep 3 seconds. This should force restart again.
 * Last instance just calls initialize again. This should end with error.
 * Then call start, followed by stop and start again. Finally, we will call finalize
 * twice. One should succeed, second should fail. After this, we will call every function
 * (none should succeed).
 */
static int test1 (void)
{
	cs_error_t error;
	unsigned int instance_id;
	int i;

	printf ("%s: initialize\n", __FUNCTION__);
	error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		fprintf (stderr, "Can't initialize SAM API. Error %d\n", error);
		return 1;
	}
	printf ("%s: register\n", __FUNCTION__);
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		fprintf (stderr, "Can't register. Error %d\n", error);
		return 1;
	}

	if (instance_id == 1 || instance_id == 2) {
		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}

		for (i = 0; i < 10; i++) {
			printf ("%s iid %d: sleep 1\n", __FUNCTION__, instance_id);
			sleep (1);

			printf ("%s iid %d: hc send\n", __FUNCTION__, instance_id);
			error = sam_hc_send ();
			if (error != CS_OK) {
				fprintf (stderr, "Can't send hc. Error %d\n", error);
				return 1;
			}
		}

		if (instance_id == 2) {
			printf ("%s iid %d: stop\n", __FUNCTION__, instance_id);
			error = sam_stop ();

			if (error != CS_OK) {
				fprintf (stderr, "Can't send hc. Error %d\n", error);
				return 1;
			}
		}

		printf ("%s iid %d: sleep 3\n", __FUNCTION__, instance_id);
		sleep (3);

		printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}

		printf ("%s iid %d: sleep 3\n", __FUNCTION__, instance_id);
		sleep (3);
		return 0;
	}

	if (instance_id == 3) {
		error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
		if (error == CS_OK) {
			fprintf (stderr, "Can initialize SAM API after initialization");
			return 1;
		}

		error = sam_start ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't start hc. Error %d\n", error);
			return 1;
		}
		error = sam_stop ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't stop hc. Error %d\n", error);
			return 1;
		}
		error = sam_finalize ();
		if (error != CS_OK) {
			fprintf (stderr, "Can't finalize sam. Error %d\n", error);
			return 1;
		}
		error = sam_finalize ();
		if (error == CS_OK) {
			fprintf (stderr, "Can finalize sam after finalization!\n");
			return 1;
		}

		if (sam_initialize (2, SAM_RECOVERY_POLICY_RESTART) == CS_OK ||
			sam_start () == CS_OK || sam_stop () == CS_OK ||
			sam_register (NULL) == CS_OK || sam_hc_send () == CS_OK ||
			sam_hc_callback_register (NULL) == CS_OK) {

			fprintf (stderr, "Can call one of function after finalization!\n");

			return 1;
		}

		return 0;
	}

	return 1;
}
Exemplo n.º 16
0
/*
 * First test will just register SAM, with policy restart. First instance will
 * sleep one second, send hc and sleep another 3 seconds. This should force restart.
 * Second instance will sleep one second, send hc, stop hc and sleep 3 seconds.
 * Then start hc again and sleep 3 seconds. This should force restart again.
 * Last instance just calls initialize again. This should end with error.
 * Then call start, followed by stop and start again. Finally, we will call finalize
 * twice. One should succeed, second should fail. After this, we will call every function
 * (none should succeed).
 */
static int test1 (void)
{
	cs_error_t error;
	unsigned int instance_id;
	int i;

	qb_enter();
	error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", error);
		return 1;
	}
	qb_log (LOG_INFO, "register");
	error = sam_register (&instance_id);
	if (error != CS_OK) {
		qb_log (LOG_ERR, "Can't register. Error %d", error);
		return 1;
	}

	if (instance_id == 1 || instance_id == 2) {
		qb_log (LOG_INFO, "iid %d: start", instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}

		for (i = 0; i < 10; i++) {
			qb_log (LOG_INFO, "iid %d: sleep 1", instance_id);
			sleep (1);

			qb_log (LOG_INFO, "iid %d: hc send", instance_id);
			error = sam_hc_send ();
			if (error != CS_OK) {
				qb_log (LOG_ERR, "Can't send hc. Error %d", error);
				return 1;
			}
		}

		if (instance_id == 2) {
			qb_log (LOG_INFO, "iid %d: stop", instance_id);
			error = sam_stop ();

			if (error != CS_OK) {
				qb_log (LOG_ERR, "Can't send hc. Error %d", error);
				return 1;
			}
		}

		qb_log (LOG_INFO, "iid %d: sleep 3", instance_id);
		sleep (3);

		qb_log (LOG_INFO, "iid %d: start", instance_id);
		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}

		qb_log (LOG_INFO, "iid %d: sleep 3", instance_id);
		sleep (3);
		return 0;
	}

	if (instance_id == 3) {
		error = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART);
		if (error == CS_OK) {
			qb_log (LOG_ERR, "Can initialize SAM API after initialization");
			return 1;
		}

		error = sam_start ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't start hc. Error %d", error);
			return 1;
		}
		error = sam_stop ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't stop hc. Error %d", error);
			return 1;
		}
		error = sam_finalize ();
		if (error != CS_OK) {
			qb_log (LOG_ERR, "Can't finalize sam. Error %d", error);
			return 1;
		}
		error = sam_finalize ();
		if (error == CS_OK) {
			qb_log (LOG_ERR, "Can finalize sam after finalization!");
			return 1;
		}

		if (sam_initialize (2, SAM_RECOVERY_POLICY_RESTART) == CS_OK ||
			sam_start () == CS_OK || sam_stop () == CS_OK ||
			sam_register (NULL) == CS_OK || sam_hc_send () == CS_OK ||
			sam_hc_callback_register (NULL) == CS_OK) {

			qb_log (LOG_ERR, "Can call one of function after finalization!");

			return 1;
		}

		return 0;
	}

	return 1;
}
Exemplo n.º 17
0
/*
 * Test cmap integration + restart policy
 */
static int test9 (pid_t pid, pid_t old_pid, int test_n) {
	cs_error_t err;
	cmap_handle_t cmap_handle;
	unsigned int instance_id;
	char *str;
	char key_name[CMAP_KEYNAME_MAXLEN];

	err = cmap_initialize (&cmap_handle);
	if (err != CS_OK) {
		qb_log (LOG_INFO, "Could not initialize Cluster Map API instance error %d. Test skipped", err);
		return (1);
	}

	qb_log (LOG_INFO, "test %d", test_n);

	if (test_n == 1) {
		qb_log (LOG_INFO, " initialize");
		err = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART | SAM_RECOVERY_POLICY_CMAP);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", err);
			return 2;
		}

		qb_log (LOG_INFO, " register");
		err = sam_register (&instance_id);
		if (err != CS_OK) {
			qb_log (LOG_ERR, "Can't register. Error %d", err);
			return 2;
		}
		qb_log (LOG_INFO, " iid %d", instance_id);

		if (instance_id < 3) {
			snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.recovery", pid);
			err = cmap_get_string(cmap_handle, key_name, &str);
			if (err != CS_OK) {
				qb_log (LOG_INFO, "Could not get \"recovery\" key: %d.", err);
				return (2);
			}

			if (strcmp(str, "restart") != 0) {
				qb_log (LOG_INFO, "Recovery key \"%s\" is not \"restart\".", str);
				return (2);
			}
			free(str);

			snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
			err = cmap_get_string(cmap_handle, key_name, &str);
			if (err != CS_OK) {
				qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
				return (2);
			}

			if (strcmp(str, "stopped") != 0) {
				qb_log (LOG_INFO, "State key is not \"stopped\".");
				return (2);
			}
			free(str);

			qb_log (LOG_INFO, "iid %d: start", instance_id);
			err = sam_start ();
			if (err != CS_OK) {
				qb_log (LOG_ERR, "Can't start hc. Error %d", err);
				return 2;
			}

			err = cmap_get_string(cmap_handle, key_name, &str);
			if (err != CS_OK) {
				qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
				return (2);
			}

			if (strcmp(str, "running") != 0) {
				qb_log (LOG_INFO, "State key is not \"running\".");
				return (2);
			}
			free(str);

			qb_log (LOG_INFO, "iid %d: waiting for kill", instance_id);
			sleep (10);

			return (2);
		}

		if (instance_id == 3) {
			qb_log (LOG_INFO, "iid %d: mark failed", instance_id);
			err = sam_mark_failed ();
			if (err != CS_OK) {
				qb_log (LOG_ERR, "Can't mark failed. Error %d", err);
				return 2;
			}

			sleep (10);

			return (2);
		}

		return (2);
	}

	if (test_n == 2) {
		qb_log (LOG_INFO, "Testing if status is failed");

		/*
		 * Previous should be FAILED
		 */
		snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
		err = cmap_get_string(cmap_handle, key_name, &str);
		if (err != CS_OK) {
			qb_log (LOG_INFO, "Could not get \"state\" key: %d.", err);
			return (2);
		}

		if (strcmp(str, "failed") != 0) {
			qb_log (LOG_INFO, "State key is not \"failed\".");
			return (2);
		}
		free(str);

		return (0);
	}

	return (2);
}
Exemplo n.º 18
0
/*
 * Test confdb integration + restart policy
 */
static int test9 (pid_t pid, pid_t old_pid, int test_n) {
	confdb_handle_t cdb_handle;
	cs_error_t err;
	hdb_handle_t res_handle, proc_handle, pid_handle;
	size_t value_len;
	char key_value[256];
	unsigned int instance_id;
	char tmp_obj[PATH_MAX];

	err = confdb_initialize (&cdb_handle, NULL);
	if (err != CS_OK) {
		printf ("Could not initialize Cluster Configuration Database API instance error %d. Test skipped\n", err);
		return (1);
	}

	printf ("%s test %d\n", __FUNCTION__, test_n);

	if (test_n == 1) {
		printf ("%s: initialize\n", __FUNCTION__);
		err = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART | SAM_RECOVERY_POLICY_CONFDB);
		if (err != CS_OK) {
			fprintf (stderr, "Can't initialize SAM API. Error %d\n", err);
			return 2;
		}

		printf ("%s: register\n", __FUNCTION__);
		err = sam_register (&instance_id);
		if (err != CS_OK) {
			fprintf (stderr, "Can't register. Error %d\n", err);
			return 2;
		}
		printf ("%s: iid %d\n", __FUNCTION__, instance_id);

		if (instance_id < 3) {
			err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE);
			if (err != CS_OK) {
				printf ("Could not start object_find %d.\n", err);
				return (2);
			}

			err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"),
			    &res_handle);
			if (err != CS_OK) {
				printf ("Could not object_find \"resources\": %d.\n", err);
				return (2);
			}

			err = confdb_object_find_start(cdb_handle, res_handle);
			if (err != CS_OK) {
				printf ("Could not start object_find %d.\n", err);
				return (2);
			}

			err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle);
			if (err != CS_OK) {
				printf ("Could not object_find \"process\": %d.\n", err);
				return (2);
			}

			if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) {
				snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid);
			}

			err = confdb_object_find_start(cdb_handle, proc_handle);
			if (err != CS_OK) {
				printf ("Could not start object_find %d.\n", err);
				return (2);
			}

			err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle);
			if (err != CS_OK) {
				printf ("Could not object_find \"%s\": %d.\n", tmp_obj, err);
				return (2);
			}

			err = confdb_key_get(cdb_handle, pid_handle, "recovery", strlen("recovery"), key_value, &value_len);
			if (err != CS_OK) {
				printf ("Could not get \"recovery\" key: %d.\n", err);
				return (2);
			}

			if (value_len != strlen ("restart") || memcmp (key_value, "restart", value_len) != 0) {
				printf ("Recovery key \"%s\" is not \"restart\".\n", key_value);
				return (2);
			}

			err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
			if (err != CS_OK) {
				printf ("Could not get \"state\" key: %d.\n", err);
				return (2);
			}

			if (value_len != strlen ("stopped") || memcmp (key_value, "stopped", value_len) != 0) {
				printf ("State key is not \"stopped\".\n");
				return (2);
			}

			printf ("%s iid %d: start\n", __FUNCTION__, instance_id);
			err = sam_start ();
			if (err != CS_OK) {
				fprintf (stderr, "Can't start hc. Error %d\n", err);
				return 2;
			}

			err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
			if (err != CS_OK) {
				printf ("Could not get \"state\" key: %d.\n", err);
				return (2);
			}

			if (value_len != strlen ("running") || memcmp (key_value, "running", value_len) != 0) {
				printf ("State key is not \"running\".\n");
				return (2);
			}

			printf ("%s iid %d: waiting for kill\n", __FUNCTION__, instance_id);
			sleep (10);

			return (2);
		}

		if (instance_id == 3) {
			printf ("%s iid %d: mark failed\n", __FUNCTION__, instance_id);
			if (err != CS_OK) {
				fprintf (stderr, "Can't start hc. Error %d\n", err);
				return 2;
			}
			err = sam_mark_failed ();
			if (err != CS_OK) {
				fprintf (stderr, "Can't mark failed. Error %d\n", err);
				return 2;
			}

			sleep (10);

			return (2);
		}

		return (2);
	}

	if (test_n == 2) {
		printf ("%s Testing if status is failed\n", __FUNCTION__);

		/*
		 * Previous should be FAILED
		 */
		err = confdb_object_find_start(cdb_handle, OBJECT_PARENT_HANDLE);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, OBJECT_PARENT_HANDLE, "resources", strlen("resources"), &res_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"resources\": %d.\n", err);
			return (2);
		}

		err = confdb_object_find_start(cdb_handle, res_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, res_handle, "process", strlen("process"), &proc_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"process\": %d.\n", err);
			return (2);
		}

		if (snprintf (tmp_obj, sizeof (tmp_obj), "%s:%d", __progname, pid) >= sizeof (tmp_obj)) {
			snprintf (tmp_obj, sizeof (tmp_obj), "%d", pid);
		}

		err = confdb_object_find_start(cdb_handle, proc_handle);
		if (err != CS_OK) {
			printf ("Could not start object_find %d.\n", err);
			return (2);
		}

		err = confdb_object_find(cdb_handle, proc_handle, tmp_obj, strlen(tmp_obj), &pid_handle);
		if (err != CS_OK) {
			printf ("Could not object_find \"%s\": %d.\n", tmp_obj, err);
			return (2);
		}

		err = confdb_key_get(cdb_handle, pid_handle, "state", strlen("state"), key_value, &value_len);
		if (err != CS_OK) {
			printf ("Could not get \"state\" key: %d.\n", err);
			return (2);
		}

		if (value_len != strlen ("failed") || memcmp (key_value, "failed", value_len) != 0) {
			printf ("State key is not \"failed\".\n");
			return (2);
		}

		return (0);
	}

	return (2);
}