END_TEST 

START_TEST(parse_alps13_output_test)
  {
  /* test 1.3 protocol strings */

  #define ALPS_13_INPUT_FILE "basil_13_short.xml"

  std::string output = "";
  std::vector<std::string> status;
  int             rc;
  FILE           *fp;
  char            linebuf[1024];

  if ((fp = fopen(ALPS_13_INPUT_FILE, "r")) == NULL)
    ck_abort_msg("Couldn't open ALPS 13 input file %s", ALPS_13_INPUT_FILE);

  while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
    output += linebuf;

  fclose(fp);

  rc = parse_alps_output(output, status);
  fail_unless(rc == 0, "Couldn't parse ALPS 1.3 output contained in file %s", ALPS_13_INPUT_FILE);

  fail_unless(search_dynamic_string_status(status, (char *)"6142") == 1, "Couldn't find node 6142 in the 1.3 status");
  fail_unless(search_dynamic_string_status(status, (char *)"CPROC") == 1, "Couldn't find CPROC in the 1.3 status");
  fail_unless(search_dynamic_string_status(status, (char *)"APROC") == 1, "Couldn't find APROC in the 1.3 status");
  fail_unless(search_dynamic_string_status(status, (char *)"CCU") == 1, "Couldn't find CCU in the 1.3 status");

  }
Ejemplo n.º 2
0
int generate_alps_status(

  std::vector<std::string> &status,
  const char               *apbasil_path,
  const char               *apbasil_protocol)

  {
  int             rc;
  char            inventory_command[MAXLINE * 2];
  std::string     alps_output;

  status.clear();
  alps_nodes.clear();

  snprintf(inventory_command, sizeof(inventory_command), APBASIL_QUERY,
    (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL,
    (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH);

  rc = get_command_output(inventory_command, alps_output);

  if (rc == PBSE_NONE)
    {
    rc = parse_alps_output(alps_output);

    if (rc == PBSE_NONE)
      {
      if (LOGLEVEL >= 7)
        {
        /* log the command if output successfully parsed */
        snprintf(log_buffer, sizeof(log_buffer),
          "Successful inventory command is: %s", inventory_command);
        log_event(PBSEVENT_JOB | PBSEVENT_SYSLOG, PBS_EVENTCLASS_JOB, __func__, log_buffer);
        }

      if (!strcmp(apbasil_protocol, "1.7"))
        rc = get_knl_information(apbasil_path);
        
      if (rc == PBSE_NONE)
        update_status(status);
      }
    }

  return(rc);
  } /* END generate_alps_status() */
Ejemplo n.º 3
0
int get_knl_information(

  const char *apbasil_path)

  {
  int         rc;
  std::string knl_output;
  char        system_command[MAXLINE * 2];

  snprintf(system_command, sizeof(system_command), APBASIL_SYSTEM,
    "1.7",
    (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH);

  rc = get_command_output(system_command, knl_output);

  if (rc == PBSE_NONE)
    rc = parse_alps_output(knl_output);

  return(rc);
  } // END get_knl_information()
int generate_alps_status(

  dynamic_string *status,
  const char     *apbasil_path,
  const char     *apbasil_protocol)

  {
  FILE           *alps_pipe;
  int             fd;
  int             rc;
  int             bytes_read;
  int             total_bytes_read = 0;
  char            inventory_command[MAXLINE * 2];
  char            input_buffer[MAXLINE];
  char           *ptr;
  dynamic_string *alps_output;

  if ((alps_output = get_dynamic_string(-1, NULL)) == NULL)
    return(ENOMEM);

  snprintf(inventory_command, sizeof(inventory_command), APBASIL_QUERY,
    (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL,
    (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH);

  if ((alps_pipe = popen(inventory_command, "r")) == NULL)
    {
    snprintf(log_buffer, sizeof(log_buffer),
      "Unable to open command %s for apbasil",
      inventory_command);
    log_err(errno, __func__, log_buffer);

    return(WRITING_PIPE_ERROR);
    }

  fd = fileno(alps_pipe);

  /* now read from the pipe */
  ptr = input_buffer;
  memset(input_buffer, 0, sizeof(input_buffer));

  while ((bytes_read = read(fd, ptr, sizeof(input_buffer) - 1)) > 0)
    {
    append_dynamic_string(alps_output, ptr);
    memset(input_buffer, 0, sizeof(input_buffer));
    total_bytes_read += bytes_read;
    }

  /* perform post-processing */
  pclose(alps_pipe);

  if ((bytes_read == -1) ||
      (total_bytes_read == 0))
    rc = READING_PIPE_ERROR;
  else
    {
    int index = alps_output->used - 1;
    while (alps_output->str[index] != '>')
      {
      alps_output->str[index] = '\0';
      index--;
      }

    alps_output->used -= 1;
    rc = parse_alps_output(alps_output, status);
    }

  free_dynamic_string(alps_output);

  return(rc);
  } /* END generate_alps_status() */
Ejemplo n.º 5
0
int generate_alps_status(

  boost::ptr_vector<std::string>& status,
  const char     *apbasil_path,
  const char     *apbasil_protocol)

  {
  FILE           *alps_pipe;
  int             fd;
  int             rc;
  int             bytes_read;
  int             total_bytes_read = 0;
  char            inventory_command[MAXLINE * 2];
  char            input_buffer[MAXLINE];
  char           *ptr;
  std::string     alps_output = "";

  snprintf(inventory_command, sizeof(inventory_command), APBASIL_QUERY,
    (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL,
    (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH);

  if ((alps_pipe = popen(inventory_command, "r")) == NULL)
    {
    snprintf(log_buffer, sizeof(log_buffer),
      "Unable to open command %s for apbasil",
      inventory_command);
    log_err(errno, __func__, log_buffer);

    return(WRITING_PIPE_ERROR);
    }

  fd = fileno(alps_pipe);

  /* now read from the pipe */
  ptr = input_buffer;
  memset(input_buffer, 0, sizeof(input_buffer));

  while ((bytes_read = read(fd, ptr, sizeof(input_buffer) - 1)) > 0)
    {
    alps_output += ptr;
    memset(input_buffer, 0, sizeof(input_buffer));
    total_bytes_read += bytes_read;
    }

  /* perform post-processing */
  pclose(alps_pipe);

  if ((bytes_read == -1) ||
      (total_bytes_read == 0))
    rc = READING_PIPE_ERROR;
  else
    {
    int index = alps_output.length() - 1;
    while (alps_output.c_str()[index] != '>')
      {
      alps_output.resize(index);
      index--;
      }

    rc = parse_alps_output(alps_output, status);
    }

  return(rc);
  } /* END generate_alps_status() */