Skip to content

Commit 493fbb4

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add manage_service feature"
2 parents 1ba121c + 2ee5496 commit 493fbb4

8 files changed

Lines changed: 399 additions & 141 deletions

File tree

manifests/api.pp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Installs & configure the heat API service
2-
2+
#
3+
# == Parameters
4+
# [*enabled*]
5+
# (optional) Should the service be enabled.
6+
# Defaults to true
7+
#
8+
# [*manage_service*]
9+
# (optional) Whether the service should be managed by Puppet.
10+
# Defaults to true.
11+
#
312
class heat::api (
13+
$manage_service = true,
414
$enabled = true,
515
$bind_host = '0.0.0.0',
616
$bind_port = '8004',
@@ -32,10 +42,12 @@
3242
name => $::heat::params::api_package_name,
3343
}
3444

35-
if $enabled {
36-
$service_ensure = 'running'
37-
} else {
38-
$service_ensure = 'stopped'
45+
if $manage_service {
46+
if $enabled {
47+
$service_ensure = 'running'
48+
} else {
49+
$service_ensure = 'stopped'
50+
}
3951
}
4052

4153
service { 'heat-api':

manifests/api_cfn.pp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Installs & configure the heat CloudFormation API service
2-
2+
#
3+
# == Parameters
4+
# [*enabled*]
5+
# (optional) Should the service be enabled.
6+
# Defaults to true
7+
#
8+
# [*manage_service*]
9+
# (optional) Whether the service should be managed by Puppet.
10+
# Defaults to true.
11+
#
312
class heat::api_cfn (
13+
$manage_service = true,
414
$enabled = true,
515
$bind_host = '0.0.0.0',
616
$bind_port = '8000',
@@ -32,10 +42,12 @@
3242
name => $::heat::params::api_cfn_package_name,
3343
}
3444

35-
if $enabled {
36-
$service_ensure = 'running'
37-
} else {
38-
$service_ensure = 'stopped'
45+
if $manage_service {
46+
if $enabled {
47+
$service_ensure = 'running'
48+
} else {
49+
$service_ensure = 'stopped'
50+
}
3951
}
4052

4153
Package['heat-common'] -> Service['heat-api-cfn']

manifests/api_cloudwatch.pp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Installs & configure the heat CloudWatch API service
2-
2+
#
3+
# == Parameters
4+
# [*enabled*]
5+
# (optional) Should the service be enabled.
6+
# Defaults to true
7+
#
8+
# [*manage_service*]
9+
# (optional) Whether the service should be managed by Puppet.
10+
# Defaults to true.
11+
#
312
class heat::api_cloudwatch (
13+
$manage_service = true,
414
$enabled = true,
515
$bind_host = '0.0.0.0',
616
$bind_port = '8003',
@@ -32,12 +42,15 @@
3242
name => $::heat::params::api_cloudwatch_package_name,
3343
}
3444

35-
if $enabled {
36-
$service_ensure = 'running'
37-
} else {
38-
$service_ensure = 'stopped'
45+
if $manage_service {
46+
if $enabled {
47+
$service_ensure = 'running'
48+
} else {
49+
$service_ensure = 'stopped'
50+
}
3951
}
4052

53+
4154
Package['heat-common'] -> Service['heat-api-cloudwatch']
4255

4356
service { 'heat-api-cloudwatch':

manifests/engine.pp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
#
55
# == parameters
66
# [*enabled*]
7-
# (optional) The state of the service
7+
# (optional) Should the service be enabled.
88
# Defaults to true
99
#
10+
# [*manage_service*]
11+
# (optional) Whether the service should be managed by Puppet.
12+
# Defaults to true.
13+
#
1014
# [*heat_stack_user_role*]
1115
# (optional) Keystone role for heat template-defined users
1216
# Defaults to 'heat_stack_user'
@@ -34,6 +38,7 @@
3438

3539
class heat::engine (
3640
$auth_encryption_key,
41+
$manage_service = true,
3742
$enabled = true,
3843
$heat_stack_user_role = 'heat_stack_user',
3944
$heat_metadata_server_url = 'http://127.0.0.1:8000',
@@ -53,10 +58,12 @@
5358
name => $::heat::params::engine_package_name,
5459
}
5560

56-
if $enabled {
57-
$service_ensure = 'running'
58-
} else {
59-
$service_ensure = 'stopped'
61+
if $manage_service {
62+
if $enabled {
63+
$service_ensure = 'running'
64+
} else {
65+
$service_ensure = 'stopped'
66+
}
6067
}
6168

6269
service { 'heat-engine':

spec/classes/heat_api_cfn_spec.rb

Lines changed: 104 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,127 @@
33
describe 'heat::api_cfn' do
44

55
let :params do
6-
{
7-
:bind_host => '127.0.0.1',
8-
:bind_port => '1234',
9-
:workers => '0'
10-
}
6+
{ :enabled => true,
7+
:manage_service => true,
8+
:bind_host => '127.0.0.1',
9+
:bind_port => '1234',
10+
:workers => '0' }
1111
end
1212

13-
let :facts do
14-
{ :osfamily => 'Debian' }
15-
end
13+
shared_examples_for 'heat-api-cfn' do
1614

17-
context 'config params' do
15+
context 'config params' do
1816

19-
it { should contain_class('heat') }
20-
it { should contain_class('heat::params') }
17+
it { should contain_class('heat') }
18+
it { should contain_class('heat::params') }
2119

22-
it { should contain_heat_config('heat_api_cfn/bind_host').with_value( params[:bind_host] ) }
23-
it { should contain_heat_config('heat_api_cfn/bind_port').with_value( params[:bind_port] ) }
24-
it { should contain_heat_config('heat_api_cfn/workers').with_value( params[:workers] ) }
20+
it { should contain_heat_config('heat_api_cfn/bind_host').with_value( params[:bind_host] ) }
21+
it { should contain_heat_config('heat_api_cfn/bind_port').with_value( params[:bind_port] ) }
22+
it { should contain_heat_config('heat_api_cfn/workers').with_value( params[:workers] ) }
2523

26-
end
24+
end
25+
26+
context 'with SSL socket options set' do
27+
let :params do
28+
{
29+
:use_ssl => true,
30+
:cert_file => '/path/to/cert',
31+
:key_file => '/path/to/key'
32+
}
33+
end
34+
35+
it { should contain_heat_config('heat_api_cfn/cert_file').with_value('/path/to/cert') }
36+
it { should contain_heat_config('heat_api_cfn/key_file').with_value('/path/to/key') }
37+
end
38+
39+
context 'with SSL socket options set with wrong parameters' do
40+
let :params do
41+
{
42+
:use_ssl => true,
43+
:key_file => '/path/to/key'
44+
}
45+
end
46+
47+
it_raises 'a Puppet::Error', /The cert_file parameter is required when use_ssl is set to true/
48+
end
49+
50+
context 'with SSL socket options set to false' do
51+
let :params do
52+
{
53+
:use_ssl => false,
54+
:cert_file => false,
55+
:key_file => false
56+
}
57+
end
58+
59+
it { should contain_heat_config('heat_api_cfn/cert_file').with_ensure('absent') }
60+
it { should contain_heat_config('heat_api_cfn/key_file').with_ensure('absent') }
61+
end
62+
63+
[{:enabled => true}, {:enabled => false}].each do |param_hash|
64+
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
65+
before do
66+
params.merge!(param_hash)
67+
end
68+
69+
it 'configures heat-api-cfn service' do
2770

28-
context 'with SSL socket options set' do
29-
let :params do
30-
{
31-
:use_ssl => true,
32-
:cert_file => '/path/to/cert',
33-
:key_file => '/path/to/key'
34-
}
71+
should contain_service('heat-api-cfn').with(
72+
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
73+
:name => platform_params[:api_service_name],
74+
:enable => params[:enabled],
75+
:hasstatus => true,
76+
:hasrestart => true,
77+
:subscribe => ['Exec[heat-dbsync]']
78+
)
79+
end
80+
end
3581
end
3682

37-
it { should contain_heat_config('heat_api_cfn/cert_file').with_value('/path/to/cert') }
38-
it { should contain_heat_config('heat_api_cfn/key_file').with_value('/path/to/key') }
83+
context 'with disabled service managing' do
84+
before do
85+
params.merge!({
86+
:manage_service => false,
87+
:enabled => false })
88+
end
89+
90+
it 'configures heat-api-cfn service' do
91+
92+
should contain_service('heat-api-cfn').with(
93+
:ensure => nil,
94+
:name => platform_params[:api_service_name],
95+
:enable => false,
96+
:hasstatus => true,
97+
:hasrestart => true,
98+
:subscribe => ['Exec[heat-dbsync]']
99+
)
100+
end
101+
end
39102
end
40103

41-
context 'with SSL socket options set with wrong parameters' do
42-
let :params do
43-
{
44-
:use_ssl => true,
45-
:key_file => '/path/to/key'
46-
}
104+
105+
context 'on Debian platforms' do
106+
let :facts do
107+
{ :osfamily => 'Debian' }
108+
end
109+
110+
let :platform_params do
111+
{ :api_service_name => 'heat-api-cfn' }
47112
end
48113

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

52-
context 'with SSL socket options set to false' do
53-
let :params do
54-
{
55-
:use_ssl => false,
56-
:cert_file => false,
57-
:key_file => false
58-
}
117+
context 'on RedHat platforms' do
118+
let :facts do
119+
{ :osfamily => 'RedHat' }
120+
end
121+
122+
let :platform_params do
123+
{ :api_service_name => 'openstack-heat-api-cfn' }
59124
end
60125

61-
it { should contain_heat_config('heat_api_cfn/cert_file').with_ensure('absent') }
62-
it { should contain_heat_config('heat_api_cfn/key_file').with_ensure('absent') }
126+
it_configures 'heat-api-cfn'
63127
end
64128

65129
end

0 commit comments

Comments
 (0)