FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerScheduler.php
1 <?php
2 /*
3 Copyright (C) 2019, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Ojo\Test;
20 
22 
23 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
24 include_once(__DIR__.'/SchedulerTestRunner.php');
25 
31 {
35  private $testDb;
36 
37  public function __construct(TestPgDb $testDb)
38  {
39  $this->testDb = $testDb;
40  }
41 
42  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
43  {
44  $sysConf = $this->testDb->getFossSysConf();
45 
46  $agentName = "ojo";
47 
48  $agentDir = dirname(dirname(__DIR__));
49  $execDir = "$agentDir/agent";
50  system("install -D $agentDir/VERSION $sysConf/mods-enabled/$agentName/VERSION");
51  system("install -D $agentDir/agent/$agentName $sysConf/mods-enabled/$agentName/agent/$agentName");
52  $pCmd = "echo $uploadId | $execDir/$agentName --userID=$userId --groupID=$groupId --jobId=$jobId --scheduler_start -c $sysConf $args";
53  $pipeFd = popen($pCmd, "r");
54  $success = $pipeFd !== false;
55 
56  $output = "";
57  $retCode = -1;
58  if ($success) {
59  while (($buffer = fgets($pipeFd, 4096)) !== false) {
60  $output .= $buffer;
61  }
62  $retCode = pclose($pipeFd);
63  } else {
64  print "failed opening pipe to $cmd";
65  }
66 
67  unlink("$sysConf/mods-enabled/$agentName/VERSION");
68  unlink("$sysConf/mods-enabled/$agentName/agent/$agentName");
69  rmdir("$sysConf/mods-enabled/$agentName/agent/");
70  rmdir("$sysConf/mods-enabled/$agentName");
71  rmdir("$sysConf/mods-enabled");
72  unlink($sysConf."/fossology.conf");
73 
74  return array($success, $output, $retCode);
75  }
76 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, $args="")
Function to run agent from scheduler.