FOSSology  4.7.1
Open Source License Compliance by Open Source Software
SchedulerTestRunnerCli.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2014 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Reuser\Test;
9 
11 
12 include_once(__DIR__.'/../../../lib/php/Test/Agent/AgentTestMockHelper.php');
13 include_once(__DIR__.'/SchedulerTestRunner.php');
14 
20 {
24  private $testDb;
25 
26  public function __construct(TestPgDb $testDb)
27  {
28  $this->testDb = $testDb;
29  }
30 
31  public function run($uploadId, $userId=2, $groupId=2, $jobId=1, array $args=[])
32  {
33  $sysConf = $this->testDb->getFossSysConf();
34 
35  $agentName = "reuser";
36 
37  $agentDir = dirname(dirname(__DIR__));
38 
39  // Ensure VERSION is staged for the scheduler (create mods-enabled entry)
40  $installCmd = 'install -D ' . escapeshellarg($agentDir . '/VERSION') . ' ' . escapeshellarg($sysConf . '/mods-enabled/' . $agentName . '/VERSION');
41  system($installCmd);
42 
43  $execPath = $agentDir . '/agent/' . $agentName;
44 
45  $extraArgs = implode(' ', array_map('escapeshellarg', $args));
46  $cmd = 'echo ' . escapeshellarg((string)$uploadId) . ' | ' . escapeshellarg($execPath) . ' --userID=' . escapeshellarg((string)$userId) . ' --groupID=' . escapeshellarg((string)$groupId) . ' --jobId=' . escapeshellarg((string)$jobId) . ' --scheduler_start -c ' . escapeshellarg($sysConf) . ($extraArgs !== '' ? ' ' . $extraArgs : '');
47  $pipeFd = popen($cmd, 'r');
48  $success = $pipeFd !== false;
49 
50  $output = "";
51  $retCode = -1;
52  if ($success) {
53  while (($buffer = fgets($pipeFd, 4096)) !== false) {
54  $output .= $buffer;
55  }
56  $retCode = pclose($pipeFd);
57  } else {
58  print "failed opening pipe to $cmd";
59  }
60 
61  unlink("$sysConf/mods-enabled/$agentName/VERSION");
62  rmdir("$sysConf/mods-enabled/$agentName");
63  rmdir("$sysConf/mods-enabled");
64 
65  return array($success, $output, $retCode);
66  }
67 }
run($uploadId, $userId=2, $groupId=2, $jobId=1, array $args=[])
Function to run agent from scheduler.
Namespace to hold test cases for Reuser agent.