8 require_once(
"./test_common.php");
24 public $fossology_testconfig;
27 public $scheduler_path;
33 public $fossjobs_path;
40 global $fossology_testconfig;
41 global $scheduler_path;
43 global $fossjobs_path;
45 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
52 $fossology_testconfig = getenv(
'FOSSOLOGY_TESTCONFIG');
53 fwrite(STDOUT, __METHOD__ .
" got fossology_testconfig = '$fossology_testconfig'\n");
57 $fo_base_dir = realpath(__DIR__ .
'/../..');
58 $cp2foss_path = $fo_base_dir .
"/cli/cp2foss";
59 if (!is_executable($cp2foss_path)) {
60 print
"Error: cp2foss path '" . $cp2foss_path .
"' is not executable!\n";
65 $fossjobs_path = $fo_base_dir .
"/cli/fossjobs";
66 if (!is_executable($fossjobs_path)) {
67 print
"Error: fossjobs path '" . $cp2foss_path .
"' is not executable!\n";
72 $scheduler_path = $fossology_testconfig .
"/mods-enabled/scheduler/agent/fo_scheduler";
73 if (!is_executable($scheduler_path)) {
74 print
"Error: Scheduler path '$scheduler_path' is not executable!\n";
79 $scheduler_cmd =
"$scheduler_path --daemon --reset --verbose=952 -c $fossology_testconfig";
80 print
"DEBUG: Starting scheduler with '$scheduler_cmd'\n";
81 exec($scheduler_cmd, $output, $return_var);
83 if ( $return_var != 0 ) {
84 print
"Error: Could not start scheduler '$scheduler_path'\n";
89 print
"\nStarting functional test for fossjobs. \n";
94 protected function setUp() : void
97 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
106 global $fossology_testconfig;
107 global $scheduler_path;
108 global $cp2foss_path;
109 global $fossjobs_path;
111 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
113 $test_dbh = connect_to_DB($fossology_testconfig);
117 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
118 $cp2foss_command =
"$cp2foss_path -s $auth ./ -f fossjobs -d 'fossjobs testing'";
120 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$cp2foss_command'\n");
121 $last = exec(
"$cp2foss_command 2>&1", $out, $rtn);
125 if ($out && $out[5]) {
126 $upload_id = get_upload_id($out[5]);
128 $this->assertFalse(
true);
132 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
133 $this->assertEquals(1, $agent_status);
136 $command =
"$fossjobs_path $auth -U $upload_id -A agent_copyright,agent_mimetype,agent_nomos,agent_pkgagent -v";
137 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
138 $last = exec(
"$command 2>&1", $out, $rtn);
139 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" Waiting 300 seconds for the agents to complete\n");
141 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
142 $this->assertEquals(1, $agent_status);
144 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
145 $this->assertEquals(1, $agent_status);
147 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
148 $this->assertEquals(1, $agent_status);
150 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
151 $this->assertEquals(1, $agent_status);
157 $cp2foss_command =
"$cp2foss_path -s $auth ./test_fossjobs.php -f fossjobs -d 'fossjobs testing copyright' -q agent_copyright";
158 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$cp2foss_command'\n");
159 $last = exec(
"$cp2foss_command 2>&1", $out, $rtn);
163 if ($out && $out[5]) {
164 $upload_id = get_upload_id($out[5]);
166 $this->assertFalse(
true);
171 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
172 $this->assertEquals(1, $agent_status);
174 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
175 $this->assertEquals(1, $agent_status);
178 $command =
"$fossjobs_path $auth -U $upload_id -v -A agent_nomos";
179 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
180 $last = exec(
"$command 2>&1", $out, $rtn);
185 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
186 $this->assertEquals(1, $agent_status);
188 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
198 global $fossology_testconfig;
199 global $scheduler_path;
200 global $cp2foss_path;
201 global $fossjobs_path;
203 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
207 $command =
"$fossjobs_path -h -c $fossology_testconfig";
208 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
209 $last = exec(
"$command 2>&1", $out, $rtn);
210 $output_msg_count = count($out);
212 $this->assertEquals(18, $output_msg_count);
213 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
217 $command =
"$fossjobs_path $auth -a ";
218 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
219 $last = exec(
"$command 2>&1", $out, $rtn);
221 $output_msg_count = count($out);
222 $this->assertEquals(10, $output_msg_count);
227 $command =
"$fossjobs_path $auth -u ";
228 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
229 $last = exec(
"$command 2>&1", $out, $rtn);
230 fwrite(STDOUT,
"DEBUG: output was:\n");
232 $output_msg_count = count($out);
237 $this->assertEquals(3, $output_msg_count, $command);
239 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
247 global $fossology_testconfig;
249 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
259 public static function tearDownAfterClass()
262 global $fossology_testconfig;
263 global $scheduler_path;
264 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
267 print
"Stopping the scheduler\n";
268 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
269 print
"DEBUG: command is $scheduler_cmd \n";
270 exec($scheduler_cmd, $output, $return_var);
271 if ( $return_var != 0 ) {
272 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
280 print
"End of functional tests for cp2foss \n";
static setUpBeforeClass()
test_reschedule_agents()
schedule agents
test_list_agent_and_others()
list agents, list uploads, help msg