Files
puppet-nova/spec/classes/nova_init_spec.rb
Emilien Macchi 9fdcb01c96 rpc_backend: simplify parameters
Since Icehouse, there is no need to specify the whole Python namespace
for the backends.
We can now use keywords like "rabbit", "qpid" or "zmq".

This patch maintains backward compatibility with previous default
parameters in case someone overrides it with the default parameter.

Source: https://github.com/openstack/nova/blob/master/nova/rpc.py#L48-L55

Closes-bug: #1405656

Change-Id: I23d1331e047a99cac3f4939f83de190275ca1236
2014-12-31 18:38:34 +00:00

595 lines
22 KiB
Ruby

require 'spec_helper'
describe 'nova' do
shared_examples 'nova' do
context 'with default parameters' do
it 'installs packages' do
should contain_package('python').with_ensure('present')
should contain_package('python-greenlet').with(
:ensure => 'present',
:require => 'Package[python]'
)
should contain_package('python-nova').with(
:ensure => 'present',
:require => 'Package[python-greenlet]'
)
should contain_package('nova-common').with(
:name => platform_params[:nova_common_package],
:ensure => 'present',
:tag => ['openstack', 'nova']
)
end
it 'creates various files and folders' do
should contain_file('/var/log/nova').with(
:ensure => 'directory',
:mode => '0750',
:owner => 'nova',
:group => 'nova',
:require => 'Package[nova-common]'
)
should contain_file('/etc/nova/nova.conf').with(
:mode => '0640',
:owner => 'nova',
:group => 'nova',
:require => 'Package[nova-common]'
)
end
it 'configures rootwrap' do
should contain_nova_config('DEFAULT/rootwrap_config').with_value('/etc/nova/rootwrap.conf')
end
it { should contain_exec('networking-refresh').with(
:command => '/sbin/ifdown -a ; /sbin/ifup -a',
:refreshonly => true
)}
it 'configures image service' do
should contain_nova_config('DEFAULT/image_service').with_value('nova.image.glance.GlanceImageService')
should contain_nova_config('glance/api_servers').with_value('localhost:9292')
end
it 'configures auth_strategy' do
should contain_nova_config('DEFAULT/auth_strategy').with_value('keystone')
should_not contain_nova_config('DEFAULT/use_deprecated_auth').with_value(false)
end
it 'configures rabbit' do
should contain_nova_config('DEFAULT/rpc_backend').with_value('rabbit')
should contain_nova_config('DEFAULT/rabbit_host').with_value('localhost')
should contain_nova_config('DEFAULT/rabbit_password').with_value('guest').with_secret(true)
should contain_nova_config('DEFAULT/rabbit_port').with_value('5672')
should contain_nova_config('DEFAULT/rabbit_userid').with_value('guest')
should contain_nova_config('DEFAULT/rabbit_virtual_host').with_value('/')
end
it 'configures various things' do
should contain_nova_config('DEFAULT/verbose').with_value(false)
should contain_nova_config('DEFAULT/debug').with_value(false)
should contain_nova_config('DEFAULT/log_dir').with_value('/var/log/nova')
should contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova')
should contain_nova_config('DEFAULT/lock_path').with_value(platform_params[:lock_path])
should contain_nova_config('DEFAULT/service_down_time').with_value('60')
should contain_nova_config('DEFAULT/rootwrap_config').with_value('/etc/nova/rootwrap.conf')
should contain_nova_config('DEFAULT/report_interval').with_value('10')
should contain_nova_config('DEFAULT/os_region_name').with_ensure('absent')
end
it 'installs utilities' do
should contain_class('nova::utilities')
end
it 'disables syslog' do
should contain_nova_config('DEFAULT/use_syslog').with_value(false)
end
end
context 'with overridden parameters' do
let :params do
{ :verbose => true,
:debug => true,
:log_dir => '/var/log/nova2',
:image_service => 'nova.image.local.LocalImageService',
:rabbit_host => 'rabbit',
:rabbit_userid => 'rabbit_user',
:rabbit_port => '5673',
:rabbit_password => 'password',
:rabbit_ha_queues => 'undef',
:lock_path => '/var/locky/path',
:state_path => '/var/lib/nova2',
:service_down_time => '120',
:auth_strategy => 'foo',
:ensure_package => '2012.1.1-15.el6',
:memcached_servers => ['memcached01:11211', 'memcached02:11211'],
:install_utilities => false,
:notification_driver => 'ceilometer.compute.nova_notifier',
:notification_topics => 'openstack',
:notify_api_faults => true,
:report_interval => '60',
:os_region_name => 'MyRegion' }
end
it 'installs packages' do
should contain_package('nova-common').with('ensure' => '2012.1.1-15.el6')
should contain_package('python-nova').with('ensure' => '2012.1.1-15.el6')
end
it 'configures image service' do
should contain_nova_config('DEFAULT/image_service').with_value('nova.image.local.LocalImageService')
should_not contain_nova_config('glance/api_servers')
end
it 'configures auth_strategy' do
should contain_nova_config('DEFAULT/auth_strategy').with_value('foo')
should_not contain_nova_config('DEFAULT/use_deprecated_auth').with_value(true)
end
it 'configures rabbit' do
should contain_nova_config('DEFAULT/rpc_backend').with_value('rabbit')
should contain_nova_config('DEFAULT/rabbit_host').with_value('rabbit')
should contain_nova_config('DEFAULT/rabbit_password').with_value('password').with_secret(true)
should contain_nova_config('DEFAULT/rabbit_port').with_value('5673')
should contain_nova_config('DEFAULT/rabbit_userid').with_value('rabbit_user')
should contain_nova_config('DEFAULT/rabbit_virtual_host').with_value('/')
end
it 'configures memcached_servers' do
should contain_nova_config('DEFAULT/memcached_servers').with_value('memcached01:11211,memcached02:11211')
end
it 'configures various things' do
should contain_nova_config('DEFAULT/verbose').with_value(true)
should contain_nova_config('DEFAULT/debug').with_value(true)
should contain_nova_config('DEFAULT/log_dir').with_value('/var/log/nova2')
should contain_nova_config('DEFAULT/state_path').with_value('/var/lib/nova2')
should contain_nova_config('DEFAULT/lock_path').with_value('/var/locky/path')
should contain_nova_config('DEFAULT/service_down_time').with_value('120')
should contain_nova_config('DEFAULT/notification_driver').with_value('ceilometer.compute.nova_notifier')
should contain_nova_config('DEFAULT/notification_topics').with_value('openstack')
should contain_nova_config('DEFAULT/notify_api_faults').with_value(true)
should contain_nova_config('DEFAULT/report_interval').with_value('60')
should contain_nova_config('DEFAULT/os_region_name').with_value('MyRegion')
end
context 'with multiple notification_driver' do
before { params.merge!( :notification_driver => ['ceilometer.compute.nova_notifier', 'nova.openstack.common.notifier.rpc_notifier']) }
it { should contain_nova_config('DEFAULT/notification_driver').with_value(
'ceilometer.compute.nova_notifier,nova.openstack.common.notifier.rpc_notifier'
) }
end
it 'does not install utilities' do
should_not contain_class('nova::utilities')
end
context 'with logging directory disabled' do
before { params.merge!( :log_dir => false) }
it { should contain_nova_config('DEFAULT/log_dir').with_ensure('absent') }
end
end
context 'with wrong notify_on_state_change parameter' do
let :params do
{ :notify_on_state_change => 'vm_status' }
end
it 'configures database' do
should contain_nova_config('DEFAULT/notify_on_state_change').with_ensure('absent')
end
end
context 'with notify_on_state_change parameter' do
let :params do
{ :notify_on_state_change => 'vm_state' }
end
it 'configures database' do
should contain_nova_config('DEFAULT/notify_on_state_change').with_value('vm_state')
end
end
context 'with syslog enabled' do
let :params do
{ :use_syslog => 'true' }
end
it 'configures syslog' do
should contain_nova_config('DEFAULT/use_syslog').with_value(true)
should contain_nova_config('DEFAULT/syslog_log_facility').with_value('LOG_USER')
end
end
context 'with syslog enabled and log_facility parameter' do
let :params do
{ :use_syslog => 'true',
:log_facility => 'LOG_LOCAL0' }
end
it 'configures syslog' do
should contain_nova_config('DEFAULT/use_syslog').with_value(true)
should contain_nova_config('DEFAULT/syslog_log_facility').with_value('LOG_LOCAL0')
end
end
context 'with rabbit_hosts parameter' do
let :params do
{ :rabbit_hosts => ['rabbit:5673', 'rabbit2:5674'] }
end
it 'configures rabbit' do
should_not contain_nova_config('DEFAULT/rabbit_host')
should_not contain_nova_config('DEFAULT/rabbit_port')
should contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673,rabbit2:5674')
should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false)
should contain_nova_config('DEFAULT/amqp_durable_queues').with_value(false)
should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent')
end
end
context 'with rabbit_hosts parameter (one server)' do
let :params do
{ :rabbit_hosts => ['rabbit:5673'] }
end
it 'configures rabbit' do
should_not contain_nova_config('DEFAULT/rabbit_host')
should_not contain_nova_config('DEFAULT/rabbit_port')
should contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673')
should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false)
should contain_nova_config('DEFAULT/amqp_durable_queues').with_value(false)
end
end
context 'with rabbit_ha_queues set to true' do
let :params do
{ :rabbit_ha_queues => 'true' }
end
it 'configures rabbit' do
should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
end
end
context 'with amqp_durable_queues parameter' do
let :params do
{ :rabbit_hosts => ['rabbit:5673'],
:amqp_durable_queues => 'true' }
end
it 'configures rabbit' do
should_not contain_nova_config('DEFAULT/rabbit_host')
should_not contain_nova_config('DEFAULT/rabbit_port')
should contain_nova_config('DEFAULT/rabbit_hosts').with_value('rabbit:5673')
should contain_nova_config('DEFAULT/rabbit_ha_queues').with_value(true)
should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(false)
should contain_nova_config('DEFAULT/amqp_durable_queues').with_value(true)
should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent')
end
end
context 'with rabbit ssl enabled with kombu' do
let :params do
{ :rabbit_hosts => ['rabbit:5673'],
:rabbit_use_ssl => 'true',
:kombu_ssl_ca_certs => '/etc/ca.cert',
:kombu_ssl_certfile => '/etc/certfile',
:kombu_ssl_keyfile => '/etc/key',
:kombu_ssl_version => 'TLSv1', }
end
it 'configures rabbit' do
should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(true)
should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_value('/etc/ca.cert')
should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_value('/etc/certfile')
should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_value('/etc/key')
should contain_nova_config('DEFAULT/kombu_ssl_version').with_value('TLSv1')
end
end
context 'with rabbit ssl enabled without kombu' do
let :params do
{ :rabbit_hosts => ['rabbit:5673'],
:rabbit_use_ssl => 'true', }
end
it 'configures rabbit' do
should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value(true)
should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_version').with_value('SSLv3')
end
end
context 'with rabbit ssl disabled' do
let :params do
{
:rabbit_password => 'pass',
:rabbit_use_ssl => false,
:kombu_ssl_version => 'SSLv3',
}
end
it 'configures rabbit' do
should contain_nova_config('DEFAULT/rabbit_use_ssl').with_value('false')
should contain_nova_config('DEFAULT/kombu_ssl_ca_certs').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_certfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_keyfile').with_ensure('absent')
should contain_nova_config('DEFAULT/kombu_ssl_version').with_ensure('absent')
end
end
context 'with qpid rpc_backend' do
let :params do
{ :rpc_backend => 'qpid' }
end
context 'with default parameters' do
it 'configures qpid' do
should contain_nova_config('DEFAULT/rpc_backend').with_value('qpid')
should contain_nova_config('DEFAULT/qpid_hostname').with_value('localhost')
should contain_nova_config('DEFAULT/qpid_port').with_value('5672')
should contain_nova_config('DEFAULT/qpid_username').with_value('guest')
should contain_nova_config('DEFAULT/qpid_password').with_value('guest').with_secret(true)
should contain_nova_config('DEFAULT/qpid_heartbeat').with_value('60')
should contain_nova_config('DEFAULT/qpid_protocol').with_value('tcp')
should contain_nova_config('DEFAULT/qpid_tcp_nodelay').with_value(true)
end
end
context 'with qpid_password parameter (without qpid_sasl_mechanisms)' do
before do
params.merge!({ :qpid_password => 'guest' })
end
it { should contain_nova_config('DEFAULT/qpid_sasl_mechanisms').with_ensure('absent') }
end
context 'with qpid_password parameter (with qpid_sasl_mechanisms)' do
before do
params.merge!({
:qpid_password => 'guest',
:qpid_sasl_mechanisms => 'A'
})
end
it { should contain_nova_config('DEFAULT/qpid_sasl_mechanisms').with_value('A') }
end
context 'with qpid_password parameter (with array of qpid_sasl_mechanisms)' do
before do
params.merge!({
:qpid_password => 'guest',
:qpid_sasl_mechanisms => [ 'DIGEST-MD5', 'GSSAPI', 'PLAIN' ]
})
end
it { should contain_nova_config('DEFAULT/qpid_sasl_mechanisms').with_value('DIGEST-MD5 GSSAPI PLAIN') }
end
end
context 'with qpid rpc_backend with old parameter' do
let :params do
{ :rpc_backend => 'nova.openstack.common.rpc.impl_qpid' }
end
it { should contain_nova_config('DEFAULT/rpc_backend').with_value('nova.openstack.common.rpc.impl_qpid') }
end
context 'with rabbitmq rpc_backend with old parameter' do
let :params do
{ :rpc_backend => 'nova.openstack.common.rpc.impl_kombu' }
end
it { should contain_nova_config('DEFAULT/rpc_backend').with_value('nova.openstack.common.rpc.impl_kombu') }
end
context 'with ssh public key' do
let :params do
{
:nova_public_key => {'type' => 'ssh-rsa',
'key' => 'keydata'}
}
end
it 'should install ssh public key' do
should contain_ssh_authorized_key('nova-migration-public-key').with(
:ensure => 'present',
:key => 'keydata',
:type => 'ssh-rsa'
)
end
end
context 'with ssh public key missing key type' do
let :params do
{
:nova_public_key => {'type' => '',
'key' => 'keydata'}
}
end
it 'should raise an error' do
expect {
should contain_ssh_authorized_key('nova-migration-public-key').with(
:ensure => 'present',
:key => 'keydata',
:type => ''
)
}.to raise_error Puppet::Error, /You must provide both a key type and key data./
end
end
context 'with ssh public key missing key data' do
let :params do
{
:nova_public_key => {'type' => 'ssh-rsa',
'key' => ''}
}
end
it 'should raise an error' do
expect {
should contain_ssh_authorized_key('nova-migration-public-key').with(
:ensure => 'present',
:key => 'keydata',
:type => ''
)
}.to raise_error Puppet::Error, /You must provide both a key type and key data./
end
end
context 'with ssh private key' do
let :params do
{
:nova_private_key => {'type' => 'ssh-rsa',
'key' => 'keydata'}
}
end
it 'should install ssh private key' do
should contain_file('/var/lib/nova/.ssh/id_rsa').with(
:content => 'keydata'
)
end
end
context 'with ssh private key missing key type' do
let :params do
{
:nova_private_key => {'type' => '',
'key' => 'keydata'}
}
end
it 'should raise an error' do
expect {
should contain_file('/var/lib/nova/.ssh/id_rsa').with(
:content => 'keydata'
)
}.to raise_error Puppet::Error, /You must provide both a key type and key data./
end
end
context 'with ssh private key having incorrect key type' do
let :params do
{
:nova_private_key => {'type' => 'invalid',
'key' => 'keydata'}
}
end
it 'should raise an error' do
expect {
should contain_file('/var/lib/nova/.ssh/id_rsa').with(
:content => 'keydata'
)
}.to raise_error Puppet::Error, /Unable to determine name of private key file./
end
end
context 'with ssh private key missing key data' do
let :params do
{
:nova_private_key => {'type' => 'ssh-rsa',
'key' => ''}
}
end
it 'should raise an error' do
expect {
should contain_file('/var/lib/nova/.ssh/id_rsa').with(
:content => 'keydata'
)
}.to raise_error Puppet::Error, /You must provide both a key type and key data./
end
end
context 'with SSL socket options set' do
let :params do
{
:use_ssl => true,
:enabled_ssl_apis => ['ec2', 'osapi_compute'],
:cert_file => '/path/to/cert',
:ca_file => '/path/to/ca',
:key_file => '/path/to/key',
}
end
it { should contain_nova_config('DEFAULT/enabled_ssl_apis').with_value('ec2,osapi_compute') }
it { should contain_nova_config('DEFAULT/ssl_ca_file').with_value('/path/to/ca') }
it { should contain_nova_config('DEFAULT/ssl_cert_file').with_value('/path/to/cert') }
it { should contain_nova_config('DEFAULT/ssl_key_file').with_value('/path/to/key') }
end
context 'with SSL socket options set with wrong parameters' do
let :params do
{
:use_ssl => true,
:enabled_ssl_apis => ['ec2'],
:ca_file => '/path/to/ca',
:key_file => '/path/to/key',
}
end
it_raises 'a Puppet::Error', /The cert_file parameter is required when use_ssl is set to true/
end
context 'with SSL socket options set to false' do
let :params do
{
:use_ssl => false,
:enabled_ssl_apis => [],
:cert_file => false,
:ca_file => false,
:key_file => false,
}
end
it { should contain_nova_config('DEFAULT/enabled_ssl_apis').with_ensure('absent') }
it { should contain_nova_config('DEFAULT/ssl_ca_file').with_ensure('absent') }
it { should contain_nova_config('DEFAULT/ssl_cert_file').with_ensure('absent') }
it { should contain_nova_config('DEFAULT/ssl_key_file').with_ensure('absent') }
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
let :platform_params do
{ :nova_common_package => 'nova-common',
:lock_path => '/var/lock/nova' }
end
it_behaves_like 'nova'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
let :platform_params do
{ :nova_common_package => 'openstack-nova-common',
:lock_path => '/var/lib/nova/tmp' }
end
it_behaves_like 'nova'
end
end