Skip to content

Commit

Permalink
Merge "Add manage_service feature"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 29, 2014
2 parents 1ba121c + 2ee5496 commit 493fbb4
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 141 deletions.
22 changes: 17 additions & 5 deletions manifests/api.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Installs & configure the heat API service

#
# == Parameters
# [*enabled*]
# (optional) Should the service be enabled.
# Defaults to true
#
# [*manage_service*]
# (optional) Whether the service should be managed by Puppet.
# Defaults to true.
#
class heat::api (
$manage_service = true,
$enabled = true,
$bind_host = '0.0.0.0',
$bind_port = '8004',
Expand Down Expand Up @@ -32,10 +42,12 @@
name => $::heat::params::api_package_name,
}

if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}

service { 'heat-api':
Expand Down
22 changes: 17 additions & 5 deletions manifests/api_cfn.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Installs & configure the heat CloudFormation API service

#
# == Parameters
# [*enabled*]
# (optional) Should the service be enabled.
# Defaults to true
#
# [*manage_service*]
# (optional) Whether the service should be managed by Puppet.
# Defaults to true.
#
class heat::api_cfn (
$manage_service = true,
$enabled = true,
$bind_host = '0.0.0.0',
$bind_port = '8000',
Expand Down Expand Up @@ -32,10 +42,12 @@
name => $::heat::params::api_cfn_package_name,
}

if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}

Package['heat-common'] -> Service['heat-api-cfn']
Expand Down
23 changes: 18 additions & 5 deletions manifests/api_cloudwatch.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Installs & configure the heat CloudWatch API service

#
# == Parameters
# [*enabled*]
# (optional) Should the service be enabled.
# Defaults to true
#
# [*manage_service*]
# (optional) Whether the service should be managed by Puppet.
# Defaults to true.
#
class heat::api_cloudwatch (
$manage_service = true,
$enabled = true,
$bind_host = '0.0.0.0',
$bind_port = '8003',
Expand Down Expand Up @@ -32,12 +42,15 @@
name => $::heat::params::api_cloudwatch_package_name,
}

if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}


Package['heat-common'] -> Service['heat-api-cloudwatch']

service { 'heat-api-cloudwatch':
Expand Down
17 changes: 12 additions & 5 deletions manifests/engine.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
#
# == parameters
# [*enabled*]
# (optional) The state of the service
# (optional) Should the service be enabled.
# Defaults to true
#
# [*manage_service*]
# (optional) Whether the service should be managed by Puppet.
# Defaults to true.
#
# [*heat_stack_user_role*]
# (optional) Keystone role for heat template-defined users
# Defaults to 'heat_stack_user'
Expand Down Expand Up @@ -34,6 +38,7 @@

class heat::engine (
$auth_encryption_key,
$manage_service = true,
$enabled = true,
$heat_stack_user_role = 'heat_stack_user',
$heat_metadata_server_url = 'http://127.0.0.1:8000',
Expand All @@ -53,10 +58,12 @@
name => $::heat::params::engine_package_name,
}

if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}

service { 'heat-engine':
Expand Down
144 changes: 104 additions & 40 deletions spec/classes/heat_api_cfn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,127 @@
describe 'heat::api_cfn' do

let :params do
{
:bind_host => '127.0.0.1',
:bind_port => '1234',
:workers => '0'
}
{ :enabled => true,
:manage_service => true,
:bind_host => '127.0.0.1',
:bind_port => '1234',
:workers => '0' }
end

let :facts do
{ :osfamily => 'Debian' }
end
shared_examples_for 'heat-api-cfn' do

context 'config params' do
context 'config params' do

it { should contain_class('heat') }
it { should contain_class('heat::params') }
it { should contain_class('heat') }
it { should contain_class('heat::params') }

it { should contain_heat_config('heat_api_cfn/bind_host').with_value( params[:bind_host] ) }
it { should contain_heat_config('heat_api_cfn/bind_port').with_value( params[:bind_port] ) }
it { should contain_heat_config('heat_api_cfn/workers').with_value( params[:workers] ) }
it { should contain_heat_config('heat_api_cfn/bind_host').with_value( params[:bind_host] ) }
it { should contain_heat_config('heat_api_cfn/bind_port').with_value( params[:bind_port] ) }
it { should contain_heat_config('heat_api_cfn/workers').with_value( params[:workers] ) }

end
end

context 'with SSL socket options set' do
let :params do
{
:use_ssl => true,
:cert_file => '/path/to/cert',
:key_file => '/path/to/key'
}
end

it { should contain_heat_config('heat_api_cfn/cert_file').with_value('/path/to/cert') }
it { should contain_heat_config('heat_api_cfn/key_file').with_value('/path/to/key') }
end

context 'with SSL socket options set with wrong parameters' do
let :params do
{
:use_ssl => true,
: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,
:cert_file => false,
:key_file => false
}
end

it { should contain_heat_config('heat_api_cfn/cert_file').with_ensure('absent') }
it { should contain_heat_config('heat_api_cfn/key_file').with_ensure('absent') }
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 heat-api-cfn service' do

context 'with SSL socket options set' do
let :params do
{
:use_ssl => true,
:cert_file => '/path/to/cert',
:key_file => '/path/to/key'
}
should contain_service('heat-api-cfn').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:name => platform_params[:api_service_name],
:enable => params[:enabled],
:hasstatus => true,
:hasrestart => true,
:subscribe => ['Exec[heat-dbsync]']
)
end
end
end

it { should contain_heat_config('heat_api_cfn/cert_file').with_value('/path/to/cert') }
it { should contain_heat_config('heat_api_cfn/key_file').with_value('/path/to/key') }
context 'with disabled service managing' do
before do
params.merge!({
:manage_service => false,
:enabled => false })
end

it 'configures heat-api-cfn service' do

should contain_service('heat-api-cfn').with(
:ensure => nil,
:name => platform_params[:api_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:subscribe => ['Exec[heat-dbsync]']
)
end
end
end

context 'with SSL socket options set with wrong parameters' do
let :params do
{
:use_ssl => true,
:key_file => '/path/to/key'
}

context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end

let :platform_params do
{ :api_service_name => 'heat-api-cfn' }
end

it_raises 'a Puppet::Error', /The cert_file parameter is required when use_ssl is set to true/
it_configures 'heat-api-cfn'
end

context 'with SSL socket options set to false' do
let :params do
{
:use_ssl => false,
:cert_file => false,
:key_file => false
}
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end

let :platform_params do
{ :api_service_name => 'openstack-heat-api-cfn' }
end

it { should contain_heat_config('heat_api_cfn/cert_file').with_ensure('absent') }
it { should contain_heat_config('heat_api_cfn/key_file').with_ensure('absent') }
it_configures 'heat-api-cfn'
end

end
Loading

0 comments on commit 493fbb4

Please sign in to comment.