From 77e65871c239e2a5092bed947ae8a928f60c10b2 Mon Sep 17 00:00:00 2001 From: Roland Mas Date: Wed, 7 Nov 2012 17:33:46 +0100 Subject: [PATCH] Backport from trunk: use Loggerhead as WSGI rather than as a daemon, and testsuite for scmbzr --- src/debian/dsf-in/plugin-scmbzr.init.d | 66 ---------------- src/etc/httpd.conf.d/50-wsgi-scmbzr.conf | 3 + src/etc/httpd.conf.d/plugin-scmbzr.inc | 15 ++-- src/plugins/scmbzr/bin/install.sh | 50 ++++++++++++ .../scmbzr/packaging/control/132plugin-scmbzr | 2 +- src/plugins/scmbzr/packaging/install/plugin-scmbzr | 1 + tests/DEBDebian60Tests.php | 1 + tests/DEBDebian70Tests.php | 1 + tests/RPMCentosTests.php | 1 + tests/TarCentosTests.php | 1 + tests/func/PluginsScmBzr/bzrTest.php | 89 ++++++++++++++++++++++ 11 files changed, 157 insertions(+), 73 deletions(-) delete mode 100644 src/debian/dsf-in/plugin-scmbzr.init.d create mode 100644 src/etc/httpd.conf.d/50-wsgi-scmbzr.conf create mode 100644 src/plugins/scmbzr/bin/install.sh create mode 100644 tests/func/PluginsScmBzr/bzrTest.php diff --git a/src/debian/dsf-in/plugin-scmbzr.init.d b/src/debian/dsf-in/plugin-scmbzr.init.d deleted file mode 100644 index 9632a2e..0000000 --- a/src/debian/dsf-in/plugin-scmbzr.init.d +++ /dev/null @@ -1,66 +0,0 @@ -#! /bin/sh -### BEGIN INIT INFO -# Provides: @OLDPACKAGE@-plugin-scmbzr -# Required-Start: $local_fs $remote_fs $network -# Required-Stop: $local_fs $remote_fs $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -### END INIT INFO -# -# Init script for @OLDPACKAGE@-plugin-scmbzr Debian package. -# Based on the script provided by loggerhead. - -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -DESC="Loggerhead Bazaar Branch Browser for @FORGENAME@" -NAME=@OLDPACKAGE@-plugin-scmbzr -PIDFILE=/var/run/$NAME.pid -SCRIPTNAME=/etc/init.d/$NAME - -# Gracefully exit if the package has been removed. -[ -x /usr/bin/serve-branches ] || exit 0 - -# Check if configuration file is present -[ ! -f /etc/@OLDPACKAGE@/plugins/scmbzr/serve-branches.conf ] && exit 0 - -. /etc/@OLDPACKAGE@/plugins/scmbzr/serve-branches.conf - -# -# Function that starts the daemon/service. -# -d_start() { - start-stop-daemon -p $PIDFILE -S --startas /usr/bin/serve-branches --chuid loggerhead --make-pidfile --background --chdir $served_branches -- --prefix=$prefix --port=$port --log-folder /var/log/loggerhead 2>/dev/null -} - -# -# Function that stops the daemon/service. -# -d_stop() { - start-stop-daemon -p $PIDFILE -K -} - - -case "$1" in - start) - echo -n "Starting $DESC: $NAME" - d_start - echo "." - ;; - stop) - echo -n "Stopping $DESC: $NAME" - d_stop - echo "." - ;; - restart|force-reload) - echo -n "Restarting $DESC: $NAME" - d_stop - sleep 1 - d_start - echo "." - ;; - *) - echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/src/etc/httpd.conf.d/50-wsgi-scmbzr.conf b/src/etc/httpd.conf.d/50-wsgi-scmbzr.conf new file mode 100644 index 0000000..74eaaf6 --- /dev/null +++ b/src/etc/httpd.conf.d/50-wsgi-scmbzr.conf @@ -0,0 +1,3 @@ + + WSGIDaemonProcess fusionforge-plugin-scmbzr user=gforge group=gforge processes=4 maximum-requests=1000 display-name=fusionforge-plugin-scmbzr + diff --git a/src/etc/httpd.conf.d/plugin-scmbzr.inc b/src/etc/httpd.conf.d/plugin-scmbzr.inc index b2bc8b3..55d7433 100644 --- a/src/etc/httpd.conf.d/plugin-scmbzr.inc +++ b/src/etc/httpd.conf.d/plugin-scmbzr.inc @@ -1,8 +1,11 @@ - - Allow from all - +Alias {core/url_prefix}scm/loggerhead/static /usr/share/loggerhead/static +RewriteEngine On +RewriteRule ^{core/url_prefix}scm/loggerhead$ {core/url_prefix}scm/loggerhead/ [R] - - ProxyPass http://127.0.0.1:8081/ - ProxyPassReverse http://127.0.0.1:8081/ +WSGIScriptAlias {core/url_prefix}scm/loggerhead /usr/bin/loggerhead.wsgi + + + WSGIProcessGroup fusionforge-plugin-scmbzr + Order deny,allow + Allow from all diff --git a/src/plugins/scmbzr/bin/install.sh b/src/plugins/scmbzr/bin/install.sh new file mode 100644 index 0000000..5aef04e --- /dev/null +++ b/src/plugins/scmbzr/bin/install.sh @@ -0,0 +1,50 @@ +#! /bin/sh +# +# Configure Loggerhead for FusionForge +# Roland Mas + +set -e + +if [ `id -u` != 0 ] ; then + echo "You must be root to run this, please enter passwd" + exec su -c "$0 $1" +fi + +configfile=~gforge/.bazaar/bazaar.conf +cachedir=/var/cache/gforge/loggerhead + +case "$1" in + configure) + PATH=/usr/share/gforge/bin:/usr/share/fusionforge/bin:$PATH + repos_path=$(forge_get_config repos_path scmbzr) + web_host=$(forge_get_config web_host) + url_prefix=$(forge_get_config url_prefix) + + a2enmod wsgi + if [ ! -e $configfile ] ; then + mkdir -p $(dirname $configfile) + cat > $configfile <= 1.19~bzr477~), python-pastedeploy Provides: @PACKAGE@-plugin-scm, @OLDPACKAGE@-plugin-scmbzr Conflicts: @OLDPACKAGE@-plugin-scmbzr Replaces: @OLDPACKAGE@-plugin-scmbzr diff --git a/src/plugins/scmbzr/packaging/install/plugin-scmbzr b/src/plugins/scmbzr/packaging/install/plugin-scmbzr index c455154..5b11c98 100644 --- a/src/plugins/scmbzr/packaging/install/plugin-scmbzr +++ b/src/plugins/scmbzr/packaging/install/plugin-scmbzr @@ -1,3 +1,4 @@ +plugins/scmbzr/bin/* usr/share/gforge/scmbzr/bin/ plugins/scmbzr/common/* usr/share/gforge/plugins/scmbzr/common/ plugins/scmbzr/etc/plugins/scmbzr/* etc/gforge/plugins/scmbzr/ plugins/scmbzr/etc/*.ini etc/@PACKAGE@/config.ini.d/ diff --git a/tests/DEBDebian60Tests.php b/tests/DEBDebian60Tests.php index 943e57c..a24adec 100644 --- a/tests/DEBDebian60Tests.php +++ b/tests/DEBDebian60Tests.php @@ -30,6 +30,7 @@ class DEBDebian60Tests $suite->addTestFiles(glob("func/Forums/*Test.php")); $suite->addTestFiles(glob("func/News/*Test.php")); $suite->addTestFiles(glob("func/PluginsBlocks/*Test.php")); + $suite->addTestFiles(glob("func/PluginsScmBzr/*Test.php")); $suite->addTestFiles(glob("func/PluginsScmGit/*Test.php")); $suite->addTestFiles(glob("func/RBAC/*Test.php")); $suite->addTestFiles(glob("func/Surveys/*Test.php")); diff --git a/tests/DEBDebian70Tests.php b/tests/DEBDebian70Tests.php index 8219e10..1a52109 100644 --- a/tests/DEBDebian70Tests.php +++ b/tests/DEBDebian70Tests.php @@ -33,6 +33,7 @@ class DEBDebian60Tests $suite->addTestFiles(glob("func/PluginsMediawiki/*Test.php")); $suite->addTestFiles(glob("func/PluginsMoinMoin/*Test.php")); $suite->addTestFiles(glob("func/PluginsOnlineHelp/*Test.php")); + $suite->addTestFiles(glob("func/PluginsScmBzr/*Test.php")); $suite->addTestFiles(glob("func/PluginsScmGit/*Test.php")); // $suite->addTestFiles(glob("func/PluginsSvnTracker/*Test.php")); $suite->addTestFiles(glob("func/RBAC/*Test.php")); diff --git a/tests/RPMCentosTests.php b/tests/RPMCentosTests.php index 8e9e400..102d033 100644 --- a/tests/RPMCentosTests.php +++ b/tests/RPMCentosTests.php @@ -29,6 +29,7 @@ class RPMCentosTests // $suite->addTestFiles(glob("func/PluginsMediawiki/*Test.php")); // $suite->addTestFiles(glob("func/PluginsMoinMoin/*Test.php")); $suite->addTestFiles(glob("func/PluginsOnlineHelp/*Test.php")); +// $suite->addTestFiles(glob("func/PluginsScmBzr/*Test.php")); // $suite->addTestFiles(glob("func/PluginsScmGit/*Test.php")); // $suite->addTestFiles(glob("func/PluginsSvnTracker/*Test.php")); $suite->addTestFiles(glob("func/RBAC/*Test.php")); diff --git a/tests/TarCentosTests.php b/tests/TarCentosTests.php index 24f5918..c6622b4 100755 --- a/tests/TarCentosTests.php +++ b/tests/TarCentosTests.php @@ -29,6 +29,7 @@ class TarCentosTests // $suite->addTestFiles(glob("func/PluginsMediawiki/*Test.php")); // $suite->addTestFiles(glob("func/PluginsMoinMoin/*Test.php")); $suite->addTestFiles(glob("func/PluginsOnlineHelp/*Test.php")); +// $suite->addTestFiles(glob("func/PluginsScmBzr/*Test.php")); // $suite->addTestFiles(glob("func/PluginsScmGit/*Test.php")); // $suite->addTestFiles(glob("func/PluginsSvnTracker/*Test.php")); $suite->addTestFiles(glob("func/RBAC/*Test.php")); diff --git a/tests/func/PluginsScmBzr/bzrTest.php b/tests/func/PluginsScmBzr/bzrTest.php new file mode 100644 index 0000000..ebf89f5 --- /dev/null +++ b/tests/func/PluginsScmBzr/bzrTest.php @@ -0,0 +1,89 @@ +activatePlugin('scmbzr'); + $this->populateStandardTemplate('empty'); + $this->init(); + + $this->open(ROOT); + $this->clickAndWait("link=ProjectA"); + $this->clickAndWait("link=Admin"); + $this->clickAndWait("link=Tools"); + $this->clickAndWait("link=Source Code Admin"); + $this->click("//input[@name='scmradio' and @value='scmbzr']"); + $this->clickAndWait("submit"); + + // Run the cronjob to create repositories + $this->cron("create_scm_repos.php"); + + // Check that the repo is present and Loggerhead shows it (even if empty) + $this->open(ROOT); + $this->clickAndWait("link=ProjectA"); + $this->clickAndWait("link=SCM"); + + $this->open(ROOT.'/scm/loggerhead/'); + $this->assertTextPresent("Browsing (root)"); + $this->clickAndWait("link=projecta"); + $this->assertTextPresent("Browsing (root)/projecta"); + + // Get the address of the repo + $this->open(ROOT); + $this->clickAndWait("link=ProjectA"); + $this->clickAndWait("link=SCM"); + $p = $this->getText("//tt[contains(.,'bzr checkout bzr+ssh')]"); + $p = preg_replace(",^bzr checkout ,", "", $p); + $p = preg_replace(",://.*@,", "://root@", $p); + $p = preg_replace(",/branchname$,", "", $p); + + // Create a local branch, push it to the repo + $t = exec("mktemp -d /tmp/bzrTest.XXXXXX"); + system("cd $t && bzr init --quiet trunk >/dev/null", $ret); + $this->assertEquals($ret, 0); + + system("echo 'this is a simple text' > $t/trunk/mytext.txt"); + system("cd $t/trunk && bzr add --quiet && bzr commit -m'Adding file' --quiet", $ret); + system("echo 'another simple text' >> $t/trunk/mytext.txt"); + system("cd $t/trunk && bzr add --quiet && bzr commit -m'Modifying file' --quiet", $ret); + $this->assertEquals($ret, 0); + + system("cd $t/trunk && bzr push --quiet $p/trunk", $ret); + $this->assertEquals($ret, 0); + + $this->open(ROOT.'/scm/loggerhead/projecta'); + $this->assertTextPresent("Browsing (root)/projecta"); + $this->assertTextPresent("trunk"); + $this->clickAndWait("link=trunk"); + $this->assertTextPresent("Modifying file"); + $this->assertTextNotPresent("Adding file"); + $this->clickAndWait("link=Changes"); + $this->assertTextPresent("Modifying file"); + $this->assertTextPresent("Adding file"); + + system("rm -fr $t"); + } +} +?> -- 2.1.4