2016-06-15 08:36:25 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'watcher::api' do
|
|
|
|
|
|
|
|
let :params do
|
2022-09-04 17:04:50 +09:00
|
|
|
{
|
|
|
|
:enabled => true,
|
|
|
|
:package_ensure => 'latest',
|
2016-06-28 14:41:47 +00:00
|
|
|
}
|
2016-06-15 08:36:25 +00:00
|
|
|
end
|
|
|
|
|
2022-09-04 17:04:50 +09:00
|
|
|
let :pre_condition do
|
|
|
|
"include watcher::db
|
|
|
|
class { 'watcher': }
|
|
|
|
class { 'watcher::keystone::authtoken':
|
|
|
|
password => 'a_big_secret',
|
|
|
|
}"
|
|
|
|
end
|
2016-06-15 08:36:25 +00:00
|
|
|
|
2022-09-04 17:04:50 +09:00
|
|
|
shared_examples 'watcher-api' do
|
2016-06-15 08:36:25 +00:00
|
|
|
|
2016-06-28 14:41:47 +00:00
|
|
|
it { is_expected.to contain_class('watcher::params') }
|
2016-12-01 17:54:42 +08:00
|
|
|
it { is_expected.to contain_class('watcher::deps') }
|
2016-06-28 14:41:47 +00:00
|
|
|
|
|
|
|
it 'installs watcher-api package' do
|
|
|
|
is_expected.to contain_package('watcher-api').with(
|
|
|
|
:ensure => 'latest',
|
|
|
|
:name => platform_params[:api_package_name],
|
|
|
|
:tag => ['openstack', 'watcher-package'],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
[{:enabled => true}, {:enabled => false}].each do |param_hash|
|
|
|
|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
|
|
|
|
before do
|
|
|
|
params.merge!(param_hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'configures watcher-api service' do
|
|
|
|
is_expected.to contain_service('watcher-api').with(
|
2022-02-10 16:43:05 +09:00
|
|
|
:ensure => params[:enabled] ? 'running' : 'stopped',
|
2016-06-28 14:41:47 +00:00
|
|
|
:name => platform_params[:api_service_name],
|
|
|
|
:enable => params[:enabled],
|
|
|
|
:hasstatus => true,
|
|
|
|
:hasrestart => true,
|
2016-07-03 17:38:21 +00:00
|
|
|
:tag => ['watcher-service',
|
|
|
|
'watcher-db-manage-create_schema',
|
|
|
|
'watcher-db-manage-upgrade'],
|
2016-06-28 14:41:47 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2016-06-15 08:36:25 +00:00
|
|
|
end
|
|
|
|
|
2016-10-13 17:22:21 -06:00
|
|
|
context 'with default api configuration' do
|
|
|
|
it 'should configure the api configurations section when enabled' do
|
2022-08-15 02:18:04 +09:00
|
|
|
is_expected.to contain_watcher_config('api/port').with_value('<SERVICE DEFAULT>')
|
2016-10-13 17:22:21 -06:00
|
|
|
is_expected.to contain_watcher_config('api/max_limit').with_value('<SERVICE DEFAULT>')
|
2022-08-15 02:15:10 +09:00
|
|
|
is_expected.to contain_watcher_config('api/host').with_value('<SERVICE DEFAULT>')
|
2016-10-13 17:22:21 -06:00
|
|
|
is_expected.to contain_watcher_config('api/workers').with_value(2)
|
2016-11-06 20:25:18 +00:00
|
|
|
is_expected.to contain_watcher_config('api/enable_ssl_api').with_value('<SERVICE DEFAULT>')
|
2016-10-13 17:22:21 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-28 14:41:47 +00:00
|
|
|
context 'with disabled service managing' do
|
|
|
|
before do
|
|
|
|
params.merge!({
|
|
|
|
:manage_service => false,
|
2022-02-10 16:43:05 +09:00
|
|
|
})
|
2016-06-28 14:41:47 +00:00
|
|
|
end
|
|
|
|
|
2022-02-10 16:43:05 +09:00
|
|
|
it 'should not configure watcher-api service' do
|
|
|
|
is_expected.to_not contain_service('watcher-api')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-15 10:16:22 +08:00
|
|
|
context 'when running watcher-api in wsgi' do
|
|
|
|
before do
|
|
|
|
params.merge!({ :service_name => 'httpd' })
|
|
|
|
end
|
|
|
|
|
|
|
|
let :pre_condition do
|
2019-12-08 23:25:42 +01:00
|
|
|
"include apache
|
|
|
|
include watcher::db
|
2017-08-15 10:16:22 +08:00
|
|
|
class { 'watcher': }
|
2019-12-08 23:25:42 +01:00
|
|
|
class { 'watcher::keystone::authtoken':
|
2017-08-15 10:16:22 +08:00
|
|
|
password => 'a_big_secret',
|
|
|
|
}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'configures watcher-api service with Apache' do
|
|
|
|
is_expected.to contain_service('watcher-api').with(
|
|
|
|
:ensure => 'stopped',
|
|
|
|
:name => platform_params[:api_service_name],
|
|
|
|
:enable => false,
|
|
|
|
:tag => ['watcher-service',
|
|
|
|
'watcher-db-manage-create_schema',
|
|
|
|
'watcher-db-manage-upgrade'],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when service_name is not valid' do
|
|
|
|
before do
|
|
|
|
params.merge!({ :service_name => 'foobar' })
|
|
|
|
end
|
|
|
|
|
|
|
|
let :pre_condition do
|
2019-12-08 23:25:42 +01:00
|
|
|
"include apache
|
|
|
|
include watcher::db
|
2017-08-15 10:16:22 +08:00
|
|
|
class { 'watcher': }
|
2019-12-08 23:25:42 +01:00
|
|
|
class { 'watcher::keystone::authtoken':
|
2017-08-15 10:16:22 +08:00
|
|
|
password => 'a_big_secret',
|
|
|
|
}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it_raises 'a Puppet::Error', /Invalid service_name/
|
|
|
|
end
|
|
|
|
|
2016-06-15 08:36:25 +00:00
|
|
|
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
|
2016-06-28 14:41:47 +00:00
|
|
|
let(:platform_params) do
|
2023-03-02 12:46:00 +09:00
|
|
|
case facts[:os]['family']
|
2016-06-28 14:41:47 +00:00
|
|
|
when 'Debian'
|
|
|
|
{ :api_package_name => 'watcher-api',
|
|
|
|
:api_service_name => 'watcher-api' }
|
|
|
|
when 'RedHat'
|
|
|
|
{ :api_package_name => 'openstack-watcher-api',
|
|
|
|
:api_service_name => 'openstack-watcher-api' }
|
|
|
|
end
|
|
|
|
end
|
2016-06-15 08:36:25 +00:00
|
|
|
it_behaves_like 'watcher-api'
|
|
|
|
end
|
|
|
|
end
|
2016-06-28 14:41:47 +00:00
|
|
|
|
2016-06-15 08:36:25 +00:00
|
|
|
end
|