jenkins-bot has submitted this change and it was merged.

Change subject: Run MediaWiki unit tests via 'vagrant run-tests'
......................................................................


Run MediaWiki unit tests via 'vagrant run-tests'

This patch uses extends the MediaWiki-Vagrant's Vagrant plug-in to add a
Vagrant subcommand, 'run-tests', that executes PHPUnit tests on a running VM.

With the exception of '-h' / '--help' (which prompt Vagrant to print usage info
and then exit), all other command-line arguments are passed through to phpunit.

This patch also fixes whitespace in other ruby files.

Bug: 46676
Change-Id: I7340a306d92ed5f4bb7cfb3c0a0a7b1e7c19fa53
---
M lib/mediawiki-vagrant/commands/paste-puppet.rb
A lib/mediawiki-vagrant/commands/run-tests.rb
M lib/mediawiki-vagrant/plugin.rb
A puppet/modules/mediawiki/files/run-mediawiki-tests
M puppet/modules/mediawiki/manifests/init.pp
5 files changed, 49 insertions(+), 22 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/mediawiki-vagrant/commands/paste-puppet.rb 
b/lib/mediawiki-vagrant/commands/paste-puppet.rb
index 205d0d0..1ddaa78 100644
--- a/lib/mediawiki-vagrant/commands/paste-puppet.rb
+++ b/lib/mediawiki-vagrant/commands/paste-puppet.rb
@@ -2,29 +2,29 @@
 
 class PastePuppet < Vagrant.plugin(2, :command)
 
-       URL = URI('http://dpaste.de/api/')
+    URL = URI('http://dpaste.de/api/')
 
-       def latest_logfile
-               Dir[File.join $DIR, '/logs/puppet/*.log'].max_by { |f| 
File.mtime f }
-       end
+    def latest_logfile
+        Dir[File.join $DIR, '/logs/puppet/*.log'].max_by { |f| File.mtime f }
+    end
 
     def execute
-               begin
-                       res = Net::HTTP.post_form URL, content: 
File.read(latest_logfile)
-                       raise unless res.value.nil? and res.body =~ /^"[^"]+"$/
-               rescue RuntimeError
-                       @env.ui.error "Unexpected response from #{URL}."
-                       1
-               rescue TypeError
-                       @env.ui.error 'No Puppet log files found.'
-                       1
-               rescue SocketError, Net::HTTPExceptions
-                       @env.ui.error "Unable to connect to #{URL}."
-                       1
-               else
-                       @env.ui.success "HTTP #{res.code} #{res.msg}"
-                       @env.ui.info res.body[1...-1]
-                       0
-               end
+        begin
+            res = Net::HTTP.post_form URL, content: File.read(latest_logfile)
+            raise unless res.value.nil? and res.body =~ /^"[^"]+"$/
+        rescue RuntimeError
+            @env.ui.error "Unexpected response from #{URL}."
+            1
+        rescue TypeError
+            @env.ui.error 'No Puppet log files found.'
+            1
+        rescue SocketError, Net::HTTPExceptions
+            @env.ui.error "Unable to connect to #{URL}."
+            1
+        else
+            @env.ui.success "HTTP #{res.code} #{res.msg}"
+            @env.ui.info res.body[1...-1]
+            0
+        end
     end
 end
diff --git a/lib/mediawiki-vagrant/commands/run-tests.rb 
b/lib/mediawiki-vagrant/commands/run-tests.rb
new file mode 100644
index 0000000..79dc78f
--- /dev/null
+++ b/lib/mediawiki-vagrant/commands/run-tests.rb
@@ -0,0 +1,12 @@
+class RunTests < Vagrant.plugin(2, :command)
+    def execute
+        if ['-h', '--help'].include? @argv.first
+            @env.ui.info "Usage: vagrant run-tests [tests] [-h]"
+            return 0
+        end
+        opts = { extra_args: @argv.unshift('run-mediawiki-tests') }
+        with_target_vms(nil, :single_target => true) do |vm|
+            vm.action :ssh, ssh_opts: opts
+        end
+    end
+end
diff --git a/lib/mediawiki-vagrant/plugin.rb b/lib/mediawiki-vagrant/plugin.rb
index d3737c8..6989a97 100644
--- a/lib/mediawiki-vagrant/plugin.rb
+++ b/lib/mediawiki-vagrant/plugin.rb
@@ -1,8 +1,13 @@
 class MediaWikiVagrant < Vagrant.plugin('2')
-    name 'MediaWiki Vagrant'
+    name 'MediaWiki-Vagrant'
 
     command 'paste-puppet' do
         require 'mediawiki-vagrant/commands/paste-puppet'
         PastePuppet
     end
+
+    command 'run-tests' do
+        require 'mediawiki-vagrant/commands/run-tests'
+        RunTests
+    end
 end
diff --git a/puppet/modules/mediawiki/files/run-mediawiki-tests 
b/puppet/modules/mediawiki/files/run-mediawiki-tests
new file mode 100644
index 0000000..a246d16
--- /dev/null
+++ b/puppet/modules/mediawiki/files/run-mediawiki-tests
@@ -0,0 +1,4 @@
+#!/bin/bash
+. /etc/profile.d/puppet-managed/set_mw_install_path.sh
+cd "$MW_INSTALL_PATH"
+php tests/phpunit/phpunit.php --testdox "$@"
diff --git a/puppet/modules/mediawiki/manifests/init.pp 
b/puppet/modules/mediawiki/manifests/init.pp
index b5f1cf2..c1a8be2 100644
--- a/puppet/modules/mediawiki/manifests/init.pp
+++ b/puppet/modules/mediawiki/manifests/init.pp
@@ -126,6 +126,12 @@
         require => Exec['mediawiki setup'],
     }
 
+    file { '/usr/local/bin/run-mediawiki-tests':
+        source  => 'puppet:///modules/mediawiki/run-mediawiki-tests',
+        mode    => '0755',
+        require => Exec['configure phpunit'],
+    }
+
     exec { 'update database':
         command     => "php ${dir}/maintenance/update.php --quick",
         refreshonly => true,

-- 
To view, visit https://gerrit.wikimedia.org/r/73714
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7340a306d92ed5f4bb7cfb3c0a0a7b1e7c19fa53
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to