This change introduces a basic implementation to run glance-api as an application managed by httpd+mod_wsgi, instead of a standalone eventlet server. Change-Id: I9421ec891c535503ff61ad6107a1935a32b4b263changes/03/817403/21
parent
fa5fcb4ab5
commit
53eefc2d95
@ -0,0 +1,28 @@
|
||||
# == Class: glance::wsgi
|
||||
#
|
||||
# Configure wsgi options
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# [*task_pool_threads*]
|
||||
# (Optional) The number of thredas (per worker process) in the pool for
|
||||
# processing asynchronous tasks.
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
# [*python_interpreter*]
|
||||
# (Optional) Path to the python interpreter to use when spawning external
|
||||
# processes.
|
||||
# Defaults to $::os_service_default
|
||||
#
|
||||
class glance::wsgi (
|
||||
$task_pool_threads = $::os_service_default,
|
||||
$python_interpreter = $::os_service_default,
|
||||
) {
|
||||
|
||||
include glance::deps
|
||||
|
||||
glance_api_config {
|
||||
'wsgi/task_pool_threads': value => $task_pool_threads;
|
||||
'wsgi/python_interpreter': value => $python_interpreter;
|
||||
}
|
||||
}
|
@ -0,0 +1,201 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# Class to serve Glance API with apache mod_wsgi in place of glance-api service.
|
||||
#
|
||||
# When using this class you should disable your glance-api service.
|
||||
#
|
||||
# == Parameters
|
||||
#
|
||||
# [*servername*]
|
||||
# The servername for the virtualhost.
|
||||
# Optional. Defaults to $::fqdn
|
||||
#
|
||||
# [*port*]
|
||||
# The port.
|
||||
# Optional. Defaults to 9292
|
||||
#
|
||||
# [*bind_host*]
|
||||
# The host/ip address Apache will listen on.
|
||||
# Optional. Defaults to undef (listen on all ip addresses).
|
||||
#
|
||||
# [*path*]
|
||||
# The prefix for the endpoint.
|
||||
# Optional. Defaults to '/'
|
||||
#
|
||||
# [*ssl*]
|
||||
# Use ssl ? (boolean)
|
||||
# Optional. Defaults to true
|
||||
#
|
||||
# [*workers*]
|
||||
# Number of WSGI workers to spawn.
|
||||
# Optional. Defaults to $::os_workers
|
||||
#
|
||||
# [*priority*]
|
||||
# (optional) The priority for the vhost.
|
||||
# Defaults to '10'
|
||||
#
|
||||
# [*threads*]
|
||||
# (optional) The number of threads for the vhost.
|
||||
# Defaults to 1
|
||||
#
|
||||
# [*wsgi_process_display_name*]
|
||||
# (optional) Name of the WSGI process display-name.
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*ssl_cert*]
|
||||
# [*ssl_key*]
|
||||
# [*ssl_chain*]
|
||||
# [*ssl_ca*]
|
||||
# [*ssl_crl_path*]
|
||||
# [*ssl_crl*]
|
||||
# [*ssl_certs_dir*]
|
||||
# apache::vhost ssl parameters.
|
||||
# Optional. Default to apache::vhost 'ssl_*' defaults.
|
||||
#
|
||||
# [*access_log_file*]
|
||||
# The log file name for the virtualhost.
|
||||
# Optional. Defaults to false.
|
||||
#
|
||||
# [*access_log_pipe*]
|
||||
# Specifies a pipe where Apache sends access logs for the virtualhost.
|
||||
# Optional. Defaults to false.
|
||||
#
|
||||
# [*access_log_syslog*]
|
||||
# Sends the virtualhost access log messages to syslog.
|
||||
# Optional. Defaults to false.
|
||||
#
|
||||
# [*access_log_format*]
|
||||
# The log format for the virtualhost.
|
||||
# Optional. Defaults to false.
|
||||
#
|
||||
# [*error_log_file*]
|
||||
# The error log file name for the virtualhost.
|
||||
# Optional. Defaults to undef.
|
||||
#
|
||||
# [*error_log_pipe*]
|
||||
# Specifies a pipe where Apache sends error logs for the virtualhost.
|
||||
# Optional. Defaults to undef.
|
||||
#
|
||||
# [*error_log_syslog*]
|
||||
# Sends the virtualhost error log messages to syslog.
|
||||
# Optional. Defaults to undef.
|
||||
#
|
||||
# [*custom_wsgi_process_options*]
|
||||
# (optional) gives you the opportunity to add custom process options or to
|
||||
# overwrite the default options for the WSGI main process.
|
||||
# eg. to use a virtual python environment for the WSGI process
|
||||
# you could set it to:
|
||||
# { python-path => '/my/python/virtualenv' }
|
||||
# Defaults to {}
|
||||
#
|
||||
# [*headers*]
|
||||
# (optional) Headers for the vhost.
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*request_headers*]
|
||||
# (optional) Modifies collected request headers in various ways.
|
||||
# Defaults to undef
|
||||
#
|
||||
# [*vhost_custom_fragment*]
|
||||
# (optional) Passes a string of custom configuration
|
||||
# directives to be placed at the end of the vhost configuration.
|
||||
# Defaults to undef.
|
||||
#
|
||||
# == Dependencies
|
||||
#
|
||||
# requires Class['apache'] & Class['glance']
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# include apache
|
||||
#
|
||||
# class { 'glance::wsgi::apache': }
|
||||
#
|
||||
class glance::wsgi::apache (
|
||||
$servername = $::fqdn,
|
||||
$port = 9292,
|
||||
$bind_host = undef,
|
||||
$path = '/',
|
||||
$ssl = false,
|
||||
$workers = $::os_workers,
|
||||
$ssl_cert = undef,
|
||||
$ssl_key = undef,
|
||||
$ssl_chain = undef,
|
||||
$ssl_ca = undef,
|
||||
$ssl_crl_path = undef,
|
||||
$ssl_crl = undef,
|
||||
$ssl_certs_dir = undef,
|
||||
$wsgi_process_display_name = undef,
|
||||
$threads = 1,
|
||||
$priority = '10',
|
||||
$access_log_file = false,
|
||||
$access_log_pipe = false,
|
||||
$access_log_syslog = false,
|
||||
$access_log_format = false,
|
||||
$error_log_file = undef,
|
||||
$error_log_pipe = undef,
|
||||
$error_log_syslog = undef,
|
||||
$custom_wsgi_process_options = {},
|
||||
$headers = undef,
|
||||
$request_headers = undef,
|
||||
$vhost_custom_fragment = undef,
|
||||
) {
|
||||
|
||||
include glance::deps
|
||||
include glance::params
|
||||
include apache
|
||||
include apache::mod::wsgi
|
||||
if $ssl {
|
||||
include apache::mod::ssl
|
||||
}
|
||||
|
||||
::openstacklib::wsgi::apache { 'glance_wsgi':
|
||||
bind_host => $bind_host,
|
||||
bind_port => $port,
|
||||
group => 'glance',
|
||||
path => $path,
|
||||
priority => $priority,
|
||||
servername => $servername,
|
||||
ssl => $ssl,
|
||||
ssl_ca => $ssl_ca,
|
||||
ssl_cert => $ssl_cert,
|
||||
ssl_certs_dir => $ssl_certs_dir,
|
||||
ssl_chain => $ssl_chain,
|
||||
ssl_crl => $ssl_crl,
|
||||
ssl_crl_path => $ssl_crl_path,
|
||||
ssl_key => $ssl_key,
|
||||
threads => $threads,
|
||||
user => 'glance',
|
||||
vhost_custom_fragment => $vhost_custom_fragment,
|
||||
workers => $workers,
|
||||
wsgi_chunked_request => 'On',
|
||||
wsgi_daemon_process => 'glance-api',
|
||||
wsgi_process_display_name => $wsgi_process_display_name,
|
||||
wsgi_process_group => 'glance-api',
|
||||
wsgi_script_dir => $::glance::params::glance_wsgi_script_path,
|
||||
wsgi_script_file => 'glance-api',
|
||||
wsgi_script_source => $::glance::params::glance_wsgi_script_source,
|
||||
custom_wsgi_process_options => $custom_wsgi_process_options,
|
||||
headers => $headers,
|
||||
request_headers => $request_headers,
|
||||
access_log_file => $access_log_file,
|
||||
access_log_pipe => $access_log_pipe,
|
||||
access_log_syslog => $access_log_syslog,
|
||||
access_log_format => $access_log_format,
|
||||
error_log_file => $error_log_file,
|
||||
error_log_pipe => $error_log_pipe,
|
||||
error_log_syslog => $error_log_syslog,
|
||||
require => Anchor['glance::install::end'],
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The new ``glance::wsgi`` class, to manage parameters in the ``[wsgi]``
|
||||
section, has been added.
|
||||
|
||||
- |
|
||||
Added support for running the ``glance-api`` service by httpd and mod_wsgi.
|
@ -0,0 +1,184 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'glance::wsgi::apache' do
|
||||
shared_examples 'apache serving glance with mod_wsgi' do
|
||||
context 'with default parameters' do
|
||||
it { is_expected.to contain_class('glance::params') }
|
||||
it { is_expected.to contain_class('apache') }
|
||||
it { is_expected.to contain_class('apache::mod::wsgi') }
|
||||
it { is_expected.to_not contain_class('apache::mod::ssl') }
|
||||
it { is_expected.to contain_openstacklib__wsgi__apache('glance_wsgi').with(
|
||||
:bind_port => 9292,
|
||||
:group => 'glance',
|
||||
:path => '/',
|
||||
:servername => facts[:fqdn],
|
||||
:ssl => false,
|
||||
:threads => 1,
|
||||
:user => 'glance',
|
||||
:workers => facts[:os_workers],
|
||||
:wsgi_chunked_request => 'On',
|
||||
:wsgi_daemon_process => 'glance-api',
|
||||
:wsgi_process_group => 'glance-api',
|
||||
:wsgi_script_dir => platform_params[:wsgi_script_path],
|
||||
:wsgi_script_file => 'glance-api',
|
||||
:wsgi_script_source => platform_params[:wsgi_script_source],
|
||||
:headers => nil,
|
||||
:request_headers => nil,
|
||||
:custom_wsgi_process_options => {},
|
||||
:access_log_file => false,
|
||||
:access_log_pipe => false,
|
||||
:access_log_syslog => false,
|
||||
:access_log_format => false,
|
||||
:error_log_file => nil,
|
||||
:error_log_pipe => nil,
|
||||
:error_log_syslog => nil,
|
||||
)}
|
||||
end
|
||||
|
||||
context'when overriding parameters using different ports' do
|
||||
let :params do
|
||||
{
|
||||
:servername => 'dummy.host',
|
||||
:bind_host => '10.42.51.1',
|
||||
:port => 12345,
|
||||
:ssl => true,
|
||||
:vhost_custom_fragment => 'Timeout 99',
|
||||
:wsgi_process_display_name => 'glance-api',
|
||||
:workers => 37,
|
||||
:custom_wsgi_process_options => {
|
||||
'python_path' => '/my/python/admin/path',
|
||||
},
|
||||
:headers => ['set X-XSS-Protection "1; mode=block"'],
|
||||
:request_headers => ['set Content-Type "application/json"'],
|
||||
}
|
||||
end
|
||||
it { is_expected.to contain_class('glance::params') }
|
||||
it { is_expected.to contain_class('apache') }
|
||||
it { is_expected.to contain_class('apache::mod::wsgi') }
|
||||
it { is_expected.to contain_class('apache::mod::ssl') }
|
||||
it { is_expected.to contain_openstacklib__wsgi__apache('glance_wsgi').with(
|
||||
:bind_host => '10.42.51.1',
|
||||
:bind_port => 12345,
|
||||
:group => 'glance',
|
||||
:path => '/',
|
||||
:servername => 'dummy.host',
|
||||
:ssl => true,
|
||||
:threads => 1,
|
||||
:user => 'glance',
|
||||
:vhost_custom_fragment => 'Timeout 99',
|
||||
:workers => 37,
|
||||
:wsgi_chunked_request => 'On',
|
||||
:wsgi_daemon_process => 'glance-api',
|
||||
:wsgi_process_display_name => 'glance-api',
|
||||
:wsgi_process_group => 'glance-api',
|
||||
:wsgi_script_dir => platform_params[:wsgi_script_path],
|
||||
:wsgi_script_file => 'glance-api',
|
||||
:wsgi_script_source => platform_params[:wsgi_script_source],
|
||||
:headers => ['set X-XSS-Protection "1; mode=block"'],
|
||||
:request_headers => ['set Content-Type "application/json"'],
|
||||
:custom_wsgi_process_options => {
|
||||
'python_path' => '/my/python/admin/path',
|
||||
},
|
||||
)}
|
||||
end
|
||||
|
||||
context 'with custom access logging' do
|
||||
let :params do
|
||||
{
|
||||
:access_log_format => 'foo',
|
||||
:access_log_syslog => 'syslog:local0',
|
||||
:error_log_syslog => 'syslog:local1',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_openstacklib__wsgi__apache('glance_wsgi').with(
|
||||
:access_log_format => params[:access_log_format],
|
||||
:access_log_syslog => params[:access_log_syslog],
|
||||
:error_log_syslog => params[:error_log_syslog],
|
||||
)}
|
||||
end
|
||||
|
||||
context 'with access_log_file' do
|
||||
let :params do
|
||||
{
|
||||
:access_log_file => '/path/to/file',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_openstacklib__wsgi__apache('glance_wsgi').with(
|
||||
:access_log_file => params[:access_log_file],
|
||||
)}
|
||||
end
|
||||
|
||||
context 'with access_log_pipe' do
|
||||
let :params do
|
||||
{
|
||||
:access_log_pipe => 'pipe',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_openstacklib__wsgi__apache('glance_wsgi').with(
|
||||
:access_log_pipe => params[:access_log_pipe],
|
||||
)}
|
||||
end
|
||||
|
||||
context 'with error_log_file' do
|
||||
let :params do
|
||||
{
|
||||
:error_log_file => '/path/to/file',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_openstacklib__wsgi__apache('glance_wsgi').with(
|
||||
:error_log_file => params[:error_log_file],
|
||||
)}
|
||||
end
|
||||
|
||||
context 'with error_log_pipe' do
|
||||
let :params do
|
||||
{
|
||||
:error_log_pipe => 'pipe',
|
||||
}
|
||||
end
|
||||
|
||||
it { should contain_openstacklib__wsgi__apache('glance_wsgi').with(
|
||||
:error_log_pipe => params[:error_log_pipe],
|
||||
)}
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge!(OSDefaults.get_facts({
|
||||
:os_workers => 42,
|
||||
:concat_basedir => '/var/lib/puppet/concat',
|
||||
:fqdn => 'some.host.tld',
|
||||
}))
|
||||
end
|
||||
|
||||
let(:platform_params) do
|
||||
case facts[:osfamily]
|
||||
when 'Debian'
|
||||
{
|
||||
:httpd_service_name => 'apache2',
|
||||
:httpd_ports_file => '/etc/apache2/ports.conf',
|
||||
:wsgi_script_path => '/usr/lib/cgi-bin/glance',
|
||||
:wsgi_script_source => '/usr/bin/glance-wsgi-api'
|
||||
}
|
||||
when 'RedHat'
|
||||
{
|
||||
:httpd_service_name => 'httpd',
|
||||
:httpd_ports_file => '/etc/httpd/conf/ports.conf',
|
||||
:wsgi_script_path => '/var/www/cgi-bin/glance',
|
||||
:wsgi_script_source => '/usr/bin/glance-wsgi-api'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like 'apache serving glance with mod_wsgi'
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,38 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'glance::wsgi' do
|
||||
shared_examples 'glance::wsgi' do
|
||||
context 'with default parameters' do
|
||||
it 'configures the default values' do
|
||||
is_expected.to contain_glance_api_config('wsgi/task_pool_threads').with_value('<SERVICE DEFAULT>')
|
||||
is_expected.to contain_glance_api_config('wsgi/python_interpreter').with_value('<SERVICE DEFAULT>')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with specified parameters' do
|
||||
let :params do
|
||||
{
|
||||
:task_pool_threads => 16,
|
||||
:python_interpreter => '/usr/bin/python3'
|
||||
}
|
||||
end
|
||||
|
||||
it 'configures the default values' do
|
||||
is_expected.to contain_glance_api_config('wsgi/task_pool_threads').with_value(16)
|
||||
is_expected.to contain_glance_api_config('wsgi/python_interpreter').with_value('/usr/bin/python3')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
on_supported_os({
|
||||
:supported_os => OSDefaults.get_supported_os
|
||||
}).each do |os,facts|
|
||||
context "on #{os}" do
|
||||
let (:facts) do
|
||||
facts.merge(OSDefaults.get_facts())
|
||||
end
|
||||
|
||||
it_behaves_like 'glance::wsgi'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue