Пример #1
0
 /**
  * exec method with the same interface as that in KWUtils, will simulate
  * an execution of the condor_submit_dag executable for a few select test cases.
  *
  * @param string $command
  * @param null|mixed $output
  * @param string $chdir
  * @param null|mixed $return_val
  * @throws Zend_Exception
  */
 public function exec($command, &$output = null, $chdir = '', &$return_val = null)
 {
     // just doing the same things as the actual KWUtils exec to check
     // that this function will work the same as the exec function other
     // than the actual exec system call
     if (!empty($chdir) && is_dir($chdir)) {
         if (!chdir($chdir)) {
             throw new Zend_Exception('Failed to change directory: [' . $chdir . ']');
         }
     }
     // on Linux need to add redirection to handle stderr
     $command = KWUtils::escapeCommand($command);
     // all test cases should have the proper syntax, verify this
     if (!preg_match('/' . MIDAS_BATCHMAKE_CONDOR_SUBMIT_DAG . ".*\\'(\\S*)\\'/", $command, $matches)) {
         throw new Zend_Exception('malformed condor_submit_dag command');
     }
     $scriptName = $matches[1];
     if (preg_match('/CompileReturnNonzero.dagjob/', $scriptName)) {
         $return_val = -1;
         $output = array('1 error', '1');
     } elseif (preg_match('/Compiles.dagjob/', $scriptName)) {
         // do a bit of checking
         // ensure the $scriptName exists in the $chdir
         if (!file_exists($chdir . '/' . $scriptName)) {
             $return_val = -1;
             $output = array('1 error can not find ' . $chdir . '/' . $scriptName, '1');
             return;
         }
         $return_val = 0;
         $output = array('');
     } else {
         throw new Zend_Exception('Unexpected dagjob test script: ' . $scriptName);
     }
 }
Пример #2
0
 /**
  * has the same interface as KWUtils.exec, used to simulate a BatchMake
  * executable for testing.
  *
  * @param string $command
  * @param null|mixed $output
  * @param string $chdir
  * @param null|mixed $return_val
  * @throws Zend_Exception
  */
 public function exec($command, &$output = null, $chdir = '', &$return_val = null)
 {
     // just doing the same things as the actual KWUtils exec to check
     // that this function will work the same as the exec function other
     // than the actual exec system call
     if (!empty($chdir) && is_dir($chdir)) {
         if (!chdir($chdir)) {
             throw new Zend_Exception('Failed to change directory: [' . $chdir . ']');
         }
     }
     $command = KWUtils::escapeCommand($command);
     // now look for particular commands that this Mock object can service
     if (preg_match('/' . $this->compileFlag . '/', $command)) {
         $this->execCompile($command, $output, $chdir, $return_val);
     } elseif (preg_match('/' . $this->generateDagFlag . '/', $command)) {
         $this->execGenerateCondorDag($command, $output, $chdir, $return_val);
     } else {
         throw new Zend_Exception('unexepected BatchMake command flag:' . $command);
     }
 }