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);
  }
Example #2
0
TEST(strutil_test, parse_exec_hosts) {
  std::vector<std::string> ehv;
  std::string exec_hosts("napali/0+napali/1+napali/2+eris/0+eris/1+eris/2");
  std::string exec_hosts2("napali/0-2+eris/0-2");

  parse_exec_hosts(exec_hosts, ehv);
  EXPECT_EQ(6, ehv.size());
  EXPECT_STREQ("napali", ehv[0].c_str());
  EXPECT_STREQ("napali", ehv[1].c_str());
  EXPECT_STREQ("napali", ehv[2].c_str());
  EXPECT_STREQ("eris", ehv[3].c_str());
  EXPECT_STREQ("eris", ehv[4].c_str());
  EXPECT_STREQ("eris", ehv[5].c_str());

  ehv.clear();

  parse_exec_hosts(exec_hosts2, ehv);
  EXPECT_EQ(2, ehv.size());
  EXPECT_STREQ("napali", ehv[0].c_str());
  EXPECT_STREQ("eris", ehv[1].c_str());
}
Example #3
0
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() */
Example #4
0
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() */
END_TEST




START_TEST(parse_exec_hosts_test)
  {
  resizable_array *hrl = parse_exec_hosts(eh1);
  int              iter = -1;
  int              host_count = 0;
  host_req        *hr;

  while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL)
    {
    snprintf(buf, sizeof(buf), "ppn should be %d but is %d", 2, hr->ppn);
    fail_unless(hr->ppn == 2, buf);
    host_count++;
    free(hr->hostname);
    }

  snprintf(buf, sizeof(buf), "Should be 2 hosts but there were %d", host_count);
  fail_unless(host_count == 2, buf);

  free_resizable_array(hrl);
  hrl = parse_exec_hosts(eh2);
  iter = -1;
  host_count = 0;

  while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL)
    {
    if (host_count == 0)
      {
      snprintf(buf, sizeof(buf), "Hostname should be napali but is %s", hr->hostname);
      fail_unless(!strcmp(hr->hostname, "napali"), buf);

      snprintf(buf, sizeof(buf), "ppn should be 2 but is %d", hr->ppn);
      fail_unless(hr->ppn == 2, buf);
      }
    else
      {
      snprintf(buf, sizeof(buf), "Hostname should be l11 but is %s", hr->hostname);
      fail_unless(!strcmp(hr->hostname, "l11"), buf);

      snprintf(buf, sizeof(buf), "ppn should be 3 but is %d", hr->ppn);
      fail_unless(hr->ppn == 3, buf);
      }

    free(hr->hostname);
    host_count++;
    }

  snprintf(buf, sizeof(buf), "Should count 2 hosts but counted %d", host_count);
  fail_unless(host_count == 2, buf);

  free_resizable_array(hrl);
  hrl = parse_exec_hosts(eh3);
  iter = -1;
  host_count = 0;

  while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL)
    {
    if (host_count < 2)
      {
      snprintf(buf, sizeof(buf), "ppn should be 2 but is %d", hr->ppn);
      fail_unless(hr->ppn == 2, buf);
      }
    else if (host_count >= 2)
      {
      snprintf(buf, sizeof(buf), "ppn should be 3 but is %d", hr->ppn);
      fail_unless(hr->ppn == 3, buf);
      }

    free(hr->hostname);
    host_count++;
    }

  snprintf(buf, sizeof(buf), "Should count 4 hosts but counted %d", host_count);
  fail_unless(host_count == 4, buf);

  free_resizable_array(hrl);
  }