public static function setUpBeforeClass() { global $fossology_testconfig; global $scheduler_path; global $cp2foss_path; global $PG_CONN; $fossology_testconfig = getenv('FOSSOLOGY_TESTCONFIG'); /** set default config dir as /etc/fossology/ */ if (empty($fossology_testconfig)) { $fossology_testconfig = "/usr/local/etc/fossology/"; } fwrite(STDOUT, __METHOD__ . " got fossology_testconfig = '{$fossology_testconfig}'\n"); $cp2foss_path = "cp2foss"; /* locate the scheduler binary */ $scheduler_path = $fossology_testconfig . "/mods-enabled/scheduler/agent/fo_scheduler"; if (!is_executable($scheduler_path)) { print "Error: Scheduler path '{$scheduler_path}' is not executable!\n"; exit(1); } /* invoke the scheduler */ $scheduler_cmd = "{$scheduler_path} --daemon --reset --verbose=952 -c {$fossology_testconfig}"; print "DEBUG: Starting scheduler with '{$scheduler_cmd}'\n"; exec($scheduler_cmd, $output, $return_var); //print_r($output); if ($return_var != 0) { print "Error: Could not start scheduler '{$scheduler_path}'\n"; print "{$output}\n"; exit(1); } $PG_CONN = connect_to_DB($fossology_testconfig); // connect db add_user("fossy", "fossy"); // add account fossy/fossy print "\nStarting functional test for cp2foss. \n"; }
/** * \brief upload from url */ function test_upload_from_url() { //global $SYSCONF_DIR; global $fossology_testconfig; global $cp2foss_path; fwrite(STDOUT, " ----> Running " . __METHOD__ . "\n"); $test_dbh = connect_to_DB($fossology_testconfig); $auth = "--username fossy --password fossy -c {$fossology_testconfig}"; /** upload a file to Software Repository */ $out = ""; $pos = 0; $command = "{$cp2foss_path} {$auth} http://www.fossology.org/testdata/rpms/fedora/10/SRPMS/fossology-1.1.0-1.fc10.src.rpm -d 'fossology des' -f 'fossology path' -n 'test package'"; fwrite(STDOUT, "DEBUG: Executing '{$command}'\n"); $last = exec("{$command} 2>&1", $out, $rtn); sleep(50); //print "DEBUG: output is:\n"; //print_r($out); $upload_id = 0; /** get upload id that you just upload for testing */ if ($out && $out[5]) { $upload_id = get_upload_id($out[5]); } else { $this->assertFalse(TRUE); } $agent_status = 0; $agent_status = check_agent_status($test_dbh, "ununpack", $upload_id); $this->assertEquals(1, $agent_status); $agent_status = 0; /** do not schedule nomos */ $agent_status = check_agent_status($test_dbh, "nomos", $upload_id); $this->assertEquals(0, $agent_status); pg_close($test_dbh); fwrite(STDOUT, "DEBUG: Done running " . __METHOD__ . "\n"); }
/** * \brief schedule agents */ function test_reschedule_agents() { global $fossology_testconfig; global $scheduler_path; global $cp2foss_path; global $fossjobs_path; fwrite(STDOUT, " ----> Running " . __METHOD__ . "\n"); $test_dbh = connect_to_DB($fossology_testconfig); $out = ""; /** 1. upload one dir, no any agents except wget/unpack/adj2nest */ $auth = "--username fossy --password fossy -c {$fossology_testconfig}"; $cp2foss_command = "{$cp2foss_path} -s {$auth} ./ -f fossjobs -d 'fossjobs testing'"; // print "cp2foss_command is:$cp2foss_command\n"; fwrite(STDOUT, "DEBUG: " . __METHOD__ . " Line: " . __LINE__ . " executing '{$cp2foss_command}'\n"); $last = exec("{$cp2foss_command} 2>&1", $out, $rtn); //print_r($out); $upload_id = 0; /** get upload id that you just upload for testing */ if ($out && $out[5]) { $upload_id = get_upload_id($out[5]); } else { $this->assertFalse(TRUE); } $agent_status = 0; $agent_status = check_agent_status($test_dbh, "ununpack", $upload_id); $this->assertEquals(1, $agent_status); /** reschedule all rest of agent */ $command = "{$fossjobs_path} {$auth} -U {$upload_id} -A agent_copyright,agent_mimetype,agent_nomos,agent_pkgagent -v"; fwrite(STDOUT, "DEBUG: " . __METHOD__ . " Line: " . __LINE__ . " executing '{$command}'\n"); $last = exec("{$command} 2>&1", $out, $rtn); fwrite(STDOUT, "DEBUG: " . __METHOD__ . " Line: " . __LINE__ . " Waiting 300 seconds for the agents to complete\n"); sleep(300); //wait for the agents complete $agent_status = 0; $agent_status = check_agent_status($test_dbh, "nomos", $upload_id); $this->assertEquals(1, $agent_status); $agent_status = 0; $agent_status = check_agent_status($test_dbh, "copyright", $upload_id); $this->assertEquals(1, $agent_status); $agent_status = 0; $agent_status = check_agent_status($test_dbh, "pkgagent", $upload_id); $this->assertEquals(1, $agent_status); $agent_status = 0; $agent_status = check_agent_status($test_dbh, "mimetype", $upload_id); $this->assertEquals(1, $agent_status); $agent_status = 0; $out = ""; /** 2. upload one file, schedule copyright except wget/unpack/adj2nest */ $cp2foss_command = "{$cp2foss_path} -s {$auth} ./test_fossjobs.php -f fossjobs -d 'fossjobs testing copyright' -q agent_copyright"; fwrite(STDOUT, "DEBUG: " . __METHOD__ . " Line: " . __LINE__ . " executing '{$cp2foss_command}'\n"); $last = exec("{$cp2foss_command} 2>&1", $out, $rtn); //print_r($out); $upload_id = 0; /** get upload id that you just upload for testing */ if ($out && $out[5]) { $upload_id = get_upload_id($out[5]); } else { $this->assertFalse(TRUE); } sleep(5); //wait for the agents complete $agent_status = 0; $agent_status = check_agent_status($test_dbh, "ununpack", $upload_id); $this->assertEquals(1, $agent_status); $agent_status = 0; $agent_status = check_agent_status($test_dbh, "copyright", $upload_id); $this->assertEquals(1, $agent_status); /** reschedule just nomos */ $command = "{$fossjobs_path} {$auth} -U {$upload_id} -v -A agent_nomos"; fwrite(STDOUT, "DEBUG: " . __METHOD__ . " Line: " . __LINE__ . " executing '{$command}'\n"); $last = exec("{$command} 2>&1", $out, $rtn); //print_r($out); sleep(5); //wait for the agents complete $agent_status = 0; $agent_status = check_agent_status($test_dbh, "nomos", $upload_id); $this->assertEquals(1, $agent_status); fwrite(STDOUT, "DEBUG: Done running " . __METHOD__ . "\n"); }
/** * \brief populate test data via upload from url */ function upload_from_url() { //global $SYSCONF_DIR; global $fossology_testconfig; global $fo_cli_path; global $cp2foss_path; $test_dbh = connect_to_DB($fossology_testconfig); //$auth = "--user fossy --password fossy -c $SYSCONF_DIR"; $auth = "--user fossy --password fossy -c {$fossology_testconfig}"; /** upload a file to Software Repository */ $out = ""; $pos = 0; $command = "{$cp2foss_path} {$auth} http://www.fossology.org/rpms/fedora/10/i386/fossology-devel-1.1.0-1.fc10.i386.rpm -d 'fossology des' -f 'fossology path' -n 'test package' -q 'all'"; fwrite(STDOUT, "DEBUG: Executing '{$command}'\n"); $last = exec("{$command} 2>&1", $out, $rtn); /** wait for all the scheduled agents complete */ sleep(100); $upload_id = 0; /** get upload id that you just upload for testing */ if ($out && $out[5]) { $upload_id = get_upload_id($out[5]); } else { $this->assertFalse(TRUE); } $agent_status = 0; $agent_status = check_agent_status($test_dbh, "ununpack", $upload_id); $this->assertEquals(1, $agent_status); $uploadtree_id = get_uploadtree_id($test_dbh, $upload_id); // get uploadtree id pg_close($test_dbh); fwrite(STDOUT, "DEBUG: upload_id is:{$upload_id}\n"); return array($upload_id, $uploadtree_id); }