Skip to content

Commit 7c1cf9b

Browse files
committed
Merge pull request #31 from fcharlier/dispersion
Add swift-dispersion configuration
2 parents 8ccb51b + 2bdc710 commit 7c1cf9b

File tree

5 files changed

+296
-0
lines changed

5 files changed

+296
-0
lines changed

manifests/dispersion.pp

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# == Class: swift::dispersion
2+
#
3+
# This class creates a configuration file for swift-dispersion-report and
4+
# and swift-dispersion-populate tools.
5+
#
6+
# These tools need access to all the storage nodes and are generally ran
7+
# on the swift proxy node.
8+
#
9+
# For more details, see :
10+
# http://swift.openstack.org/admin_guide.html#cluster-health
11+
#
12+
# === Parameters
13+
#
14+
# [*auth_url*]
15+
# String. The full URL to the authentication endpoint (eg. keystone)
16+
# Optional. Defaults to '127.0.0.1'.
17+
# [*auth_user*]
18+
# String. The Swift username to use to run the tools.
19+
# Optional. Defaults to 'dispersion'.
20+
# [*auth_tenant*]
21+
# String. The user's tenant/project.
22+
# Optional. Defaults to 'services'.
23+
# [*auth_pass*]
24+
# String. The user's password.
25+
# Optional. Defaults to 'dispersion_password'.
26+
# [*auth_version*]
27+
# String. The version to pass to the 'swift' command.
28+
# Use '2.0' when using Keystone.
29+
# Optional. Defaults to '2.0'
30+
# [*swift_dir*]
31+
# String. The path to swift configuration folder
32+
# Optional. Defaults to '/etc/swift'.
33+
# [*coverage*]
34+
# Integer. The percentage of partitions to cover.
35+
# Optional. Defaults to 1
36+
# [*retries*]
37+
# Integer. Number of retries.
38+
# Optional. Defaults to 5.
39+
# [*concurrency*]
40+
# Integer. Process concurrency.
41+
# Optional. Defaults to 25.
42+
# [*dump_json*]
43+
# 'yes' or 'no'. Should 'swift-dispersion-report' dump json results ?
44+
# Optional. Defaults to no.
45+
#
46+
# === Note
47+
#
48+
# Note: if using swift < 1.5.0, swift-dispersion-report and
49+
# swift-dispersion-populate might need to be patched with
50+
# https://github.com/openstack/swift/commit/9a423d0b78a105caf6011c6c3450f7d75d20b5a1
51+
#
52+
# === Authors
53+
#
54+
# François Charlier [email protected]
55+
#
56+
57+
class swift::dispersion (
58+
$auth_url = 'http://127.0.0.1:5000/v2.0/',
59+
$auth_user = 'dispersion',
60+
$auth_tenant = 'services',
61+
$auth_pass = 'dispersion_password',
62+
$auth_version = '2.0',
63+
$swift_dir = '/etc/swift',
64+
$coverage = 1,
65+
$retries = 5,
66+
$concurrency = 25,
67+
$dump_json = 'no'
68+
) {
69+
70+
include swift::params
71+
72+
file { '/etc/swift/dispersion.conf':
73+
ensure => present,
74+
content => template('swift/dispersion.conf.erb'),
75+
owner => 'swift',
76+
group => 'swift',
77+
mode => '0660',
78+
require => Package['swift'],
79+
}
80+
81+
exec { 'swift-dispersion-populate':
82+
path => ['/bin', '/usr/bin'],
83+
subscribe => File['/etc/swift/dispersion.conf'],
84+
timeout => 0,
85+
onlyif => "swift -A ${auth_url} -U ${auth_tenant}:${auth_user} -K ${auth_pass} -V ${auth_version} stat | grep 'Account: '",
86+
unless => "swift -A ${auth_url} -U ${auth_tenant}:${auth_user} -K ${auth_pass} -V ${auth_version} list | grep dispersion_",
87+
}
88+
89+
}

manifests/keystone/dispersion.pp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# == Class: swift::keystone::dispersion
2+
#
3+
# This class creates a user in Keystone for the swift-dispersion-report
4+
# and swift-dispersion-populate tools.
5+
#
6+
# The user is given the admin role in the services tenant.
7+
#
8+
# Use the class swift::dispersion to create the matching config file.
9+
#
10+
# === Parameters
11+
#
12+
# [*auth_user*]
13+
# String. The name of the user.
14+
# Optional. Defaults to 'dispersion'.
15+
#
16+
# [*auth_pass*]
17+
# String. The user's password.
18+
# Optional. Defaults to 'dispersion_password'.
19+
#
20+
# === Authors
21+
#
22+
# François Charlier [email protected]
23+
#
24+
25+
class swift::keystone::dispersion(
26+
$auth_user = 'dispersion',
27+
$auth_pass = 'dispersion_password'
28+
) {
29+
30+
keystone_user { $auth_user:
31+
ensure => present,
32+
password => $auth_pass,
33+
}
34+
35+
keystone_user_role { "${auth_user}@services":
36+
ensure => present,
37+
roles => 'admin',
38+
require => Keystone_user[$auth_user]
39+
}
40+
}

spec/classes/swift_dispersion_spec.rb

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
require 'spec_helper'
2+
3+
describe 'swift::dispersion' do
4+
5+
let :facts do
6+
{ :osfamily => 'Debian' }
7+
end
8+
9+
it { should contain_file('/etc/swift/dispersion.conf').with(
10+
:ensure => 'present',
11+
:owner => 'swift',
12+
:group => 'swift',
13+
:mode => '0660',
14+
:require => 'Package[swift]')
15+
}
16+
17+
describe 'with default parameters' do
18+
it { should contain_file('/etc/swift/dispersion.conf') \
19+
.with_content(/^\[dispersion\]$/)
20+
}
21+
it { should contain_file('/etc/swift/dispersion.conf') \
22+
.with_content(/^auth_url = http:\/\/127.0.0.1:5000\/v2.0\/$/)
23+
}
24+
it { should contain_file('/etc/swift/dispersion.conf') \
25+
.with_content(/^auth_version = 2.0$/)
26+
}
27+
it { should contain_file('/etc/swift/dispersion.conf') \
28+
.with_content(/^auth_user = services:dispersion$/)
29+
}
30+
it { should contain_file('/etc/swift/dispersion.conf') \
31+
.with_content(/^auth_key = dispersion_password$/)
32+
}
33+
it { should contain_file('/etc/swift/dispersion.conf') \
34+
.with_content(/^swift_dir = \/etc\/swift$/)
35+
}
36+
it { should contain_file('/etc/swift/dispersion.conf') \
37+
.with_content(/^dispersion_coverage = 1$/)
38+
}
39+
it { should contain_file('/etc/swift/dispersion.conf') \
40+
.with_content(/^retries = 5$/)
41+
}
42+
it { should contain_file('/etc/swift/dispersion.conf') \
43+
.with_content(/^concurrency = 25$/)
44+
}
45+
it { should contain_file('/etc/swift/dispersion.conf') \
46+
.with_content(/^dump_json = no$/)
47+
}
48+
it { should contain_exec('swift-dispersion-populate').with(
49+
:path => ['/bin', '/usr/bin'],
50+
:subscribe => 'File[/etc/swift/dispersion.conf]',
51+
:onlyif => "swift -A http://127.0.0.1:5000/v2.0/ -U services:dispersion -K dispersion_password -V 2.0 stat | grep 'Account: '",
52+
:unless => "swift -A http://127.0.0.1:5000/v2.0/ -U services:dispersion -K dispersion_password -V 2.0 list | grep dispersion_"
53+
)}
54+
end
55+
56+
describe 'when parameters are overriden' do
57+
let :params do
58+
{
59+
:auth_url => 'https://169.254.0.1:7000/auth/v8.0/',
60+
:auth_user => 'foo',
61+
:auth_tenant => 'bar',
62+
:auth_pass => 'dummy',
63+
:auth_version => '1.0',
64+
:swift_dir => '/usr/local/etc/swift',
65+
:coverage => 42,
66+
:retries => 51,
67+
:concurrency => 4682,
68+
:dump_json => 'yes'
69+
}
70+
end
71+
it { should contain_file('/etc/swift/dispersion.conf') \
72+
.with_content(/^\[dispersion\]$/)
73+
}
74+
it { should contain_file('/etc/swift/dispersion.conf') \
75+
.with_content(/^auth_url = https:\/\/169.254.0.1:7000\/auth\/v8.0\/$/)
76+
}
77+
it { should contain_file('/etc/swift/dispersion.conf') \
78+
.with_content(/^auth_version = 1.0$/)
79+
}
80+
it { should contain_file('/etc/swift/dispersion.conf') \
81+
.with_content(/^auth_user = bar:foo$/)
82+
}
83+
it { should contain_file('/etc/swift/dispersion.conf') \
84+
.with_content(/^auth_key = dummy$/)
85+
}
86+
it { should contain_file('/etc/swift/dispersion.conf') \
87+
.with_content(/^swift_dir = \/usr\/local\/etc\/swift$/)
88+
}
89+
it { should contain_file('/etc/swift/dispersion.conf') \
90+
.with_content(/^dispersion_coverage = 42$/)
91+
}
92+
it { should contain_file('/etc/swift/dispersion.conf') \
93+
.with_content(/^retries = 51$/)
94+
}
95+
it { should contain_file('/etc/swift/dispersion.conf') \
96+
.with_content(/^concurrency = 4682$/)
97+
}
98+
it { should contain_file('/etc/swift/dispersion.conf') \
99+
.with_content(/^dump_json = yes$/)
100+
}
101+
it { should contain_exec('swift-dispersion-populate').with(
102+
:path => ['/bin', '/usr/bin'],
103+
:subscribe => 'File[/etc/swift/dispersion.conf]',
104+
:onlyif => "swift -A https://169.254.0.1:7000/auth/v8.0/ -U bar:foo -K dummy -V 1.0 stat | grep 'Account: '",
105+
:unless => "swift -A https://169.254.0.1:7000/auth/v8.0/ -U bar:foo -K dummy -V 1.0 list | grep dispersion_"
106+
)}
107+
end
108+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require 'spec_helper'
2+
3+
describe 'swift::keystone::dispersion' do
4+
5+
describe 'with default class parameters' do
6+
7+
it { should contain_keystone_user('dispersion').with(
8+
:ensure => 'present',
9+
:password => 'dispersion_password'
10+
) }
11+
12+
it { should contain_keystone_user_role('dispersion@services').with(
13+
:ensure => 'present',
14+
:roles => 'admin',
15+
:require => 'Keystone_user[dispersion]'
16+
) }
17+
end
18+
19+
describe 'when overriding password' do
20+
21+
let :params do
22+
{
23+
:auth_pass => 'foo'
24+
}
25+
end
26+
27+
it { should contain_keystone_user('dispersion').with(
28+
:ensure => 'present',
29+
:password => 'foo'
30+
) }
31+
32+
end
33+
34+
describe 'when overriding auth user' do
35+
36+
let :params do
37+
{
38+
:auth_user => 'bar'
39+
}
40+
end
41+
42+
it { should contain_keystone_user('bar') }
43+
44+
it { should contain_keystone_user_role('bar@services') }
45+
46+
end
47+
48+
end

templates/dispersion.conf.erb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[dispersion]
2+
auth_url = <%= auth_url %>
3+
auth_version = <%= auth_version %>
4+
auth_user = <%= auth_tenant %>:<%= auth_user %>
5+
auth_key = <%= auth_pass %>
6+
swift_dir = <%= swift_dir %>
7+
dispersion_coverage = <%= coverage %>
8+
retries = <%= retries %>
9+
concurrency = <%= concurrency %>
10+
dump_json = <%= dump_json %>
11+

0 commit comments

Comments
 (0)