Exemplo n.º 1
0
int confirm_reservation(

  char       *jobid,
  char       *reservation_id,
  long long   pagg_id_value,
  char       *apbasil_path,
  char       *apbasil_protocol,
  char       *command_buf,
  int         command_buf_size)

  {
  int       rc;
  FILE     *alps_pipe;
  int       fd;
  char      output[MAXLINE * 4];
  char     *ptr;
  int       bytes_read;
  int       total_bytes_read = 0;

  get_confirm_command(reservation_id, 
    pagg_id_value,
    apbasil_protocol,
    apbasil_path,
    command_buf,
    command_buf_size);


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

    return(WRITING_PIPE_ERROR);
    }

  fd = fileno(alps_pipe);

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

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

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

  if ((bytes_read == -1) ||
      (total_bytes_read == 0))
    rc = READING_PIPE_ERROR;
  else
    rc = parse_confirmation_output(output);

  return(rc);
  } /* END confirm_reservation() */
END_TEST




START_TEST(confirm_reservation_test)
  {
  char      *rsv_id = (char *)"20";
  long long  pagg = 20;
  int        rc;

  /* this test only works if you're root */
  if (getuid() == 0)
    {
    rc = confirm_reservation(jobids[0], rsv_id, pagg, NULL, apbasil_protocol);
    /*fail_unless(rc == 0, "Couldn't execute the reservation");*/
    snprintf(buf, sizeof(buf), "Reservation id should be 20 but was %s", rsv_id);
    fail_unless(!strcmp(rsv_id, "20"), buf);
    
    rc = confirm_reservation(jobids[1], rsv_id, pagg, blank_cmd, apbasil_protocol);
    fail_unless(rc != 0, "Somehow parsed the blank command's output?");
    
    rc = parse_confirmation_output((char *)"tom");
    fail_unless(rc == ALPS_PARSING_ERROR, "We parsed non-xml?");
    }
  }