#include "logtest.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <limits.h>
#include <unistd.h>
#include <stdarg.h>


static char host_name[_POSIX_HOST_NAME_MAX] = {0};
static const char *hostname(void)
{
	gethostname(host_name, _POSIX_HOST_NAME_MAX);
	return host_name;
}

static bool is_test_done_on_pl(void)
{
	return (strncmp(hostname(), "PL-", strlen("PL-")) == 0);
}

static void cond_check(void)
{
	if (is_test_done_on_pl() == false) {
		fprintf(stderr, "Test must be done on payload node \n");
		exit(EXIT_FAILURE);
	}
}

static int lockNode(void)
{
	int rc;
	char command[256];
	sprintf(command, "amf-adm lock safNode=%s,safCluster=myClmCluster", hostname());
	rc = system(command);
	return WEXITSTATUS(rc);
}

static int unlockNode(void)
{
	int rc;
	char command[256];
	sprintf(command, "amf-adm unlock safNode=%s,safCluster=myClmCluster", hostname());
	rc = system(command);
	return WEXITSTATUS(rc);
}

void saLogInitializ_14_01_1(void)
{
	cond_check();
	lockNode();

	rc = saLogInitialize(&logHandle, &logCallbacks, &logVersion);
	saLogFinalize(logHandle);
	test_validate(rc, SA_AIS_ERR_UNAVAILABLE);

	unlockNode();
}

void add_suite_14(void)
{
	test_suite_add(14, "Log Service CLM Operations");
	test_case_add(14, saLogInitializ_14_01_1, "saLogInitializ() Expected SA_AIS_ERR_UNAVAILABLE");
}
