Support platforms without quantum server package

RedHat platforms don't have a separate package for the quantum server.

Change-Id: Ied83733f1dc8ec55a664e1d9c7119d3105a0a8e2
This commit is contained in:
Mathieu Gagné 2013-05-19 00:42:56 -04:00 committed by Dan Bode
parent 1ffb21b5aa
commit 17c25b8d82
6 changed files with 149 additions and 42 deletions

View File

@ -4,7 +4,7 @@
#
# TODO: create ability to have multiple L3 services
#
# === Parameters:
# === Parameters
#
# [*package_ensure*]
# (optional) The state of the package
@ -46,14 +46,6 @@
# (optional) The port of the metadata server
# Defaults to 9697
#
# [*use_ovs*]
# (optional) Whether or not to use OVS to create any bridges
# Defaults to false
#
# [*external_port*]
# (optional) The uplink port to use on the external bridge
# Defaults to false
#
class quantum::agents::l3 (
$package_ensure = 'present',
$enabled = true,
@ -70,7 +62,7 @@ class quantum::agents::l3 (
include quantum::params
Quantum_config<||> ~> Service['quantum-l3']
Quantum_config<||> ~> Service['quantum-l3']
Quantum_l3_agent_config<||> ~> Service['quantum-l3']
quantum_l3_agent_config {
@ -87,12 +79,15 @@ class quantum::agents::l3 (
if $::quantum::params::l3_agent_package {
Package['quantum-l3'] -> Quantum_l3_agent_config<||>
Package['quantum-l3'] -> Service['quantum-l3']
package { 'quantum-l3':
name => $::quantum::params::l3_agent_package,
ensure => $package_ensure,
require => Package['quantum'],
}
} else {
# Some platforms (RedHat) does not provide a quantum L3 agent package.
# The quantum L3 agent config file is provided by the quantum package.
Package['quantum'] -> Quantum_l3_agent_config<||>
}
if $enabled {

View File

@ -64,11 +64,11 @@ class quantum::server (
include quantum::params
require keystone::python
Quantum_config<||> ~> Service['quantum-server']
Quantum_config<||> ~> Service['quantum-server']
Quantum_api_config<||> ~> Service['quantum-server']
quantum_config {
'DEFAULT/log_file': value => $log_file
'DEFAULT/log_file': value => $log_file
}
if $enabled {
@ -80,10 +80,15 @@ class quantum::server (
if ($::quantum::params::server_package) {
Package['quantum-server'] -> Quantum_api_config<||>
Package['quantum-server'] -> Quantum_config<||>
package {'quantum-server':
Package['quantum-server'] -> Service['quantum-server']
package { 'quantum-server':
name => $::quantum::params::server_package,
ensure => $package_ensure
}
} else {
# Some platforms (RedHat) does not provide a quantum-server package.
# The quantum api config file is provided by the quantum package.
Package['quantum'] -> Quantum_api_config<||>
}
if ($auth_type == 'keystone') {
@ -111,11 +116,12 @@ class quantum::server (
}
}
service {'quantum-server':
service { 'quantum-server':
name => $::quantum::params::server_service,
ensure => $service_ensure,
enable => $enabled,
hasstatus => true,
hasrestart => true
hasrestart => true,
require => Class['quantum'],
}
}

View File

@ -2,20 +2,69 @@ require 'spec_helper'
describe 'quantum::agents::l3' do
let :pre_condition do
"class { 'quantum': rabbit_password => 'passw0rd' }"
end
let :default_params do
{ :package_ensure => 'present',
:enabled => true,
:debug => false,
:external_network_bridge => 'br-ex',
:use_namespaces => true,
:interface_driver => 'quantum.agent.linux.interface.OVSInterfaceDriver',
:router_id => nil,
:gateway_external_network_id => nil,
:handle_internal_only_routers => true,
:metadata_port => '9697',
:root_helper => 'sudo /usr/bin/quantum-rootwrap /etc/quantum/rootwrap.conf' }
end
let :params do
{
:external_network_bridge => 'br-floating'
}
{ }
end
shared_examples_for 'quantum l3 agent' do
let :p do
default_params.merge(params)
end
it { should include_class('quantum::params') }
it 'configures quantum l3 agent' do
should contain_quantum_l3_agent_config('DEFAULT/external_network_bridge').with(
:value => params[:external_network_bridge]
it 'configures l3_agent.ini' do
should contain_quantum_l3_agent_config('DEFAULT/debug').with_value(p[:debug])
should contain_quantum_l3_agent_config('DEFAULT/external_network_bridge').with_value(p[:external_network_bridge])
should contain_quantum_l3_agent_config('DEFAULT/use_namespaces').with_value(p[:use_namespaces])
should contain_quantum_l3_agent_config('DEFAULT/interface_driver').with_value(p[:interface_driver])
should contain_quantum_l3_agent_config('DEFAULT/router_id').with_value(p[:router_id])
should contain_quantum_l3_agent_config('DEFAULT/gateway_external_network_id').with_value(p[:gateway_external_network_id])
should contain_quantum_l3_agent_config('DEFAULT/handle_internal_only_routers').with_value(p[:handle_internal_only_routers])
should contain_quantum_l3_agent_config('DEFAULT/metadata_port').with_value(p[:metadata_port])
should contain_quantum_l3_agent_config('DEFAULT/root_helper').with_value(p[:root_helper])
end
it 'installs quantum l3 agent package' do
if platform_params.has_key?(:l3_agent_package)
should contain_package('quantum-l3').with(
:name => platform_params[:l3_agent_package],
:ensure => p[:package_ensure],
:require => 'Package[quantum]'
)
should contain_package('quantum-l3').with_before(/Quantum_l3_agent_config\[.+\]/)
else
should contain_package('quantum').with_before(/Quantum_l3_agent_config\[.+\]/)
end
end
it 'configures quantum l3 agent service' do
should contain_service('quantum-l3').with(
:name => platform_params[:l3_agent_service],
:enable => true,
:ensure => 'running',
:require => 'Class[Quantum]'
)
end
end
context 'on Debian platforms' do
@ -23,6 +72,11 @@ describe 'quantum::agents::l3' do
{ :osfamily => 'Debian' }
end
let :platform_params do
{ :l3_agent_package => 'quantum-l3-agent',
:l3_agent_service => 'quantum-l3-agent' }
end
it_configures 'quantum l3 agent'
end
@ -31,6 +85,10 @@ describe 'quantum::agents::l3' do
{ :osfamily => 'RedHat' }
end
let :platform_params do
{ :l3_agent_service => 'quantum-l3-agent' }
end
it_configures 'quantum l3 agent'
end
end

View File

@ -2,23 +2,62 @@ require 'spec_helper'
describe 'quantum::server' do
let :pre_condition do
"class { 'quantum': rabbit_password => 'passw0rd' }"
end
let :params do
{
:auth_password => 'passw0rd',
:auth_user => 'quantum'
}
{ :auth_password => 'passw0rd',
:auth_user => 'quantum' }
end
let :default_params do
{ :package_ensure => 'present',
:enabled => true,
:log_file => '/var/log/quantum/server.log',
:auth_type => 'keystone',
:auth_host => 'localhost',
:auth_port => '35357',
:auth_tenant => 'services',
:auth_user => 'quantum' }
end
shared_examples_for 'a quantum server' do
it { should include_class('quantum::params') }
it 'configures quantum.conf' do
should contain_quantum_config('keystone_authtoken/admin_user').with(
:value => params[:auth_user]
)
let :p do
default_params.merge(params)
end
it 'configures quantum-api.conf' do
should contain_quantum_api_config('filter:authtoken/admin_user').with(
:value => params[:auth_user]
it { should include_class('quantum::params') }
it { should contain_quantum_config('DEFAULT/log_file').with_value(p[:log_file]) }
it 'configures authentication middleware' do
should contain_quantum_api_config('filter:authtoken/auth_host').with_value(p[:auth_host]);
should contain_quantum_api_config('filter:authtoken/auth_port').with_value(p[:auth_port]);
should contain_quantum_api_config('filter:authtoken/admin_tenant_name').with_value(p[:auth_tenant]);
should contain_quantum_api_config('filter:authtoken/admin_user').with_value(p[:auth_user]);
should contain_quantum_api_config('filter:authtoken/admin_password').with_value(p[:auth_password]);
end
it 'installs quantum server package' do
if platform_params.has_key?(:server_package)
should contain_package('quantum-server').with(
:name => platform_params[:server_package],
:ensure => p[:package_ensure]
)
should contain_package('quantum-server').with_before(/Quantum_api_config\[.+\]/)
should contain_package('quantum-server').with_before(/Quantum_config\[.+\]/)
should contain_package('quantum-server').with_before(/Service\[quantum-server\]/)
else
should contain_package('quantum').with_before(/Quantum_api_config\[.+\]/)
end
end
it 'configures quantum server service' do
should contain_service('quantum-server').with(
:name => platform_params[:server_service],
:enable => true,
:ensure => 'running',
:require => 'Class[Quantum]'
)
end
end
@ -27,21 +66,19 @@ describe 'quantum::server' do
before do
params.delete(:auth_password)
end
it do
expect {
should contain_quantum_api_config('filter:authtoken/admin_user').with(
:value => params[:auth_user]
)
}.to raise_error(Puppet::Error, /auth_password must be set/)
end
it_raises 'a Puppet::Error', /auth_password must be set/
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
let :platform_params do
{ :server_package => 'quantum-server',
:server_service => 'quantum-server' }
end
it_configures 'a quantum server'
it_configures 'a quantum server with broken authentication'
end
@ -51,6 +88,10 @@ describe 'quantum::server' do
{ :osfamily => 'RedHat' }
end
let :platform_params do
{ :server_service => 'quantum-server' }
end
it_configures 'a quantum server'
it_configures 'a quantum server with broken authentication'
end

5
spec/shared_examples.rb Normal file
View File

@ -0,0 +1,5 @@
shared_examples_for "a Puppet::Error" do |description|
it "with message matching #{description.inspect}" do
expect { should have_class_count(1) }.to raise_error(Puppet::Error, description)
end
end

View File

@ -1,5 +1,7 @@
require 'puppetlabs_spec_helper/module_spec_helper'
require 'shared_examples'
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures'
c.alias_it_should_behave_like_to :it_raises, 'raises'
end