END_TEST START_TEST(get_reservation_command_test) { resizable_array *hrl = parse_exec_hosts(eh1); dynamic_string *apbasil_command; char *reserve_param; char *reserve_param2; char *nppn; int ppn; apbasil_command = get_reservation_command(hrl, uname, jobids[0], NULL, apbasil_protocol, NULL, 0, 0); snprintf(buf, sizeof(buf), "Username '%s' not found in command '%s'", uname, apbasil_command->str); fail_unless(strstr(apbasil_command->str, uname) != NULL, buf); reserve_param = strstr(apbasil_command->str, "ReserveParam "); fail_unless(reserve_param != NULL, "Couldn't find a ReserveParam element in the request"); reserve_param2 = strstr(reserve_param + 1, "ReserveParam "); snprintf(buf, sizeof(buf), "Found two ReserveParam elements when there should be only one '%s'", apbasil_command->str); fail_unless(reserve_param2 == NULL, buf); free_resizable_array(hrl); free_dynamic_string(apbasil_command); hrl = parse_exec_hosts(eh3); apbasil_command = get_reservation_command(hrl, uname, jobids[1], apbasil_path, apbasil_protocol, NULL, 0, 1); reserve_param = strstr(apbasil_command->str, "ReserveParam "); reserve_param2 = strstr(reserve_param + 1, "ReserveParam "); fail_unless(reserve_param != NULL, "Couldn't find the first ReserveParam element in the request"); nppn = strstr(reserve_param, "nppn"); fail_unless(nppn != NULL, "Couldn't find the nppn specification in the first reservation"); nppn += strlen("nppn='"); ppn = atoi(nppn); snprintf(buf, sizeof(buf), "nppn should be 3 but is %d", ppn); fail_unless(ppn == 3, buf); }
int create_alps_reservation( char *exec_hosts, char *username, char *jobid, char *apbasil_path, char *apbasil_protocol, long long pagg_id_value, char **reservation_id) { resizable_array *host_req_list; dynamic_string *command; int rc = 1; int retry_count = 0; char *user = strdup(username); char *aroba; host_req_list = parse_exec_hosts(exec_hosts); if (host_req_list->num == 0) { /* this is a login only job */ return(PBSE_NONE); } if ((aroba = strchr(user, '@')) != NULL) *aroba = '\0'; command = get_reservation_command(host_req_list, user, jobid, apbasil_path, apbasil_protocol); free(user); /* retry on failure up to */ while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = execute_reservation(command->str, reservation_id); if (rc != PBSE_NONE) usleep(100); } free_dynamic_string(command); if (rc == PBSE_NONE) { rc = 1; retry_count = 0; while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = confirm_reservation(jobid, *reservation_id, pagg_id_value, apbasil_path, apbasil_protocol); if (rc != PBSE_NONE) usleep(100); } } return(rc); } /* END create_alps_reservation() */
int create_alps_reservation( char *exec_hosts, char *username, char *jobid, char *apbasil_path, char *apbasil_protocol, long long pagg_id_value, int use_nppn, int nppcu, int mppdepth, char **reservation_id, const char *mppnodes) { resizable_array *host_req_list; dynamic_string *command; int rc = 1; int retry_count = 0; char *user = strdup(username); char *aroba; if ((aroba = strchr(user, '@')) != NULL) *aroba = '\0'; if (strchr(exec_hosts, '|') == NULL) { host_req_list = parse_exec_hosts(exec_hosts,mppnodes); if (host_req_list->num == 0) { free(user); free_resizable_array(host_req_list); /* this is a login only job */ return(PBSE_NONE); } command = get_reservation_command(host_req_list, user, jobid, apbasil_path, apbasil_protocol, NULL, use_nppn, nppcu, mppdepth); free_resizable_array(host_req_list); } else { command = get_reservation_command(NULL, user, jobid, apbasil_path, apbasil_protocol, exec_hosts, use_nppn, nppcu, mppdepth); } free(user); /* retry on failure up to */ while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = execute_reservation(command->str, reservation_id); if (rc != PBSE_NONE) usleep(100); } if (rc == PBSE_NONE) { char confirm_command_buf[MAXLINE * 2]; if (LOGLEVEL >= 3) { snprintf(log_buffer, sizeof(log_buffer), "Successful reservation command is: %s", command->str); log_event(PBSEVENT_JOB | PBSEVENT_SYSLOG, PBS_EVENTCLASS_JOB, __func__, log_buffer); } rc = 1; retry_count = 0; while ((retry_count++ < APBASIL_RETRIES) && (rc != apbasil_fail_permanent) && (rc != PBSE_NONE)) { rc = confirm_reservation(jobid, *reservation_id, pagg_id_value, apbasil_path, apbasil_protocol, confirm_command_buf, sizeof(confirm_command_buf)); if (rc != PBSE_NONE) usleep(100); } if (rc != PBSE_NONE) { snprintf(log_buffer, sizeof(log_buffer), "Failed confirmation command is: %s", confirm_command_buf); log_err(-1, __func__, confirm_command_buf); } else if (LOGLEVEL >= 3) { snprintf(log_buffer, sizeof(log_buffer), "Successful confirmation command is: %s", confirm_command_buf); log_event(PBSEVENT_JOB | PBSEVENT_SYSLOG, PBS_EVENTCLASS_JOB, __func__, log_buffer); } } else { snprintf(log_buffer, sizeof(log_buffer), "Failed reservation command is: %s", command->str); log_err(-1, __func__, log_buffer); } free_dynamic_string(command); return(rc); } /* END create_alps_reservation() */