https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106345
Revision: 106345
Author: hashar
Date: 2011-12-15 17:43:34 +0000 (Thu, 15 Dec 2011)
Log Message:
-----------
fix up testswarm fetcher
* Add job to TestSwarm
* now use an ini file for partial configuration
-> /etc/testswarm/fetcher.ini
* Remove missleading or superflous debug messages
Still need to fix up the SQLite file rights which actually deny
Apache from accessing the db.
Modified Paths:
--------------
trunk/tools/testswarm/scripts/testswarm-mw-fetcher-run.php
trunk/tools/testswarm/scripts/testswarm-mw-fetcher.php
Added Paths:
-----------
trunk/tools/testswarm/scripts/fetcher-sample.ini
Property Changed:
----------------
trunk/tools/testswarm/scripts/
Property changes on: trunk/tools/testswarm/scripts
___________________________________________________________________
Added: svn:ignore
+ fetcher.ini
Added: trunk/tools/testswarm/scripts/fetcher-sample.ini
===================================================================
--- trunk/tools/testswarm/scripts/fetcher-sample.ini
(rev 0)
+++ trunk/tools/testswarm/scripts/fetcher-sample.ini 2011-12-15 17:43:34 UTC
(rev 106345)
@@ -0,0 +1,28 @@
+; Configuration MediaWiki testswarm fetcher
+;
+; This file is read by the testswarm-mw-fetcher-run.php script to
+; authenticate itself on your TestSwarm installation.
+; It must be available as /etc/testswarm/fetcher.ini
+;
+; You will have to manually create a username using your local TestSwarm
+; installation web interface. Upon user creation, TestSwarm generates an
+; authentication token which can be used by scripts without revealing
+; the user password.
+;
+[TestSwarmAPI]
+
+; Username on testswarm used for submitting job
+username = "MediaWiki"
+
+; The token is 32 hexadecimals characters and need to be fetched from
+; the database manually:
+;
+; mysql -p -u testswarm testswarm
+; mysql> SELECT auth FROM users WHERE name='MediaWiki' \G
+; *************************** 1. row ***************************
+; auth: 1234567890123456789012345678912345678912
+; 1 row in set (0.00 sec)
+authtoken = ""
+
+; URL for your TestSwarm repository
+url = "http://localhost/testswarm/"
Modified: trunk/tools/testswarm/scripts/testswarm-mw-fetcher-run.php
===================================================================
--- trunk/tools/testswarm/scripts/testswarm-mw-fetcher-run.php 2011-12-15
17:33:28 UTC (rev 106344)
+++ trunk/tools/testswarm/scripts/testswarm-mw-fetcher-run.php 2011-12-15
17:43:34 UTC (rev 106345)
@@ -51,6 +51,7 @@
'debug' => false,
'root' => '/var/lib/testswarm/mediawiki-trunk',
'svnUrl' =>
'http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3',
+ 'testPattern' =>
'/checkouts/mw/trunk/r$1/tests/qunit/?filter=$2',
'minRev' => 105305,
);
break;
@@ -63,4 +64,18 @@
require_once( __DIR__ . '/testswarm-mw-fetcher.php' );
$main = new TestSwarmMWMain( $options );
-$main->tryFetchNextRev();
+$rev = $main->tryFetchNextRev();
+
+if( $rev === false ) {
+ print "No new revision, nothing left to do. Exiting.\n";
+ exit;
+}
+
+$fetcher_conf = parse_ini_file( "/etc/testswarm/fetcher.ini", true );
+$api = new TestSwarmAPI(
+ $main
+ , $fetcher_conf['TestSwarmAPI']['username']
+ , $fetcher_conf['TestSwarmAPI']['authtoken']
+ , $fetcher_conf['TestSwarmAPI']['url']
+);
+$api->doAddJob( $rev );
Modified: trunk/tools/testswarm/scripts/testswarm-mw-fetcher.php
===================================================================
--- trunk/tools/testswarm/scripts/testswarm-mw-fetcher.php 2011-12-15
17:33:28 UTC (rev 106344)
+++ trunk/tools/testswarm/scripts/testswarm-mw-fetcher.php 2011-12-15
17:43:34 UTC (rev 106345)
@@ -54,12 +54,15 @@
/** Path to log file */
protected $logPath;
+ /** URL pattern to add one test. $1 is rev, $2 testname */
+ protected $testPattern =
"/checkouts/mw/trunk/r$1/tests/qunit/?filter=$2";
/** GETTERS **/
public function getSvnCmd() { return $this->svnCmd; }
public function getSvnUrl() { return $this->svnUrl; }
public function getLogPath() { return $this->logPath; }
+ public function getTestPattern() { return $this->testPattern; }
/** SETTERS **/
@@ -114,6 +117,10 @@
$this->minRev = $options['minRev'];
}
+ if ( isset( $options['testPattern'] ) ) {
+ $this->testPattern = $options['testPattern'];
+ }
+
return $this;
}
@@ -124,19 +131,23 @@
public function tryFetchNextRev() {
$this->prepareRootDirs();
+ $result = false;
// Now find out the next revision in the remote repository
- $next = $this->getNextCheckoutRevId();
- if ( !$next ) {
+ $nextRev = $this->getNextCheckoutRevId();
+ if ( !$nextRev ) {
$this->debug( 'No next revision', __METHOD__ );
- return false;
} else {
// And install it
- $fetcher = new TestSwarmMWFetcher( &$this, $next );
- return $fetcher->run();
+ $fetcher = new TestSwarmMWFetcher( &$this, $nextRev );
+ $result = $fetcher->run();
+ if( $result === true ) {
+ return $nextRev;
+ }
}
+
+ return $result;
}
-
/** SVN REVISION HELPERS **/
/**
@@ -214,8 +225,6 @@
} else {
$next = $this->getNextFollowingRevId( $cur );
}
-
- $this->debug( __METHOD__ . ": Going to use r{$next}" );
return $next;
}
@@ -247,8 +256,8 @@
* @return Array of paths relevant for an install.
*/
public function getPathsForRev( $id ) {
- if ( !is_int( $id ) ) {
- throw new Exception( __METHOD__ . ': Given non
numerical revision' );
+ if ( !is_numeric( $id ) ) {
+ throw new Exception( __METHOD__ . ": Given non
numerical revision " . var_export($id, true) );
}
return array(
@@ -296,7 +305,6 @@
* @param $path String Path to create ex: /tmp/my/foo/bar
*/
public function mkdir( $path ) {
- $this->debug( "Attempting to create directory '$path'...",
__METHOD__ );
if ( !file_exists( $path ) ) {
if ( @mkdir( $path, 0777, true ) ) {
$this->debug( "Created directory '$path'",
__METHOD__ );
@@ -304,8 +312,6 @@
print "Could not create directory '$path'.
Exiting.\n";
exit(1);
}
- } else {
- $this->debug( "Creating directory '$path' aborted.
Directory already exist", __METHOD__ );
}
}
@@ -387,8 +393,8 @@
$this->main->log( "Run for r{$this->svnRevId} started",
__METHOD__ );
$this->doCheckout();
- $this->doInstall();
- $this->doAppendSettings();
+ #$this->doInstall();
+ #$this->doAppendSettings();
/**
* @todo FIXME:
@@ -396,6 +402,7 @@
* - Make POST request to TestSwarm install to add jobs for
these test runs
* (CURL addjob.php with login/auth token)
*/
+ return true;
}
/**
@@ -501,3 +508,94 @@
return true;
}
}
+
+class TestSwarmAPI {
+ public $URL;
+ private $user;
+ private $authToken;
+
+ /**
+ * Initialize a testswarm instance
+ * @param $user String A testswarm username
+ * @param $authtoken String associated user authentication token
+ * @param $URL String URL to the testswarm instance. Default:
+ * http://localhost/testswarm
+ */
+ public function __construct( TestSwarmMWMain $context, $user,
$authtoken,
+ $URL = 'http://localhost/testswarm'
+ ) {
+ $this->context = $context;
+ $this->URL = $URL;
+ $this->user = $user;
+ $this->authToken = $authtoken;
+
+ // FIXME check user auth before continuing.
+ }
+
+ /**
+ * Add a job to the Testswarm instance
+ * FIXME: lot of hardcoded options there 8-)
+ */
+ public function doAddJob( $revision ) {
+ $params = array(
+ "state" => "addjob",
+ "output" => "dump",
+ "user" => $this->user,
+ "auth" => $this->authToken,
+ "max" => 3,
+ "job_name" => "MediaWiki trunk r{$revision}",
+ "browsers" => "popularbetamobile",
+ );
+ $query = http_build_query( $params );
+
+ $localPaths = $this->context->getPathsForRev( $revision );
+
+ $filenames = array_map( 'basename',
+ glob( $localPaths['mw'] .
"/tests/qunit/suites/resources/*/*.js" )
+ );
+
+ # Append each of our test file to the job query submission
+ foreach( $filenames as $filename) {
+ if ( substr( $filename, -8 ) === '.test.js' ) {
+ $suiteName = substr( $filename, 0, -8 );
+ $pattern = $this->context->getTestPattern();
+
+ $testUrl = str_replace( array( '$1', '$2' ),
+ array( rawurlencode($revision),
rawurlencode($suiteName) ),
+ $pattern
+ );
+ $query .=
+ "&suites[]=" . rawurlencode( $suiteName ) .
+ "&urls[]=" . $testUrl."\n";
+ }
+ }
+
+ //print "Testswarm base URL: {$this->URL}\n";
+ //print "Queries: $query\n";
+
+ # Forge curl request and submit it
+ $ch = curl_init();
+ curl_setopt_array( $ch, array(
+ CURLOPT_RETURNTRANSFER => 1
+ , CURLOPT_USERAGENT => "TestSwarm-fetcher (ContInt;
hashar)"
+ , CURLOPT_SSL_VERIFYHOST => FALSE
+ , CURLOPT_SSL_VERIFYPEER => FALSE
+ , CURLOPT_POST => TRUE
+ , CURLOPT_URL => $this->URL
+ , CURLOPT_POSTFIELDS => $query
+ ));
+ $ret = curl_exec( $ch );
+ $err = curl_errno( $ch );
+ $error = curl_error( $ch );
+
+ if( !$ret ) {
+ $this->context->log(
+ "Curl returned an error: #$err, $error\n"
+ );
+ return false;
+ }
+
+ $this->context->log( $ret );
+ return true;
+ }
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs