Skip to content

Commit

Permalink
WSGI: make it work, and test it with acceptance
Browse files Browse the repository at this point in the history
* Finalize httpd service name support in API class following
  puppet-keystone model.
* Implement unit tests.
* Implement separated acceptance tests that deploy Ceilometer API in
  WSGI.

This patch aims to finalize and validate we can deploy Ceilometer API in
WSGI with puppet-ceilometer.
Also that we can update from eventlet to WSGI (it's tested in our beaker jobs).

Closes-bug: #1481532
Change-Id: I3695acf5522457837e079c36d68a0e35dbf6b72c
(cherry picked from commit 257a60ce79f00f96239d06d84c9660f14a31bd68)
  • Loading branch information
EmilienM committed Aug 14, 2015
1 parent 1394f5e commit 05926aa
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 19 deletions.
52 changes: 38 additions & 14 deletions manifests/api.pp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
# (optional) ensure state for package.
# Defaults to 'present'
#
# [*service_name*]
# (optional) Name of the service that will be providing the
# server functionality of ceilometer-api.
# If the value is 'httpd', this means ceilometer-api will be a web
# service, and you must use another class to configure that
# web service. For example, use class { 'ceilometer::wsgi::apache'...}
# to make keystone be a web app using apache mod_wsgi.
# Defaults to '$::ceilometer::params::api_service_name'
#
class ceilometer::api (
$manage_service = true,
$enabled = true,
Expand All @@ -75,23 +84,24 @@
$keystone_identity_uri = false,
$host = '0.0.0.0',
$port = '8777',
$service_name = $::ceilometer::params::api_service_name,
# DEPRECATED PARAMETERS
$keystone_host = '127.0.0.1',
$keystone_port = '35357',
$keystone_auth_admin_prefix = false,
$keystone_protocol = 'http',
) {
) inherits ceilometer::params {

include ::ceilometer::params
include ::ceilometer::policy

validate_string($keystone_password)

Ceilometer_config<||> ~> Service['ceilometer-api']
Class['ceilometer::policy'] ~> Service['ceilometer-api']
Ceilometer_config<||> ~> Service[$service_name]
Class['ceilometer::policy'] ~> Service[$service_name]

Package['ceilometer-api'] -> Ceilometer_config<||>
Package['ceilometer-api'] -> Service['ceilometer-api']
Package['ceilometer-api'] -> Service[$service_name]
Package['ceilometer-api'] -> Class['ceilometer::policy']
package { 'ceilometer-api':
ensure => $package_ensure,
Expand All @@ -106,16 +116,30 @@
$service_ensure = 'stopped'
}
}

Package['ceilometer-common'] -> Service['ceilometer-api']
service { 'ceilometer-api':
ensure => $service_ensure,
name => $::ceilometer::params::api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
require => Class['ceilometer::db'],
subscribe => Exec['ceilometer-dbsync']
Package['ceilometer-common'] -> Service[$service_name]

if $service_name == $::ceilometer::params::api_service_name {
service { 'ceilometer-api':
ensure => $service_ensure,
name => $::ceilometer::params::api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
require => Class['ceilometer::db'],
subscribe => Exec['ceilometer-dbsync'],
tag => 'ceilometer-service',
}
} elsif $service_name == 'httpd' {
include ::apache::params
service { 'ceilometer-api':
ensure => 'stopped',
name => $::ceilometer::params::api_service_name,
enable => false,
tag => 'ceilometer-service',
}
Class['ceilometer::db'] -> Service[$service_name]
} else {
fail('Invalid service_name. Either keystone/openstack-ceilometer-api for running as a standalone service, or httpd for being run by a httpd server')
}

ceilometer_config {
Expand Down
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}
}
$ceilometer_wsgi_script_path = '/usr/lib/cgi-bin/ceilometer'
$ceilometer_wsgi_script_source = '/usr/share/ceilometer/app.wsgi'
$ceilometer_wsgi_script_source = '/usr/lib/python2.7/dist-packages/ceilometer/api/app.wsgi'
}
default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem: \
Expand Down
133 changes: 133 additions & 0 deletions spec/acceptance/ceilometer_wsgi_apache_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
require 'spec_helper_acceptance'

describe 'ceilometer with mysql' do

context 'default parameters' do

