Example #1
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);
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}
Example #5
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;
}