2016-06-15 08:36:25 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'watcher::api' do
|
|
|
|
|
|
|
|
let :params do
|
2016-08-17 22:26:52 +00:00
|
|
|
{ :watcher_client_password => 'password',
|
2016-06-28 14:41:47 +00:00
|
|
|
:manage_service => true,
|
|
|
|
:enabled => true,
|
|
|
|
:package_ensure => 'latest',
|
|
|
|
}
|
2016-06-15 08:36:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'watcher-api' do
|
|
|
|
|
2016-08-17 22:26:52 +00:00
|
|
|
context 'without required parameter watcher_client_password' do
|
|
|
|
before { params.delete(:watcher_client_password) }
|
2016-06-15 08:36:25 +00:00
|
|
|
it { expect { is_expected.to raise_error(Puppet::Error) } }
|
|
|
|
end
|
|
|
|
|
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(
|
|
|
|
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
|
|
|
|
: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
|
|
|
|
is_expected.to contain_watcher_config('api/port').with_value('9322')
|
|
|
|
is_expected.to contain_watcher_config('api/max_limit').with_value('<SERVICE DEFAULT>')
|
|
|
|
is_expected.to contain_watcher_config('api/host').with_value('0.0.0.0')
|
|
|
|
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,
|
|
|
|
:enabled => false })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'configures watcher-api service' do
|
|
|
|
is_expected.to contain_service('watcher-api').with(
|
|
|
|
:ensure => nil,
|
|
|
|
:name => platform_params[:api_service_name],
|
|
|
|
:enable => false,
|
|
|
|
: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
|
2016-10-13 17:22:21 -06:00
|
|
|
|
|
|
|
it 'should not configure the api configurations section when disabled' do
|
|
|
|
is_expected.to_not contain_watcher_config('api/port')
|
|
|
|
is_expected.to_not contain_watcher_config('api/max_limit')
|
|
|
|
is_expected.to_not contain_watcher_config('api/host')
|
|
|
|
is_expected.to_not contain_watcher_config('api/workers')
|
2016-11-06 20:25:18 +00:00
|
|
|
is_expected.to_not contain_watcher_config('api/enable_ssl_api')
|
2016-10-13 17:22:21 -06:00
|
|
|
end
|
|
|
|
|
2016-06-28 14:41:47 +00:00
|
|
|
end
|
|
|
|
|
2016-06-15 08:36:25 +00:00
|
|
|
context 'watcher clients auth section with default parameters' do
|
|
|
|
it 'configures watcher clients auth' do
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/username').with_value('watcher')
|
2016-08-17 22:26:52 +00:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/password').with_value( params[:watcher_client_password] )
|
2018-05-13 00:55:24 +08:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/auth_url').with_value('http://localhost:5000/')
|
2016-06-15 08:36:25 +00:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/auth_uri').with_value('http://localhost:5000/')
|
2019-03-15 09:24:31 +08:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/project_name').with_value('services')
|
2016-07-06 16:32:46 -06:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/project_domain_name').with_value('<SERVICE DEFAULT>')
|
2019-03-13 14:31:30 +05:30
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/user_domain_name').with_value('<SERVICE DEFAULT>')
|
2016-06-15 08:36:25 +00:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/insecure').with_value('<SERVICE DEFAULT>')
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/auth_type').with_value('password')
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/cafile').with_value('<SERVICE DEFAULT>')
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/certfile').with_value('<SERVICE DEFAULT>')
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/keyfile').with_value('<SERVICE DEFAULT>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'watcher clients auth section with overridden parameters' do
|
|
|
|
before do
|
|
|
|
params.merge! ({
|
|
|
|
:watcher_client_username => 'watcher_user',
|
|
|
|
:watcher_client_password => 'PassWoRD',
|
2016-08-17 22:26:52 +00:00
|
|
|
:watcher_client_auth_uri => 'http://localhost:5001/',
|
|
|
|
:watcher_client_auth_url => 'http://localhost:35358/',
|
2016-06-15 08:36:25 +00:00
|
|
|
:watcher_client_project_name => 'ProjectZero',
|
|
|
|
:watcher_client_project_domain_name => 'WatcherDomain',
|
2019-03-13 14:31:30 +05:30
|
|
|
:watcher_client_user_domain_name => 'WatcherUserDomain',
|
2016-06-15 08:36:25 +00:00
|
|
|
:watcher_client_insecure => 'true',
|
|
|
|
:watcher_client_auth_type => 'password',
|
|
|
|
:watcher_client_cafile => '/tmp/ca.crt',
|
|
|
|
:watcher_client_certfile => '/tmp/watcher.com.crt',
|
|
|
|
:watcher_client_keyfile => '/tmp/key.pm',
|
|
|
|
})
|
|
|
|
end
|
|
|
|
it 'configures watcher clients auth' do
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/username').with_value( params[:watcher_client_username] )
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/password').with_value( params[:watcher_client_password] )
|
2016-08-17 22:26:52 +00:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/auth_uri').with_value('http://localhost:5001/')
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/auth_url').with_value('http://localhost:35358/')
|
2016-06-15 08:36:25 +00:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/project_name').with_value( params[:watcher_client_project_name] )
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/project_domain_name').with_value( params[:watcher_client_project_domain_name] )
|
2019-03-13 14:31:30 +05:30
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/user_domain_name').with_value( params[:watcher_client_user_domain_name] )
|
2016-06-15 08:36:25 +00:00
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/insecure').with_value( params[:watcher_client_insecure] )
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/auth_type').with_value( params[:watcher_client_auth_type] )
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/cafile').with_value( params[:watcher_client_cafile] )
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/certfile').with_value( params[:watcher_client_certfile] )
|
|
|
|
is_expected.to contain_watcher_config('watcher_clients_auth/keyfile').with_value( params[:watcher_client_keyfile] )
|
|
|
|
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
|
|
|
|
"include ::apache
|
|
|
|
include ::watcher::db
|
|
|
|
class { 'watcher': }
|
|
|
|
class { '::watcher::keystone::authtoken':
|
|
|
|
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
|
|
|
|
"include ::apache
|
|
|
|
include ::watcher::db
|
|
|
|
class { 'watcher': }
|
|
|
|
class { '::watcher::keystone::authtoken':
|
|
|
|
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
|
|
|
|
case facts[:osfamily]
|
|
|
|
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
|