1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#
# Unit tests for magnum::api
#
require 'spec_helper'
describe 'magnum::api' do
let :pre_condition do
'class { "magnum::keystone::authtoken": password => "secret", }'
end
let :default_params do
{ :package_ensure => 'present',
:enabled => true,
:port => '9511',
:host => '127.0.0.1',
:max_limit => '1000',
:sync_db => 'true',
:enabled_ssl => 'false',
:ssl_cert_file => '<SERVICE DEFAULT>',
:ssl_key_file => '<SERVICE DEFAULT>',
:enable_proxy_headers_parsing => '<SERVICE DEFAULT>',
}
end
let :params do
{}
end
shared_examples_for 'magnum-api' do
let :p do
default_params.merge(params)
end
it { is_expected.to contain_class('magnum::deps') }
it { is_expected.to contain_class('magnum::params') }
it { is_expected.to contain_class('magnum::policy') }
it 'configures magnum api package' do
is_expected.to contain_package('magnum-api').with(
:ensure => p[:package_ensure],
:name => platform_params[:api_package],
:tag => ['openstack', 'magnum-package'],
)
end
it 'ensures magnum api service is running' do
is_expected.to contain_service('magnum-api').with(
'hasstatus' => true,
'tag' => 'magnum-service',
)
end
it 'configures magnum.conf' do
is_expected.to contain_magnum_config('api/port').with_value(p[:port])
is_expected.to contain_magnum_config('api/host').with_value(p[:host])
is_expected.to contain_magnum_config('api/max_limit').with_value(p[:max_limit])
is_expected.to contain_magnum_config('api/enabled_ssl').with_value(p[:enabled_ssl])
is_expected.to contain_magnum_config('api/ssl_cert_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_magnum_config('api/ssl_key_file').with_value('<SERVICE DEFAULT>')
is_expected.to contain_magnum_config('api/workers').with_value(facts[:os_workers])
end
it { is_expected.to contain_oslo__middleware('magnum_config').with(
:enable_proxy_headers_parsing => '<SERVICE DEFAULT>',
)}
context 'when overriding parameters' do
before :each do
params.merge!(
:port => '1234',
:host => '0.0.0.0',
:max_limit => '10',
:workers => 10,
)
end
it 'should replace default parameters with new values' do
is_expected.to contain_magnum_config('api/port').with_value(p[:port])
is_expected.to contain_magnum_config('api/host').with_value(p[:host])
is_expected.to contain_magnum_config('api/max_limit').with_value(p[:max_limit])
is_expected.to contain_magnum_config('api/workers').with_value(p[:workers])
end
end
context 'with SSL enabled' do
let :params do
{
:enabled_ssl => true,
:ssl_cert_file => '/path/to/cert',
:ssl_key_file => '/path/to/key'
}
end
it { is_expected.to contain_magnum_config('api/enabled_ssl').with_value(p[:enabled_ssl]) }
it { is_expected.to contain_magnum_config('api/ssl_cert_file').with_value(p[:ssl_cert_file]) }
it { is_expected.to contain_magnum_config('api/ssl_key_file').with_value(p[:ssl_key_file]) }
end
context 'with oslo_middleware configured' do
let :params do
{
:enable_proxy_headers_parsing => true,
}
end
it { is_expected.to contain_oslo__middleware('magnum_config').with(
:enable_proxy_headers_parsing => 'true',
)}
end
end
shared_examples 'magnum-api wsgi' do
let :pre_condition do
"include magnum
class { 'magnum::keystone::authtoken':
password => 'secret',
}
include apache"
end
let :params do
{
:service_name => 'httpd',
}
end
context 'with required params' do
it { should contain_service('magnum-api').with(
:ensure => 'stopped',
:name => platform_params[:api_service],
:enable => false,
:hasstatus => true,
:tag => 'magnum-service',
)}
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
let(:platform_params) do
case facts[:os]['family']
when 'Debian'
{ :api_package => 'magnum-api',
:api_service => 'magnum-api' }
when 'RedHat'
{ :api_package => 'openstack-magnum-api',
:api_service => 'openstack-magnum-api' }
end
end
it_configures 'magnum-api'
it_configures 'magnum-api wsgi'
end
end
end
|