r106345 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106344‎ | r106345 | r106346 >
Date:17:43, 15 December 2011
Author:hashar
Status:ok
Tags:
Comment:
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 (modified) (history)
  • /trunk/tools/testswarm/scripts/fetcher-sample.ini (added) (history)
  • /trunk/tools/testswarm/scripts/testswarm-mw-fetcher-run.php (modified) (history)
  • /trunk/tools/testswarm/scripts/testswarm-mw-fetcher.php (modified) (history)

Diff [purge]

Index: trunk/tools/testswarm/scripts/testswarm-mw-fetcher-run.php
@@ -51,6 +51,7 @@
5252 'debug' => false,
5353 'root' => '/var/lib/testswarm/mediawiki-trunk',
5454 'svnUrl' => 'http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3',
 55+ 'testPattern' => '/checkouts/mw/trunk/r$1/tests/qunit/?filter=$2',
5556 'minRev' => 105305,
5657 );
5758 break;
@@ -63,4 +64,18 @@
6465 require_once( __DIR__ . '/testswarm-mw-fetcher.php' );
6566
6667 $main = new TestSwarmMWMain( $options );
67 -$main->tryFetchNextRev();
 68+$rev = $main->tryFetchNextRev();
 69+
 70+if( $rev === false ) {
 71+ print "No new revision, nothing left to do. Exiting.\n";
 72+ exit;
 73+}
 74+
 75+$fetcher_conf = parse_ini_file( "/etc/testswarm/fetcher.ini", true );
 76+$api = new TestSwarmAPI(
 77+ $main
 78+ , $fetcher_conf['TestSwarmAPI']['username']
 79+ , $fetcher_conf['TestSwarmAPI']['authtoken']
 80+ , $fetcher_conf['TestSwarmAPI']['url']
 81+);
 82+$api->doAddJob( $rev );
Index: trunk/tools/testswarm/scripts/fetcher-sample.ini
@@ -0,0 +1,28 @@
 2+; Configuration MediaWiki testswarm fetcher
 3+;
 4+; This file is read by the testswarm-mw-fetcher-run.php script to
 5+; authenticate itself on your TestSwarm installation.
 6+; It must be available as /etc/testswarm/fetcher.ini
 7+;
 8+; You will have to manually create a username using your local TestSwarm
 9+; installation web interface. Upon user creation, TestSwarm generates an
 10+; authentication token which can be used by scripts without revealing
 11+; the user password.
 12+;
 13+[TestSwarmAPI]
 14+
 15+; Username on testswarm used for submitting job
 16+username = "MediaWiki"
 17+
 18+; The token is 32 hexadecimals characters and need to be fetched from
 19+; the database manually:
 20+;
 21+; mysql -p -u testswarm testswarm
 22+; mysql> SELECT auth FROM users WHERE name='MediaWiki' \G
 23+; *************************** 1. row ***************************
 24+; auth: 1234567890123456789012345678912345678912
 25+; 1 row in set (0.00 sec)
 26+authtoken = ""
 27+
 28+; URL for your TestSwarm repository
 29+url = "http://localhost/testswarm/"
Index: trunk/tools/testswarm/scripts/testswarm-mw-fetcher.php
@@ -54,12 +54,15 @@
5555 /** Path to log file */
5656 protected $logPath;
5757
 58+ /** URL pattern to add one test. $1 is rev, $2 testname */
 59+ protected $testPattern = "/checkouts/mw/trunk/r$1/tests/qunit/?filter=$2";
5860
5961 /** GETTERS **/
6062
6163 public function getSvnCmd() { return $this->svnCmd; }
6264 public function getSvnUrl() { return $this->svnUrl; }
6365 public function getLogPath() { return $this->logPath; }
 66+ public function getTestPattern() { return $this->testPattern; }
6467
6568
6669 /** SETTERS **/
@@ -114,6 +117,10 @@
115118 $this->minRev = $options['minRev'];
116119 }
117120
 121+ if ( isset( $options['testPattern'] ) ) {
 122+ $this->testPattern = $options['testPattern'];
 123+ }
 124+
