Skip to content

Commit 59afc07

Browse files
author
Dan Bode
committedApr 21, 2012
Refactor of swift server configs
This commit performs a refactor of the swift::storage::config to use fragments. Updates server templates - makes workers,user, and mount_checks configurable - adds a default for concurrency - makes the pipeline configurable - remove vm_test_mode flag Updates swift::storage::server to use fragments for the config file. This has been refactored to allow the end user a greater level of flexibility over how they can configure custom plugins for swift. Also adds additional class params: pipeline, mount_check, user, workers, concurrency. Update the unit tests for swift::storage:server
1 parent aaf2784 commit 59afc07

7 files changed

+132
-76
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ spec/fixtures/modules/rsync
44
spec/fixtures/modules/ssh
55
spec/fixtures/modules/stdlib
66
spec/fixtures/modules/xinetd
7+
spec/fixtures/modules/*

‎manifests/storage/server.pp

+26-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@
66
define swift::storage::server(
77
$type,
88
$storage_local_net_ip,
9-
$devices = '/srv/node',
10-
$owner = 'swift',
11-
$group = 'swift',
12-
$max_connections = 25,
9+
$devices = '/srv/node',
10+
$owner = 'swift',
11+
$group = 'swift',
12+
$max_connections = 25,
13+
$pipeline = ["${type}-server"],
14+
$mount_check = 'false',
15+
$user = 'swift',
16+
$workers = '1',
17+
$concurrency = $::processorcount,
1318
# this parameters needs to be specified after type and name
1419
$config_file_path = "${type}-server/${name}.conf"
1520
) {
1621

22+
# TODO if array does not include type-server, warn
23+
if(
24+
(is_array($pipeline) and ! member($pipeline, "${type}-server")) or
25+
$pipline != "${type}-server"
26+
) {
27+
warning("swift storage server ${type} must specify ${type}-server")
28+
}
29+
1730
include "swift::storage::$type"
31+
include 'concat::setup'
1832

1933
validate_re($name, '^\d+$')
2034
validate_re($type, '^object|container|account$')
@@ -31,11 +45,17 @@
3145
read_only => false,
3246
}
3347

34-
file { "/etc/swift/${config_file_path}":
35-
content => template("swift/${type}-server.conf.erb"),
48+
concat { "/etc/swift/${config_file_path}":
3649
owner => $owner,
3750
group => $group,
3851
notify => Service["swift-${type}"],
52+
mode => 640,
3953
}
4054

55+
# you can now add your custom fragments at the user level
56+
concat::fragment { "swift-${type}-${name}":
57+
target => "/etc/swift/${config_file_path}",
58+
content => template("swift/${type}-server.conf.erb"),
59+
order => '00',
60+
}
4161
}

‎spec/defines/swift_storage_server_spec.rb

+85-55
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
let :facts do
55
{
66
:operatingsystem => 'Ubuntu',
7-
:osfamily => 'Debian'
7+
:osfamily => 'Debian',
8+
:processorcount => 1
89
}
910

1011
end
@@ -21,8 +22,6 @@ class { 'swift::storage': storage_local_net_ip => '10.0.0.1' }"
2122
:max_connections => '25'}
2223
end
2324

24-
25-
2625
describe 'with an invalid title' do
2726
let :params do
2827
{:storage_local_net_ip => '127.0.0.1',
@@ -39,66 +38,97 @@ class { 'swift::storage': storage_local_net_ip => '10.0.0.1' }"
3938
end
4039

4140
['account', 'object', 'container'].each do |t|
42-
[{:storage_local_net_ip => '10.0.0.1',
43-
:type => t},
44-
{:storage_local_net_ip => '127.0.0.1',
45-
:type => t}
46-
].each do |param_set|
47-
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
48-
let :title do
49-
'8000'
50-
end
51-
let :param_hash do
52-
default_params.merge(param_set)
41+
42+
describe "for type #{t}" do
43+
44+
let :title do
45+
'8000'
46+
end
47+
48+
let :req_params do
49+
{:storage_local_net_ip => '10.0.0.1', :type => t}
50+
end
51+
let :params do
52+
req_params
53+
end
54+
55+
it { should contain_package("swift-#{t}").with_ensure('present') }
56+
it { should contain_service("swift-#{t}").with(
57+
:ensure => 'running',
58+
:enable => true,
59+
:hasstatus => true
60+
)}
61+
let :fragment_file do
62+
"/var/lib/puppet/concat/_etc_swift_#{t}-server_#{title}.conf/fragments/00_swift-#{t}-#{title}"
63+
end
64+
65+
describe 'when parameters are overridden' do
66+
{
67+
:devices => '/tmp/foo',
68+
:user => 'dan',
69+
:mount_check => true,
70+
:concurrency => 5,
71+
:workers => 7,
72+
:pipeline => 'foo'
73+
}.each do |k,v|
74+
describe "when #{k} is set" do
75+
let :params do req_params.merge({k => v}) end
76+
it { should contain_file(fragment_file) \
77+
.with_content(/^#{k.to_s}\s*=\s*#{v}\s*$/)
78+
}
79+
end
80+
describe "when pipline is passed an array" do
81+
let :params do req_params.merge({:pipeline => [1,2,3]}) end
82+
it { should contain_file(fragment_file) \
83+
.with_content(/^pipeline\s*=\s*1 2 3\s*$/)
84+
}
85+
end
5386
end
87+
end
88+
89+
describe 'with all allowed defaults' do
5490
let :params do
55-
param_set
91+
req_params
5692
end
57-
let :config_file_path do
58-
"#{t}-server/#{title}.conf"
59-
end
60-
it { should contain_package("swift-#{t}").with_ensure('present') }
61-
it { should contain_service("swift-#{t}").with(
62-
:ensure => 'running',
63-
:enable => true,
64-
:hasstatus => true
65-
)}
66-
it { should contain_file("/etc/swift/#{t}-server/").with(
67-
:ensure => 'directory',
68-
:owner => 'swift',
69-
:group => 'swift'
70-
)}
93+
7194
it { should contain_rsync__server__module("#{t}#{title}").with(
72-
:path => param_hash[:devices],
95+
:path => '/srv/node',
7396
:lock_file => "/var/lock/#{t}#{title}.lock",
74-
:uid => param_hash[:owner],
75-
:gid => param_hash[:group],
76-
:max_connections => param_hash[:max_connections],
97+
:uid => 'swift',
98+
:gid => 'swift',
99+
:max_connections => 25,
77100
:read_only => false
78101
)}
79-
it { should contain_file("/etc/swift/#{config_file_path}").with(
80-
:owner => param_hash[:owner],
81-
:group => param_hash[:group]
82-
)}
83-
it 'should have some contents' do
84-
content = param_value(
85-
subject,
86-
'file', "/etc/swift/#{config_file_path}",
87-
'content'
88-
)
89-
expected_lines =
90-
[
91-
'[DEFAULT]',
92-
"devices = #{param_hash[:devices]}",
93-
"bind_ip = #{param_hash[:storage_local_net_ip]}",
94-
"bind_port = #{title}"
95-
]
96-
(content.split("\n") & expected_lines).should =~ expected_lines
97-
end
98-
end
99102

100-
# TODO - I do not want to add tests for the upstart stuff
101-
# I need to check the tickets and see if this stuff is fixed
103+
# verify template lines
104+
it { should contain_file(fragment_file) \
105+
.with_content(/^devices\s*=\s*\/srv\/node\s*$/)
106+
}
107+
it { should contain_file(fragment_file) \
108+
.with_content(/^bind_ip\s*=\s*10\.0\.0\.1\s*$/)
109+
}
110+
it { should contain_file(fragment_file) \
111+
.with_content(/^bind_port\s*=\s*#{title}\s*$/)
112+
}
113+
it { should contain_file(fragment_file) \
114+
.with_content(/^mount_check\s*=\s*false\s*$/)
115+
}
116+
it { should contain_file(fragment_file) \
117+
.with_content(/^user\s*=\s*swift\s*$/)
118+
}
119+
it { should contain_file(fragment_file) \
120+
.with_content(/^log_facility\s*=\s*LOG_LOCAL2\s*$/)
121+
}
122+
it { should contain_file(fragment_file) \
123+
.with_content(/^workers\s*=\s*1\s*$/)
124+
}
125+
it { should contain_file(fragment_file) \
126+
.with_content(/^concurrency\s*=\s*1\s*$/)
127+
}
128+
it { should contain_file(fragment_file) \
129+
.with_content(/^pipeline\s*=\s*#{t}-server\s*$/)
130+
}
131+
end
102132
end
103133
end
104134
end

‎spec/spec_helper.rb

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ def param_value(subject, type, title, param)
66
subject.resource(type, title).send(:parameters)[param.to_sym]
77
end
88

9+
def verify_contents(subject, title, expected_lines)
10+
content = subject.resource('file', title).send(:parameters)[:content]
11+
(content.split("\n") & expected_lines).should == expected_lines
12+
end
13+
914
RSpec.configure do |c|
1015
c.module_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/modules'))
1116
# Using an empty site.pp file to avoid: https://github.com/rodjek/rspec-puppet/issues/15

‎templates/account-server.conf.erb

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
devices = <%= devices %>
33
bind_ip = <%= storage_local_net_ip %>
44
bind_port = <%= bind_port %>
5-
mount_check = false
6-
user = swift
5+
mount_check = <%= mount_check %>
6+
user = <%= user %>
77
log_facility = LOG_LOCAL2
8-
workers = 2
8+
workers = <%= workers %>
9+
concurrency = <%= concurrency %>
910

1011
[pipeline:main]
11-
pipeline = account-server
12+
pipeline = <%= pipeline.to_a.join(' ') %>
1213

1314
[app:account-server]
1415
use = egg:swift#account
1516

1617
[account-replicator]
17-
vm_test_mode = yes
1818

1919
[account-auditor]
2020

‎templates/container-server.conf.erb

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
devices = <%= devices %>
33
bind_ip = <%= storage_local_net_ip %>
44
bind_port = <%= bind_port %>
5-
mount_check = false
6-
user = swift
5+
mount_check = <%= mount_check %>
6+
user = <%= user %>
77
log_facility = LOG_LOCAL2
8-
workers = 2
8+
workers = <%= workers %>
9+
concurrency = <%= concurrency %>
910

1011
[pipeline:main]
11-
pipeline = container-server
12+
pipeline = <%= pipeline.to_a.join(' ') %>
1213

1314
[app:container-server]
1415
use = egg:swift#container
1516

1617
[container-replicator]
17-
vm_test_mode = yes
1818

1919
[container-updater]
2020

‎templates/object-server.conf.erb

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
devices = <%= devices %>
33
bind_ip = <%= storage_local_net_ip %>
44
bind_port = <%= bind_port %>
5-
mount_check = false
6-
user = swift
5+
mount_check = <%= mount_check %>
6+
user = <%= user %>
77
log_facility = LOG_LOCAL2
8-
workers = 2
8+
workers = <%= workers %>
9+
concurrency = <%= concurrency %>
910

1011
[pipeline:main]
11-
pipeline = object-server
12+
pipeline = <%= pipeline.to_a.join(' ') %>
1213

1314
[app:object-server]
1415
use = egg:swift#object
1516

1617
[object-replicator]
17-
vm_test_mode = yes
1818

1919
[object-updater]
2020

0 commit comments

Comments
 (0)
Please sign in to comment.