Mark Bergsma has submitted this change and it was merged.

Change subject: contint::localvhost easily setup an apache listener
......................................................................


contint::localvhost easily setup an apache listener

This generalized the QUnit vhost listening on localhost.  To run browser
tests, I would need as well a vhost listening on localhost and pointing
to some document root.

I simply converted the existing Apache conf for QUnit to be a template,
the class contint::localvhost let us fill the placeholders.

The QUnit vhost has been migrated to use the new class.

Apache 'Listen' statements are under /etc/apache2/conf.d/

bug: 54385
Change-Id: I3e17c2ab82fbbab5be654f48ca55cca98070ba40
---
D modules/contint/files/apache/qunit.localhost
A modules/contint/manifests/localvhost.pp
M modules/contint/manifests/website.pp
A modules/contint/templates/apache/listen.erb
A modules/contint/templates/apache/localvhost.erb
5 files changed, 93 insertions(+), 42 deletions(-)

Approvals:
  Mark Bergsma: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/contint/files/apache/qunit.localhost 
b/modules/contint/files/apache/qunit.localhost
deleted file mode 100644
index 344201e..0000000
--- a/modules/contint/files/apache/qunit.localhost
+++ /dev/null
@@ -1,33 +0,0 @@
-#####################################################################
-### THIS FILE IS MANAGED BY PUPPET
-### puppet:///modules/contint/apache/qunit.localhost
-#####################################################################
-# vim: filetype=apache
-
-# We would prefer not having external requests
-Listen 127.0.0.1:9412
-Listen [::1]:9412
-
-<VirtualHost *:9412>
-       ServerName localhost
-       DocumentRoot /srv/localhost/qunit
-
-       <Directory />
-               Order deny,allow
-               Deny from all
-       </Directory>
-
-       <Directory /srv/localhost/qunit>
-               Options +Indexes
-               Options FollowSymLinks
-
-               Order deny,allow
-               Deny from all
-               Allow from 127.0.0.1/32
-               Allow from ::1/128
-       </Directory>
-
-       LogLevel warn
-       ErrorLog /var/log/apache2/qunit_error.log
-       CustomLog /var/log/apache2/qunit_access.log vhost_combined
-</VirtualHost>
diff --git a/modules/contint/manifests/localvhost.pp 
b/modules/contint/manifests/localvhost.pp
new file mode 100644
index 0000000..0f3160b
--- /dev/null
+++ b/modules/contint/manifests/localvhost.pp
@@ -0,0 +1,42 @@
+# == Class contint::localvhost
+#
+# Craft an apache configuration file to listen on localhost:$port (default to
+# port 9412) and point that vhost to $docroot (default to
+# /srv/localhost${name}).
+#
+# The $name is by default used as a prefix for the Apache logs. You can
+# override it using $log_prefix.
+#
+# == Example:
+#
+# contint::localvhost { 'qunit:' }
+#
+# Creates a vhost listening on 127.0.0.1:9412 having a DocumentRoot at
+# /srv/localhost/qunit.
+#
+class contint::localvhost(
+    $docroot = "/srv/localhost/${name}",
+    $port = 9412,
+    $log_prefix = $name,
+){
+
+    file { "/etc/apache2/sites-available/${name}.localhost":
+        mode    => '0444',
+        owner   => 'root',
+        group   => 'root',
+        content => template('contint/apache/localvhost.erb'),
+    }
+
+    $apache_listens = [
+        { 'ip' => '127.0.0.1', 'port' => $port, 'proto' => 'http', },
+        { 'ip' => '[::1]',     'port' => $port, 'proto' => 'http', },
+    ]
+    file { "/etc/apache2/conf.d/listen-localhost-${port}":
+        content => template('contint/apache/listen.erb'),
+    }
+
+    apache_site { "${name} localhost":
+        name => "${name}.localhost"
+    }
+
+}
diff --git a/modules/contint/manifests/website.pp 
b/modules/contint/manifests/website.pp
index 00bce89..2184910 100644
--- a/modules/contint/manifests/website.pp
+++ b/modules/contint/manifests/website.pp
@@ -97,15 +97,11 @@
     group  => 'jenkins-slave',
   }
 
-  # Apache configuration for a virtual host on localhost
-  file { '/etc/apache2/sites-available/qunit.localhost':
-    mode   => '0444',
-    owner  => 'root',
-    group  => 'root',
-    source => 'puppet:///modules/contint/apache/qunit.localhost',
-  }
-  apache_site { 'qunit localhost':
-    name => 'qunit.localhost'
+  contint::localvhost { 'qunit':
+    port       => 9412,
+    docroot    => '/srv/localhost/qunit',
+    log_prefix => 'qunit',
+    require    => File['/srv/localhost/qunit'],
   }
 
 }
diff --git a/modules/contint/templates/apache/listen.erb 
b/modules/contint/templates/apache/listen.erb
new file mode 100644
index 0000000..af917a9
--- /dev/null
+++ b/modules/contint/templates/apache/listen.erb
@@ -0,0 +1,18 @@
+#####################################################################
+#### THIS FILE IS MANAGED BY PUPPET
+#### puppet:///modules/contint/apache/listen.erb
+######################################################################
+
+# Ports Apache is listening to in addition to the default ports:
+<%
+# Apache Listen format is:
+# Listen [IP-address:]portnumber [protocol]
+@apache_listens.sort.each do |l|
+       # Tweak ip and proto to match Apache format
+       ip = l.fetch('ip', '')
+       ip += ':' if ip != ''
+       proto = l.fetch('protocol', '')
+       proto = ' ' + proto if proto != ''
+-%>
+       Listen <%= ip -%><%= l.fetch('port') -%><%= proto -%>
+<% end -%>
diff --git a/modules/contint/templates/apache/localvhost.erb 
b/modules/contint/templates/apache/localvhost.erb
new file mode 100644
index 0000000..bc9510b
--- /dev/null
+++ b/modules/contint/templates/apache/localvhost.erb
@@ -0,0 +1,28 @@
+#####################################################################
+### THIS FILE IS MANAGED BY PUPPET
+### puppet:///modules/contint/apache/localvhost.erb
+#####################################################################
+
+<VirtualHost *:<%= @port %>>
+       ServerName localhost
+       DocumentRoot <%= @docroot %>
+
+       <Directory />
+               Order deny,allow
+               Deny from all
+       </Directory>
+
+       <Directory <%= @docroot %>>
+               Options +Indexes
+               Options FollowSymLinks
+
+               Order deny,allow
+               Deny from all
+               Allow from 127.0.0.1/32
+               Allow from ::1/128
+       </Directory>
+
+       LogLevel warn
+       ErrorLog /var/log/apache2/<%= @log_prefix %>_error.log
+       CustomLog /var/log/apache2/<%= @log_prefix %>_access.log vhost_combined
+</VirtualHost>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3e17c2ab82fbbab5be654f48ca55cca98070ba40
Gerrit-PatchSet: 3
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Hashar <has...@free.fr>
Gerrit-Reviewer: Hashar <has...@free.fr>
Gerrit-Reviewer: Mark Bergsma <m...@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