static char *ais_clm_show_members(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i; SaClmClusterNotificationBufferT buf; SaClmClusterNotificationT notif[64]; SaAisErrorT ais_res; switch (cmd) { case CLI_INIT: e->command = "ais show clm members"; e->usage = "Usage: ais show clm members\n" " List members of the cluster using the CLM (Cluster Membership) service.\n"; return NULL; case CLI_GENERATE: return NULL; /* no completion */ } if (a->argc != e->args) return CLI_SHOWUSAGE; buf.notification = notif; buf.numberOfItems = ARRAY_LEN(notif); ais_res = saClmClusterTrack(clm_handle, SA_TRACK_CURRENT, &buf); if (ais_res != SA_AIS_OK) { ast_cli(a->fd, "Error retrieving current cluster members.\n"); return CLI_FAILURE; } ast_cli(a->fd, "\n" "=============================================================\n" "=== Cluster Members =========================================\n" "=============================================================\n" "===\n"); for (i = 0; i < buf.numberOfItems; i++) { SaClmClusterNodeT *node = &buf.notification[i].clusterNode; ast_cli(a->fd, "=== ---------------------------------------------------------\n" "=== Node Name: %s\n" "=== ==> ID: 0x%x\n" "=== ==> Address: %s\n" "=== ==> Member: %s\n", (char *) node->nodeName.value, (int) node->nodeId, (char *) node->nodeAddress.value, node->member ? "Yes" : "No"); ast_cli(a->fd, "=== ---------------------------------------------------------\n" "===\n"); } ast_cli(a->fd, "=============================================================\n" "\n"); return CLI_SUCCESS; }
void saClmClusterTrackStop_01(void) { trackFlags = SA_TRACK_CURRENT; nodeId = 131343; invocation = 600; safassert(saClmInitialize(&clmHandle, &clmCallback11, &clmVersion_1), SA_AIS_OK); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); rc = saClmClusterNodeGetAsync(clmHandle, invocation, nodeId); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); rc = saClmClusterNodeGetAsync(clmHandle, invocation, nodeId); rc = saClmClusterNodeGetAsync(clmHandle, invocation, nodeId); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); safassert(saClmClusterTrackStop(clmHandle), SA_AIS_OK); safassert(saClmDispatch(clmHandle,SA_DISPATCH_ALL), SA_AIS_OK); rc = saClmClusterTrack(clmHandle, trackFlags, NULL); safassert(saClmClusterTrackStop(clmHandle), SA_AIS_OK); safassert(saClmFinalize(clmHandle), SA_AIS_OK); test_validate(rc, SA_AIS_OK); }
void saftest_daemon_handle_cluster_track_request( saftest_map_table_entry_t *map_entry, saftest_msg_t *request, saftest_msg_t **reply) { clm_session_t *clm_session = NULL; SaClmClusterNotificationBufferT *buffer = NULL; SaClmClusterNotificationBufferT real_buffer; SaAisErrorT status; SaUint8T track_flags = 0; const char *xml_file = NULL; FILE *fp = NULL; saftest_log("Received a cluster track request for id %d\n", saftest_msg_get_ubit32_value(request, "CLM_SESSION_ID")); clm_session = lookup_clm_session_from_request(request); if (0 == strcmp("TRUE", saftest_msg_get_str_value(request, "TRACK_CURRENT"))) { track_flags |= SA_TRACK_CURRENT; } if (0 == strcmp("TRUE", saftest_msg_get_str_value(request, "TRACK_CHANGES"))) { track_flags |= SA_TRACK_CHANGES; } if (0 == strcmp("TRUE", saftest_msg_get_str_value(request, "TRACK_CHANGES_ONLY"))) { track_flags |= SA_TRACK_CHANGES_ONLY; } if (0 == strcmp("TRUE", saftest_msg_get_str_value(request, "INVALID_TRACK_FLAGS"))) { track_flags = -1; } if ((track_flags & SA_TRACK_CURRENT) && (0 == strcmp("FALSE", saftest_msg_get_str_value(request, "NULL_NOTIFICATION_BUFFER")))) { buffer = &real_buffer; if (0 == strcmp("FALSE", saftest_msg_get_str_value(request, "NULL_CLUSTER_NOTIFICATION"))) { buffer->numberOfItems = saftest_msg_get_ubit32_value(request, "NUMBER_OF_ITEMS"); if (0 == buffer->numberOfItems) { /* * This is a special unit test case, setting a pointer for * notification_buffer->notification but setting numberOfItems * to be 0. */ buffer->notification = (SaClmClusterNotificationT *)buffer; } else { buffer->notification = (SaClmClusterNotificationT *) malloc(buffer->numberOfItems * sizeof(SaClmClusterNotificationT)); if (NULL == buffer->notification) { saftest_abort("unable to allocate cluster notification array"); } } } } clm_session->track_flags = track_flags; if (((track_flags & SA_TRACK_CHANGES) && !(track_flags & SA_TRACK_CHANGES_ONLY)) || ((track_flags & SA_TRACK_CHANGES_ONLY) && !(track_flags & SA_TRACK_CHANGES))) { saftest_log("Will write the callback info to %s\n", saftest_msg_get_str_value(request, "XML_FILE")); strcpy(clm_session->cluster_track_callback_xml_file, saftest_msg_get_str_value(request, "XML_FILE")); } else { memset(clm_session->cluster_track_callback_xml_file, 0, sizeof(clm_session->cluster_track_callback_xml_file)); } status = saClmClusterTrack(clm_session->clm_handle, clm_session->track_flags, buffer); if ((SA_AIS_OK == status) && (track_flags & SA_TRACK_CURRENT) && (NULL != buffer)) { xml_file = saftest_msg_get_str_value(request, "XML_FILE"); saftest_assert(NULL != xml_file, "Must provide an XML_FILE"); fp = fopen(xml_file, "w+"); if (NULL == fp) { saftest_abort("Unable to open %s for writing\n", xml_file); } saftest_daemon_write_cluster(fp, buffer); fclose(fp); } (*reply) = saftest_reply_msg_create(request, map_entry->reply_op, status); }
static void test_clm_during_cpg_test(void) { SaClmHandleT clmHandle = { 0 }; SaAisErrorT err; SaClmCallbacksT callbacks = { .saClmClusterNodeGetCallback = _clm_nodeget_callback, .saClmClusterTrackCallback = _clm_nodetrack_callback, }; SaVersionT version = { .releaseCode = 'B', .majorVersion = 1, .minorVersion = 1 }; SaClmClusterNodeT node; int status = 0; pid_t r; while ( (err = saClmInitialize(&clmHandle, &callbacks, &version)) == SA_AIS_ERR_TRY_AGAIN ); if ( err != SA_AIS_OK ) DIE("saClmInitialize(): %d", err); if ( (err = saClmClusterNodeGet(clmHandle, SA_CLM_LOCAL_NODE_ID, 1000000, &node)) != SA_AIS_OK ) DIE("saClmNodeGet(): %d", err); test_data.node_id = node.nodeId; DPRINTF("We are '%.*s', ID: %d", node.nodeName.length, node.nodeName.value, node.nodeId); if ( (err = saClmClusterTrack(clmHandle, SA_TRACK_CURRENT | SA_TRACK_CHANGES, NULL)) != SA_AIS_OK ) DIE("saClmClusterTrack(): %d", err); r = 0; status = 0; /* Note: The man pages of FreeBSD says that waitpid() should return 0 if no process has ended * but I get 1 instead. Weird. * TODO(Jflesch): Figure out what I did wrong. */ while ( test_data.keep_dispatching && (test_data.test_cpg_pid == -1 || ( (r = waitpid(test_data.test_cpg_pid, &status, WNOHANG) != -1) && (r == 0 || r == 1 || (!WIFEXITED(status) && !WIFSIGNALED(status))) ) ) ) { if ( (err = saClmDispatch(clmHandle, SA_DISPATCH_ALL)) != SA_AIS_OK ) DIE("saClmDispatch(): %d", err); if ( test_data.nmb_peers == test_data.max_nmb_peers ) { if ( test_data.master_id != test_data.node_id ) { DPRINTF("Synchronized."); /* -> we are a slave, the only thing we have to do is run CPG tests again */ test_data.keep_dispatching = 0; test_data.run_cpg_test = 1; } else if ( test_data.test_cpg_pid == -1 ) { DPRINTF("Synchronized."); test_data.nmb_clm_notifications = 0; DPRINTF("(master) Running CPG tests ..."); test_data.test_cpg_pid = start_cpg_tests(); /* // */ DPRINTF("(master) CPG tests started"); } } usleep(10 * 1000); /* 10ms */ } if ( test_data.keep_dispatching ) /* => end of test */ { if ( test_data.test_cpg_pid < 0 ) DIE("CPG tests not even started"); if ( r <= -1 ) DIE("waitpid() failed: %d, %s", errno, strerror(errno)); if ( WIFSIGNALED(status) ) DIE("CPG tests died because of signal %d", WTERMSIG(status)); if ( WEXITSTATUS(status) != 0 ) DIE("CPG tests died returning the value %d", WEXITSTATUS(status)); } #ifdef BE_NICE if ( (err = saClmClusterTrackStop(clmHandle)) != SA_AIS_OK ) DIE("saClmTrackStop(): %d", err); #endif if ( (err = saClmFinalize(clmHandle)) != SA_AIS_OK ) DIE("saClmFinalize(): %d", err); if ( test_data.nmb_clm_notifications <= 0 ) DIE("Got no CLM notifications"); if ( test_data.run_cpg_test ) { DPRINTF("(slave) Running CPG tests ..."); test_cpg_multiplayer(test_data.max_nmb_peers); DPRINTF("(slave) CPG test finished"); } } void test_clm(int nmb_peers) { if ( nmb_peers <= 1 ) DIE("Not enought peers"); test_data = TEST_DATA_START_VALUE; test_data.max_nmb_peers = nmb_peers; DPRINTF(" - Rerun of the CPG multiplayer test, keeping an eye on CLM behavior"); test_clm_during_cpg_test(); /* DPRINTF(" - Misuse of the API"); ? */ }