19 require_once(
"./test_common.php");
35 public $fossology_testconfig;
38 public $scheduler_path;
44 public $fossjobs_path;
51 global $fossology_testconfig;
52 global $scheduler_path;
54 global $fossjobs_path;
56 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
63 $fossology_testconfig = getenv(
'FOSSOLOGY_TESTCONFIG');
64 fwrite(STDOUT, __METHOD__ .
" got fossology_testconfig = '$fossology_testconfig'\n");
68 $fo_base_dir = realpath(__DIR__ .
'/../..');
69 $cp2foss_path = $fo_base_dir .
"/cli/cp2foss";
70 if (!is_executable($cp2foss_path)) {
71 print
"Error: cp2foss path '" . $cp2foss_path .
"' is not executable!\n";
76 $fossjobs_path = $fo_base_dir .
"/cli/fossjobs";
77 if (!is_executable($fossjobs_path)) {
78 print
"Error: fossjobs path '" . $cp2foss_path .
"' is not executable!\n";
83 $scheduler_path = $fossology_testconfig .
"/mods-enabled/scheduler/agent/fo_scheduler";
84 if (!is_executable($scheduler_path)) {
85 print
"Error: Scheduler path '$scheduler_path' is not executable!\n";
90 $scheduler_cmd =
"$scheduler_path --daemon --reset --verbose=952 -c $fossology_testconfig";
91 print
"DEBUG: Starting scheduler with '$scheduler_cmd'\n";
92 exec($scheduler_cmd, $output, $return_var);
94 if ( $return_var != 0 ) {
95 print
"Error: Could not start scheduler '$scheduler_path'\n";
100 print
"\nStarting functional test for fossjobs. \n";
105 protected function setUp()
108 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
117 global $fossology_testconfig;
118 global $scheduler_path;
119 global $cp2foss_path;
120 global $fossjobs_path;
122 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
124 $test_dbh = connect_to_DB($fossology_testconfig);
128 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
129 $cp2foss_command =
"$cp2foss_path -s $auth ./ -f fossjobs -d 'fossjobs testing'";
131 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$cp2foss_command'\n");
132 $last = exec(
"$cp2foss_command 2>&1", $out, $rtn);
136 if ($out && $out[5]) {
137 $upload_id = get_upload_id($out[5]);
139 $this->assertFalse(
true);
143 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
144 $this->assertEquals(1, $agent_status);
147 $command =
"$fossjobs_path $auth -U $upload_id -A agent_copyright,agent_mimetype,agent_nomos,agent_pkgagent -v";
148 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
149 $last = exec(
"$command 2>&1", $out, $rtn);
150 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" Waiting 300 seconds for the agents to complete\n");
152 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
153 $this->assertEquals(1, $agent_status);
155 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
156 $this->assertEquals(1, $agent_status);
158 $agent_status = check_agent_status($test_dbh,
"pkgagent", $upload_id);
159 $this->assertEquals(1, $agent_status);
161 $agent_status = check_agent_status($test_dbh,
"mimetype", $upload_id);
162 $this->assertEquals(1, $agent_status);
168 $cp2foss_command =
"$cp2foss_path -s $auth ./test_fossjobs.php -f fossjobs -d 'fossjobs testing copyright' -q agent_copyright";
169 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$cp2foss_command'\n");
170 $last = exec(
"$cp2foss_command 2>&1", $out, $rtn);
174 if ($out && $out[5]) {
175 $upload_id = get_upload_id($out[5]);
177 $this->assertFalse(
true);
182 $agent_status = check_agent_status($test_dbh,
"ununpack", $upload_id);
183 $this->assertEquals(1, $agent_status);
185 $agent_status = check_agent_status($test_dbh,
"copyright", $upload_id);
186 $this->assertEquals(1, $agent_status);
189 $command =
"$fossjobs_path $auth -U $upload_id -v -A agent_nomos";
190 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
191 $last = exec(
"$command 2>&1", $out, $rtn);
196 $agent_status = check_agent_status($test_dbh,
"nomos", $upload_id);
197 $this->assertEquals(1, $agent_status);
199 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
209 global $fossology_testconfig;
210 global $scheduler_path;
211 global $cp2foss_path;
212 global $fossjobs_path;
214 fwrite(STDOUT,
" ----> Running " . __METHOD__ .
"\n");
218 $command =
"$fossjobs_path -h -c $fossology_testconfig";
219 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
220 $last = exec(
"$command 2>&1", $out, $rtn);
221 $output_msg_count = count($out);
223 $this->assertEquals(18, $output_msg_count);
224 $auth =
"--username fossy --password fossy -c $fossology_testconfig";
228 $command =
"$fossjobs_path $auth -a ";
229 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
230 $last = exec(
"$command 2>&1", $out, $rtn);
232 $output_msg_count = count($out);
233 $this->assertEquals(10, $output_msg_count);
238 $command =
"$fossjobs_path $auth -u ";
239 fwrite(STDOUT,
"DEBUG: " . __METHOD__ .
" Line: " . __LINE__ .
" executing '$command'\n");
240 $last = exec(
"$command 2>&1", $out, $rtn);
241 fwrite(STDOUT,
"DEBUG: output was:\n");
243 $output_msg_count = count($out);
248 $this->assertEquals(3, $output_msg_count, $command);
250 fwrite(STDOUT,
"DEBUG: Done running " . __METHOD__ .
"\n");
258 global $fossology_testconfig;
260 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
270 public static function tearDownAfterClass()
273 global $fossology_testconfig;
274 global $scheduler_path;
275 fwrite(STDOUT,
"--> Running " . __METHOD__ .
" method.\n");
278 print
"Stopping the scheduler\n";
279 $scheduler_cmd =
"$scheduler_path -k -c $fossology_testconfig";
280 print
"DEBUG: command is $scheduler_cmd \n";
281 exec($scheduler_cmd, $output, $return_var);
282 if ( $return_var != 0 ) {
283 print
"Error: Could not stop scheduler via '$scheduler_cmd'\n";
291 print
"End of functional tests for cp2foss \n";
test_reschedule_agents()
schedule agents
static setUpBeforeClass()
test_list_agent_and_others()
list agents, list uploads, help msg