MCPcopy Create free account
hub / github.com/corosync/corosync / test_cmap_restart

Function test_cmap_restart

test/testsam.c:1186–1313  ·  view source on GitHub ↗

* Test cmap integration + restart policy */

Source from the content-addressed store, hash-verified

1184 * Test cmap integration + restart policy
1185 */
1186static int test_cmap_restart (pid_t pid, pid_t old_pid, int test_n) {
1187 cs_error_t err;
1188 cmap_handle_t cmap_handle;
1189 unsigned int instance_id;
1190 char *str;
1191 char key_name[CMAP_KEYNAME_MAXLEN];
1192
1193 err = cmap_initialize (&cmap_handle);
1194 if (err != CS_OK) {
1195 printf ("Could not initialize Cluster Map API instance error %d. Test skipped\n", err);
1196 return (1);
1197 }
1198
1199 printf ("%s test %d\n", __FUNCTION__, test_n);
1200
1201 if (test_n == 1) {
1202 printf ("%s: initialize\n", __FUNCTION__);
1203 err = sam_initialize (2000, SAM_RECOVERY_POLICY_RESTART | SAM_RECOVERY_POLICY_CMAP);
1204 if (err != CS_OK) {
1205 fprintf (stderr, "Can't initialize SAM API. Error %d\n", err);
1206 return 2;
1207 }
1208
1209 printf ("%s: register\n", __FUNCTION__);
1210 err = sam_register (&instance_id);
1211 if (err != CS_OK) {
1212 fprintf (stderr, "Can't register. Error %d\n", err);
1213 return 2;
1214 }
1215 printf ("%s: iid %d\n", __FUNCTION__, instance_id);
1216
1217 if (instance_id < 3) {
1218 snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.recovery", pid);
1219 err = cmap_get_string(cmap_handle, key_name, &str);
1220 if (err != CS_OK) {
1221 printf ("Could not get \"recovery\" key: %d.\n", err);
1222 return (2);
1223 }
1224
1225 if (strcmp(str, "restart") != 0) {
1226 printf ("Recovery key \"%s\" is not \"restart\".\n", str);
1227 free(str);
1228 return (2);
1229 }
1230 free(str);
1231
1232 snprintf(key_name, CMAP_KEYNAME_MAXLEN, "resources.process.%d.state", pid);
1233 err = cmap_get_string(cmap_handle, key_name, &str);
1234 if (err != CS_OK) {
1235 printf ("Could not get \"state\" key: %d.\n", err);
1236 return (2);
1237 }
1238
1239 if (strcmp(str, "stopped") != 0) {
1240 printf ("State key is not \"stopped\".\n");
1241 free(str);
1242 return (2);
1243 }

Callers

nothing calls this directly

Calls 6

cmap_initializeFunction · 0.85
sam_initializeFunction · 0.85
sam_registerFunction · 0.85
cmap_get_stringFunction · 0.85
sam_startFunction · 0.85
sam_mark_failedFunction · 0.85

Tested by

no test coverage detected