Skip to content

Commit 4752a3d

Browse files
author
Dan Bode
committed
Decouple memcached configuration from proxy
It is possible that the memcache server(s) may reside on different machines than the swift proxy. This commit decouples the configurations of the two services.
1 parent c7caf05 commit 4752a3d

File tree

3 files changed

+177
-41
lines changed

3 files changed

+177
-41
lines changed

manifests/proxy.pp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
#
2+
# TODO - assumes that proxy server is always a memcached server
3+
#
4+
# TODO - the full list of all things that can be configured is here
5+
# https://github.com/openstack/swift/tree/master/swift/common/middleware
6+
#
17
# Installs and configures the swift proxy node.
28
#
39
# [*Parameters*]
410
#
5-
# [*allow_account_management*]
6-
# [*account_autocreate*] Rather accounts should automatically be created.
7-
# I think this may be tempauth specific
811
# [*proxy_local_net_ip*] The address that the proxy will bind to.
9-
# [*proxy_port*] Port that the swift proxy service will bind to.
10-
# Optional. Defaults to 11211
12+
# Required.
13+
# [*port*] The port to which the proxy server will bind.
14+
# Optional. Defaults to 8080.
15+
# [*workers*] Number of threads to process requests.
16+
# Optional. Defaults to the number of processors.
1117
# [*auth_type*] - Type of authorization to use.
1218
# valid values are tempauth, swauth, and keystone.
1319
# Optional. Defaults to tempauth.
20+
# [*allow_account_management*]
21+
# Rather or not requests through this proxy can create and
22+
# delete accounts. Optional. Defaults to true.
23+
# [*account_autocreate*] Rather accounts should automatically be created.
24+
# Has to be set to true for tempauth. Optional. Defaults to true.
25+
# [*proxy_port*] Port that the swift proxy service will bind to.
26+
# Optional. Defaults to 11211
1427
# [*package_ensure*] Ensure state of the swift proxy package.
1528
# Optional. Defaults to present.
16-
#
29+
# [*cache_servers*] A list of the memcache servers to be used. Entries
30+
# should be in the form host:port.
1731
# == sw auth specific configuration
1832
# [*swauth_endpoint*]
1933
# [*swauth_super_admin_user*]
@@ -33,21 +47,30 @@
3347
# Copyright 2011 Puppetlabs Inc, unless otherwise noted.
3448
#
3549
class swift::proxy(
36-
# why did cloudbuilders default this to false?
3750
$proxy_local_net_ip,
51+
$port = '8080',
52+
$workers = $::processorcount,
53+
$cache_servers = ['127.0.0.1:11211'],
3854
$allow_account_management = true,
39-
$account_autocreate = false,
40-
$proxy_port = '11211',
4155
$auth_type = 'tempauth',
56+
$account_autocreate = true,
4257
$swauth_endpoint = '127.0.0.1',
4358
$swauth_super_admin_key = 'swauthkey',
4459
$package_ensure = 'present'
4560
) inherits swift {
4661

47-
Class['memcached'] -> Class['swift::proxy']
48-
62+
validate_bool($account_autocreate)
63+
validate_bool($allow_account_management)
4964
validate_re($auth_type, 'tempauth|swauth|keystone')
5065

66+
if($auth_type == 'tempauth' and ! $account_autocreate ){
67+
fail("\$account_autocreate must be set to true when auth type is tempauth")
68+
}
69+
70+
if $cache_server_ips =~ /^127\.0\.0\.1/ {
71+
Class['memcached'] -> Class['swift::proxy']
72+
}
73+
5174
if(auth_type == 'keystone') {
5275
fail('Keystone is currently not supported, it should be supported soon :)')
5376
}

spec/classes/swift_proxy_spec.rb

Lines changed: 140 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ class { swift: swift_hash_suffix => string }
2929
class { 'ssh::server::install': }"
3030
end
3131

32-
describe 'with default parameters' do
32+
describe 'without the proxy local network ip address being specified' do
33+
it "should fail" do
34+
expect do
35+
subject
36+
end.should raise_error(Puppet::Error, /Must pass proxy_local_net_ip/)
37+
end
38+
end
3339

34-
let :config_file do
35-
File.join(fixture_dir, 'default_proxy_server')
40+
describe 'when proxy_local_net_ip is set' do
41+
42+
let :params do
43+
{:proxy_local_net_ip => '127.0.0.1'}
3644
end
3745

38-
it { should contain_package('swift-proxy').with_ensure('present') }
39-
it { should_not contain_package('python-swauth') }
4046
it { should contain_service('swift-proxy').with(
4147
{:ensure => 'running',
4248
:provider => 'upstart',
@@ -49,58 +55,167 @@ class { 'ssh::server::install': }"
4955
:owner => 'swift',
5056
:group => 'swift',
5157
:mode => '0660',
52-
:content => File.read(config_file),
5358
:require => 'Package[swift-proxy]'
5459
}
5560
)}
61+
62+
it 'should contain default config file' do
63+
content = param_value(
64+
subject,
65+
'file', '/etc/swift/proxy-server.conf',
66+
'content'
67+
)
68+
expected_lines =
69+
[
70+
'[DEFAULT]',
71+
'bind_port = 8080',
72+
"workers = #{facts[:processorcount]}",
73+
'user = swift',
74+
'[pipeline:main]',
75+
'pipeline = healthcheck cache tempauth proxy-server',
76+
'[app:proxy-server]',
77+
'use = egg:swift#proxy',
78+
'allow_account_management = true',
79+
'account_autocreate = true',
80+
'[filter:healthcheck]',
81+
'use = egg:swift#healthcheck',
82+
'[filter:cache]',
83+
'use = egg:swift#memcache',
84+
'memcache_servers = 127.0.0.1:11211'
85+
]
86+
(content.split("\n") & expected_lines).should =~ expected_lines
87+
end
88+
89+
describe 'when more parameters are set' do
90+
let :params do
91+
{
92+
:proxy_local_net_ip => '10.0.0.2',
93+
:port => '80',
94+
:workers => 3,
95+
:cache_servers => ['foo:1', 'bar:2'],
96+
:allow_account_management => true
97+
}
98+
end
99+
it 'should contain default config file' do
100+
content = param_value(
101+
subject,
102+
'file', '/etc/swift/proxy-server.conf',
103+
'content'
104+
)
105+
expected_lines =
106+
[
107+
'bind_port = 80',
108+
"workers = 3",
109+
'allow_account_management = true',
110+
'memcache_servers = foo:1,bar:2'
111+
]
112+
(content.split("\n") & expected_lines).should =~ expected_lines
113+
end
114+
end
56115
# TODO this resource should just be here temporarily until packaging
57116
# is fixed
58117
it { should contain_file('/etc/init/swift-proxy.conf') }
59118

119+
describe 'when using tempauth' do
120+
121+
it { should_not contain_package('python-swauth') }
122+
it 'should fail when setting account_autocreate to false' do
123+
params[:auth_type] = 'tempauth'
124+
params[:account_autocreate] = false
125+
expect do
126+
subject
127+
end.should raise_error(Puppet::Error, /account_autocreate must be set to true when auth type is tempauth/)
128+
end
129+
it 'should contain tempauth configuration' do
130+
content = param_value(
131+
subject,
132+
'file', '/etc/swift/proxy-server.conf',
133+
'content'
134+
)
135+
expected_lines =
136+
[
137+
'pipeline = healthcheck cache tempauth proxy-server',
138+
'[filter:tempauth]',
139+
'use = egg:swift#tempauth',
140+
'user_admin_admin = admin .admin .reseller_admin',
141+
'user_test_tester = testing .admin',
142+
'user_test2_tester2 = testing2 .admin',
143+
'user_test_tester3 = testing3'
144+
]
145+
(content.split("\n") & expected_lines).should =~ expected_lines
146+
end
147+
end
148+
149+
describe 'when supplying bad values for parameters' do
150+
[:account_autocreate, :allow_account_management].each do |param|
151+
it "should fail when #{param} is not passed a boolean" do
152+
params[param] = 'false'
153+
expect do
154+
subject
155+
end.should raise_error(Puppet::Error, /is not a boolean/)
156+
end
157+
end
158+
end
60159
end
61160

62161
describe 'when using swauth' do
63162

64163
let :params do
65-
{:auth_type => 'swauth' }
164+
{:proxy_local_net_ip => '127.0.0.1',
165+
:auth_type => 'swauth' }
66166
end
67167

68168
describe 'with defaults' do
69169

70-
let :config_file do
71-
File.join(fixture_dir, 'swauth_default_proxy_server')
72-
end
73-
74170
it { should contain_package('python-swauth').with(
75171
{:ensure => 'present',
76172
:before => 'Package[swift-proxy]'
77173
}
78174
)}
79-
it { should contain_file('/etc/swift/proxy-server.conf').with(
80-
{:content => File.read(config_file)}
81-
)}
175+
it 'should create a config file with default swauth config' do
176+
content = param_value(
177+
subject,
178+
'file', '/etc/swift/proxy-server.conf',
179+
'content'
180+
)
181+
expected_lines =
182+
[
183+
'[filter:swauth]',
184+
'use = egg:swauth#swauth',
185+
'default_swift_cluster = local#127.0.0.1',
186+
'super_admin_key = swauthkey'
187+
]
188+
(content.split("\n") & expected_lines).should =~ expected_lines
189+
190+
end
82191
end
83192

84193
describe 'with parameter overrides' do
85194

86195
let :params do
87-
{:auth_type => 'swauth',
196+
{:proxy_local_net_ip => '127.0.0.1',
197+
:auth_type => 'swauth',
88198
:swauth_endpoint => '10.0.0.1',
89199
:swauth_super_admin_key => 'key'
90200
}
91201
end
92-
let :config_file do
93-
File.join(fixture_dir, 'swauth_overrides_proxy_server')
94-
end
95-
96-
it { should contain_file('/etc/swift/proxy-server.conf').with(
97-
{:content => File.read(config_file)}
98-
)}
99202

203+
it 'should create a config file with default swauth config' do
204+
content = param_value(
205+
subject,
206+
'file', '/etc/swift/proxy-server.conf',
207+
'content'
208+
)
209+
expected_lines =
210+
[
211+
'[filter:swauth]',
212+
'use = egg:swauth#swauth',
213+
'default_swift_cluster = local#10.0.0.1',
214+
'super_admin_key = key'
215+
]
216+
(content.split("\n") & expected_lines).should =~ expected_lines
217+
end
100218
end
101-
102219
end
103-
104220
end
105-
106221
end

templates/proxy-server.conf.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# This file is managed by puppet. Do not edit
22
#
33
[DEFAULT]
4-
#cert_file = /etc/swift/cert.crt
5-
#key_file = /etc/swift/cert.key
6-
bind_port = 8080
7-
workers = 8
4+
bind_port = <%= port %>
5+
workers = <%= workers %>
86
user = swift
97

108
[pipeline:main]
@@ -37,4 +35,4 @@ use = egg:swift#healthcheck
3735
[filter:cache]
3836
use = egg:swift#memcache
3937
# multi-proxy config not supported
40-
memcache_servers = <%= proxy_local_net_ip %>:<%= proxy_port %>
38+
memcache_servers = <%= cache_servers.to_a.join(',') %>

0 commit comments

Comments
 (0)