it 'should work with no errors' do
pp= <<-EOS
Exec { logoutput => 'on_failure' }
# Common resources
case $::osfamily {
'Debian': {
include ::apt
class { '::openstack_extras::repo::debian::ubuntu':
release => 'kilo',
package_require => true,
}
$package_provider = 'apt'
}
'RedHat': {
class { '::openstack_extras::repo::redhat::redhat':
release => 'kilo',
}
package { 'openstack-selinux': ensure => 'latest' }
$package_provider = 'yum'
}
default: {
fail("Unsupported osfamily (${::osfamily})")
}
}
class { '::mysql::server': }
class { '::rabbitmq':
delete_guest_user => true,
package_provider => $package_provider,
}
rabbitmq_vhost { '/':
provider => 'rabbitmqctl',
require => Class['rabbitmq'],
}
rabbitmq_user { 'ceilometer':
admin => true,
password => 'an_even_bigger_secret',
provider => 'rabbitmqctl',
require => Class['rabbitmq'],
}
rabbitmq_user_permissions { 'ceilometer@/':
configure_permission => '.*',
write_permission => '.*',
read_permission => '.*',
provider => 'rabbitmqctl',
require => Class['rabbitmq'],
}
# Keystone resources, needed by Ceilometer to run
class { '::keystone::db::mysql':
password => 'keystone',
}
class { '::keystone':
verbose => true,
debug => true,
database_connection => 'mysql://keystone:[email protected]/keystone',
admin_token => 'admin_token',
enabled => true,
}
class { '::keystone::roles::admin':
email => '[email protected]',
password => 'a_big_secret',
}
class { '::keystone::endpoint':
public_url => "https://${::fqdn}:5000/",
admin_url => "https://${::fqdn}:35357/",
}
# Ceilometer resources
class { '::ceilometer':
metering_secret => 'secrete',
rabbit_userid => 'ceilometer',
rabbit_password => 'an_even_bigger_secret',
rabbit_host => '127.0.0.1',
}
# Until https://review.openstack.org/177593 is merged:
Package<| title == 'python-mysqldb' |> -> Class['ceilometer::db']
class { '::ceilometer::db::mysql':
password => 'a_big_secret',
}
class { '::ceilometer::db':
database_connection => 'mysql://ceilometer:[email protected]/ceilometer?charset=utf8',
}
class { '::ceilometer::keystone::auth':
password => 'a_big_secret',
}
class { '::ceilometer::client': }
class { '::ceilometer::collector': }
class { '::ceilometer::expirer': }
class { '::ceilometer::alarm::evaluator': }
class { '::ceilometer::alarm::notifier': }
class { '::ceilometer::agent::central': }
class { '::ceilometer::agent::notification': }
class { '::ceilometer::api':
enabled => true,
keystone_password => 'a_big_secret',
keystone_identity_uri => 'http://127.0.0.1:35357/',
service_name => 'httpd',
}
include ::apache
class { '::ceilometer::wsgi::apache':
ssl => false,
}
EOS


# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe port(8777) do
it { is_expected.to be_listening }
end

describe cron do
it { is_expected.to have_entry('1 0 * * * ceilometer-expirer').with_user('ceilometer') }
end

end
end
52 changes: 49 additions & 3 deletions spec/classes/ceilometer_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
describe 'ceilometer::api' do

let :pre_condition do
"class { 'ceilometer': metering_secret => 's3cr3t' }"
"class { 'ceilometer': metering_secret => 's3cr3t' }
include ::ceilometer::db"
end

let :params do
Expand Down Expand Up @@ -113,11 +114,51 @@
)
end
end

context 'when running ceilometer-api in wsgi' do
before do
params.merge!({ :service_name => 'httpd' })
end

let :pre_condition do
"include ::apache
include ::ceilometer::db
class { 'ceilometer': metering_secret => 's3cr3t' }"
end

it 'configures ceilometer-api service with Apache' do
is_expected.to contain_service('ceilometer-api').with(
:ensure => 'stopped',
:name => platform_params[:api_service_name],
:enable => false,
:tag => 'ceilometer-service',
)
end
end

context 'when service_name is not valid' do
before do
params.merge!({ :service_name => 'foobar' })
end

let :pre_condition do
"include ::apache
include ::ceilometer::db
class { 'ceilometer': metering_secret => 's3cr3t' }"
end

it_raises 'a Puppet::Error', /Invalid service_name/
end
end

context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
{ :osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '8.0',
:concat_basedir => '/var/lib/puppet/concat',
:fqdn => 'some.host.tld',
:processorcount => 2 }
end

let :platform_params do
Expand All @@ -130,7 +171,12 @@

context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
{ :osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '7.1',
:fqdn => 'some.host.tld',
:concat_basedir => '/var/lib/puppet/concat',
:processorcount => 2 }
end

let :platform_params do
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/ceilometer_wsgi_apache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
:httpd_service_name => 'apache2',
:httpd_ports_file => '/etc/apache2/ports.conf',
:wsgi_script_path => '/usr/lib/cgi-bin/ceilometer',
:wsgi_script_source => '/usr/share/ceilometer/app.wsgi'
:wsgi_script_source => '/usr/lib/python2.7/dist-packages/ceilometer/api/app.wsgi'
}
end

Expand Down

0 comments on commit 05926aa

Please sign in to comment.