From 92a036cfda05f4613cfdb27b8ce06808304ced55 Mon Sep 17 00:00:00 2001 From: Mark Dechiaro Date: Mon, 11 Feb 2019 16:12:08 -0600 Subject: [PATCH] Fix wsgi_daemon_process to support hash data type The README states wsgi_daemon_process is a hash data type however the ERB template interpolates it as a string. As this type it currently cannot accept multiple daemon processes per vhost, and requires wsgi_daemon_process_options to manage parameters. This commit adds logic to the parameter to support this data type while maintaining original functionality. The data type allows for multiple daemons per vhost, and deprecates wsgi_daemon_process_options. --- README.md | 24 ++++++++++++++---------- manifests/vhost.pp | 5 ++++- spec/acceptance/vhost_spec.rb | 7 ++++--- spec/defines/vhost_spec.rb | 4 ++-- templates/vhost/_wsgi.erb | 12 ++++++++++-- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5c02b2a345..9f64f1f202 100755 --- a/README.md +++ b/README.md @@ -561,11 +561,13 @@ apache::vhost { 'wsgi.example.com': port => '80', docroot => '/var/www/pythonapp', wsgi_application_group => '%{GLOBAL}', - wsgi_daemon_process => 'wsgi', - wsgi_daemon_process_options => { - processes => '2', - threads => '15', - display-name => '%{GROUP}', + wsgi_daemon_process => { + 'wsgi' => { + processes => '2', + threads => '15', + display-name => '%{GROUP}', + }, + 'foo' => {}, }, wsgi_import_script => '/var/www/demo.wsgi', wsgi_import_script_options => { @@ -4853,7 +4855,7 @@ apache::vhost { 'subdomain.loc': Sets up a virtual host with [WSGI](https://github.com/GrahamDumpleton/mod_wsgi). * `wsgi_daemon_process`: A hash that sets the name of the WSGI daemon, accepting [certain keys](http://modwsgi.readthedocs.org/en/latest/configuration-directives/WSGIDaemonProcess.html). Default: `undef`. -* `wsgi_daemon_process_options`. _Optional._ Default: `undef`. +* `wsgi_daemon_process_options`. _Optional._ Default: `undef`. **Deprecated:** Please add values inside Hash `wsgi_daemon_process`. * `wsgi_process_group`: Sets the group ID that the virtual host runs under. Default: `undef`. * `wsgi_script_aliases`: Requires a hash of web paths to filesystem .wsgi paths. Default: `undef`. * `wsgi_script_aliases_match`: Requires a hash of web path regexes to filesystem .wsgi paths. Default: `undef` @@ -4866,12 +4868,14 @@ An example virtual host configuration with WSGI: apache::vhost { 'wsgi.example.com': port => '80', docroot => '/var/www/pythonapp', - wsgi_daemon_process => 'wsgi', - wsgi_daemon_process_options => - { processes => '2', + wsgi_daemon_process => { + 'wsgi' => { + processes => '2', threads => '15', display-name => '%{GROUP}', - }, + }, + 'foo' => {}, + }, wsgi_process_group => 'wsgi', wsgi_script_aliases => { '/' => '/var/www/demo.wsgi' }, wsgi_chunked_request => 'On', diff --git a/manifests/vhost.pp b/manifests/vhost.pp index e2630f10a6..6a77e764de 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -114,7 +114,7 @@ $block = [], Enum['absent', 'present'] $ensure = 'present', $wsgi_application_group = undef, - $wsgi_daemon_process = undef, + Optional[Variant[String,Hash]] $wsgi_daemon_process = undef, Optional[Hash] $wsgi_daemon_process_options = undef, $wsgi_import_script = undef, Optional[Hash] $wsgi_import_script_options = undef, @@ -933,6 +933,9 @@ # - $wsgi_process_group # - $wsgi_script_aliases # - $wsgi_pass_authorization + if $wsgi_daemon_process_options { + deprecation('apache::vhost::wsgi_daemon_process_options', 'This parameter is deprecated. Please add values inside Hash `wsgi_daemon_process`.') + } if $wsgi_application_group or $wsgi_daemon_process or ($wsgi_import_script and $wsgi_import_script_options) or $wsgi_process_group or ($wsgi_script_aliases and ! empty($wsgi_script_aliases)) or $wsgi_pass_authorization { concat::fragment { "${name}-wsgi": target => "${priority_real}${filename}.conf", diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index d587ba1d7b..434c59df43 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -1510,7 +1510,7 @@ class { 'apache::mod::wsgi': } apache::vhost { 'test.server': docroot => '/tmp', wsgi_application_group => '%{GLOBAL}', - wsgi_daemon_process => 'wsgi', + wsgi_daemon_process => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} }, wsgi_daemon_process_options => {processes => '2'}, wsgi_process_group => 'nobody', wsgi_script_aliases => { '/test' => '/test1' }, @@ -1531,7 +1531,7 @@ class { 'apache::mod::wsgi': } apache::vhost { 'test.server': docroot => '/tmp', wsgi_application_group => '%{GLOBAL}', - wsgi_daemon_process => 'wsgi', + wsgi_daemon_process => { 'wsgi' => { 'python-home' => '/usr' }, 'foo' => {} }, wsgi_daemon_process_options => {processes => '2'}, wsgi_import_script => '/test1', wsgi_import_script_options => { application-group => '%{GLOBAL}', process-group => 'wsgi' }, @@ -1549,7 +1549,8 @@ class { 'apache::mod::wsgi': } describe file("#{$vhost_dir}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'WSGIApplicationGroup %{GLOBAL}' } - it { is_expected.to contain 'WSGIDaemonProcess wsgi processes=2' } + it { is_expected.to contain 'WSGIDaemonProcess foo' } + it { is_expected.to contain 'WSGIDaemonProcess wsgi python-home=/usr' } it { is_expected.to contain 'WSGIImportScript /test1 application-group=%{GLOBAL} process-group=wsgi' } it { is_expected.to contain 'WSGIProcessGroup nobody' } it { is_expected.to contain 'WSGIScriptAlias /test "/test1"' } diff --git a/spec/defines/vhost_spec.rb b/spec/defines/vhost_spec.rb index 92796656f0..dcefbd1ba0 100644 --- a/spec/defines/vhost_spec.rb +++ b/spec/defines/vhost_spec.rb @@ -320,7 +320,7 @@ 'setenvifnocase' => 'REMOTE_ADDR ^127.0.0.1 localhost=true', 'block' => 'scm', 'wsgi_application_group' => '%{GLOBAL}', - 'wsgi_daemon_process' => 'wsgi', + 'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} }, 'wsgi_daemon_process_options' => { 'processes' => '2', 'threads' => '15', @@ -1691,7 +1691,7 @@ let :params do { 'docroot' => '/rspec/docroot', - 'wsgi_daemon_process' => 'wsgi', + 'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} }, } end diff --git a/templates/vhost/_wsgi.erb b/templates/vhost/_wsgi.erb index 72d40ff59c..fdc8141700 100644 --- a/templates/vhost/_wsgi.erb +++ b/templates/vhost/_wsgi.erb @@ -5,10 +5,18 @@ <% if @wsgi_application_group -%> WSGIApplicationGroup <%= @wsgi_application_group %> <% end -%> -<% if @wsgi_daemon_process and @wsgi_daemon_process_options -%> +<% if @wsgi_daemon_process.is_a? String and @wsgi_daemon_process_options -%> WSGIDaemonProcess <%= @wsgi_daemon_process %> <%= @wsgi_daemon_process_options.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %> -<% elsif @wsgi_daemon_process and !@wsgi_daemon_process_options -%> +<% elsif @wsgi_daemon_process.is_a? String and !@wsgi_daemon_process_options -%> WSGIDaemonProcess <%= @wsgi_daemon_process %> +<% elsif @wsgi_daemon_process.is_a? Hash -%> + <%- @wsgi_daemon_process.each do |key, val| -%> + <%- if val.empty? -%> + WSGIDaemonProcess <%= key %> + <%- else -%> + WSGIDaemonProcess <%= key %> <%= val.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %> +<% end -%> +<% end -%> <% end -%> <% if @wsgi_import_script and @wsgi_import_script_options -%> WSGIImportScript <%= @wsgi_import_script %> <%= @wsgi_import_script_options.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %>