diff --git a/manifests/api.pp b/manifests/api.pp index 66d71d38b..9bcb67937 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -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, @@ -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, @@ -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 { diff --git a/manifests/params.pp b/manifests/params.pp index 524c2f902..a1923230b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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: \ diff --git a/spec/acceptance/ceilometer_wsgi_apache_spec.rb b/spec/acceptance/ceilometer_wsgi_apache_spec.rb new file mode 100644 index 000000000..d731de218 --- /dev/null +++ b/spec/acceptance/ceilometer_wsgi_apache_spec.rb @@ -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:keystone@127.0.0.1/keystone', + admin_token => 'admin_token', + enabled => true, + } + class { '::keystone::roles::admin': + email => 'test@example.tld', + 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:a_big_secret@127.0.0.1/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 diff --git a/spec/classes/ceilometer_api_spec.rb b/spec/classes/ceilometer_api_spec.rb index e54eea1a9..6ada5b8be 100644 --- a/spec/classes/ceilometer_api_spec.rb +++ b/spec/classes/ceilometer_api_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/classes/ceilometer_wsgi_apache_spec.rb b/spec/classes/ceilometer_wsgi_apache_spec.rb index b7c689900..ad4c07654 100644 --- a/spec/classes/ceilometer_wsgi_apache_spec.rb +++ b/spec/classes/ceilometer_wsgi_apache_spec.rb @@ -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