118125 return $this;
119126 }
120127
@@ -124,19 +131,23 @@
125132 public function tryFetchNextRev() {
126133 $this->prepareRootDirs();
127134
 135+ $result = false;
128136 // Now find out the next revision in the remote repository
129 - $next = $this->getNextCheckoutRevId();
130 - if ( !$next ) {
 137+ $nextRev = $this->getNextCheckoutRevId();
 138+ if ( !$nextRev ) {
131139 $this->debug( 'No next revision', __METHOD__ );
132 - return false;
133140 } else {
134141 // And install it
135 - $fetcher = new TestSwarmMWFetcher( &$this, $next );
136 - return $fetcher->run();
 142+ $fetcher = new TestSwarmMWFetcher( &$this, $nextRev );
 143+ $result = $fetcher->run();
 144+ if( $result === true ) {
 145+ return $nextRev;
 146+ }
137147 }
 148+
 149+ return $result;
138150 }
139151
140 -
141152 /** SVN REVISION HELPERS **/
142153
143154 /**
@@ -214,8 +225,6 @@
215226 } else {
216227 $next = $this->getNextFollowingRevId( $cur );
217228 }
218 -
219 - $this->debug( __METHOD__ . ": Going to use r{$next}" );
220229 return $next;
221230 }
222231
@@ -247,8 +256,8 @@
248257 * @return Array of paths relevant for an install.
249258 */
250259 public function getPathsForRev( $id ) {
251 - if ( !is_int( $id ) ) {
252 - throw new Exception( __METHOD__ . ': Given non numerical revision' );
 260+ if ( !is_numeric( $id ) ) {
 261+ throw new Exception( __METHOD__ . ": Given non numerical revision " . var_export($id, true) );
253262 }
254263
255264 return array(
@@ -296,7 +305,6 @@
297306 * @param $path String Path to create ex: /tmp/my/foo/bar
298307 */
299308 public function mkdir( $path ) {
300 - $this->debug( "Attempting to create directory '$path'...", __METHOD__ );
301309 if ( !file_exists( $path ) ) {
302310 if ( @mkdir( $path, 0777, true ) ) {
303311 $this->debug( "Created directory '$path'", __METHOD__ );
@@ -304,8 +312,6 @@
305313 print "Could not create directory '$path'. Exiting.\n";
306314 exit(1);
307315 }
308 - } else {
309 - $this->debug( "Creating directory '$path' aborted. Directory already exist", __METHOD__ );
310316 }
311317 }
312318
@@ -387,8 +393,8 @@
388394 $this->main->log( "Run for r{$this->svnRevId} started", __METHOD__ );
389395
390396 $this->doCheckout();
391 - $this->doInstall();
392 - $this->doAppendSettings();
 397+ #$this->doInstall();
 398+ #$this->doAppendSettings();
393399
394400 /**
395401 * @todo FIXME:
@@ -396,6 +402,7 @@
397403 * - Make POST request to TestSwarm install to add jobs for these test runs
398404 * (CURL addjob.php with login/auth token)
399405 */
 406+ return true;
400407 }
401408
402409 /**
@@ -501,3 +508,94 @@
502509 return true;
503510 }
504511 }
 512+
 513+class TestSwarmAPI {
 514+ public $URL;
 515+ private $user;
 516+ private $authToken;
 517+
 518+ /**
 519+ * Initialize a testswarm instance
 520+ * @param $user String A testswarm username
 521+ * @param $authtoken String associated user authentication token
 522+ * @param $URL String URL to the testswarm instance. Default:
 523+ * http://localhost/testswarm
 524+ */
 525+ public function __construct( TestSwarmMWMain $context, $user, $authtoken,
 526+ $URL = 'http://localhost/testswarm'
 527+ ) {
 528+ $this->context = $context;
 529+ $this->URL = $URL;
 530+ $this->user = $user;
 531+ $this->authToken = $authtoken;
 532+
 533+ // FIXME check user auth before continuing.
 534+ }
 535+
 536+ /**
 537+ * Add a job to the Testswarm instance
 538+ * FIXME: lot of hardcoded options there 8-)
 539+ */
 540+ public function doAddJob( $revision ) {
 541+ $params = array(
 542+ "state" => "addjob",
 543+ "output" => "dump",
 544+ "user" => $this->user,
 545+ "auth" => $this->authToken,
 546+ "max" => 3,
 547+ "job_name" => "MediaWiki trunk r{$revision}",
 548+ "browsers" => "popularbetamobile",
 549+ );
 550+ $query = http_build_query( $params );
 551+
 552+ $localPaths = $this->context->getPathsForRev( $revision );
 553+
 554+ $filenames = array_map( 'basename',
 555+ glob( $localPaths['mw'] . "/tests/qunit/suites/resources/*/*.js" )
 556+ );
 557+
 558+ # Append each of our test file to the job query submission
 559+ foreach( $filenames as $filename) {
 560+ if ( substr( $filename, -8 ) === '.test.js' ) {
 561+ $suiteName = substr( $filename, 0, -8 );
 562+ $pattern = $this->context->getTestPattern();
 563+
 564+ $testUrl = str_replace( array( '$1', '$2' ),
 565+ array( rawurlencode($revision), rawurlencode($suiteName) ),
 566+ $pattern
 567+ );
 568+ $query .=
 569+ "&suites[]=" . rawurlencode( $suiteName ) .
 570+ "&urls[]=" . $testUrl."\n";
 571+ }
 572+ }
 573+
 574+ //print "Testswarm base URL: {$this->URL}\n";
 575+ //print "Queries: $query\n";
 576+
 577+ # Forge curl request and submit it
 578+ $ch = curl_init();
 579+ curl_setopt_array( $ch, array(
 580+ CURLOPT_RETURNTRANSFER => 1
 581+ , CURLOPT_USERAGENT => "TestSwarm-fetcher (ContInt; hashar)"
 582+ , CURLOPT_SSL_VERIFYHOST => FALSE
 583+ , CURLOPT_SSL_VERIFYPEER => FALSE
 584+ , CURLOPT_POST => TRUE
 585+ , CURLOPT_URL => $this->URL
 586+ , CURLOPT_POSTFIELDS => $query
 587+ ));
 588+ $ret = curl_exec( $ch );
 589+ $err = curl_errno( $ch );
 590+ $error = curl_error( $ch );
 591+
 592+ if( !$ret ) {
 593+ $this->context->log(
 594+ "Curl returned an error: #$err, $error\n"
 595+ );
 596+ return false;
 597+ }
 598+
 599+ $this->context->log( $ret );
 600+ return true;
 601+ }
 602+}
Property changes on: trunk/tools/testswarm/scripts
___________________________________________________________________
Added: svn:ignore
505603 + fetcher.ini

Status & tagging log