Merge pull request #32 from bodepd/allow_multi_devices

Allow multiple devices per endpoint.
This commit is contained in:
Branan Purvine-Riley 2012-06-05 17:16:53 -07:00
commit 8ccb51bddb
12 changed files with 240 additions and 54 deletions

View File

@ -163,22 +163,19 @@ class role_swift_storage inherits role_swift {
# these exported resources write ring config
# resources into the database so that they can be
# consumed by the ringbuilder role
@@ring_object_device { "${swift_local_net_ip}:6000":
@@ring_object_device { "${swift_local_net_ip}:6000/1":
zone => $swift_zone,
device_name => 1,
weight => 1,
}
@@ring_container_device { "${swift_local_net_ip}:6001":
@@ring_container_device { "${swift_local_net_ip}:6001/1":
zone => $swift_zone,
device_name => 1,
weight => 1,
}
# TODO should device be changed to volume
@@ring_account_device { "${swift_local_net_ip}:6002":
@@ring_account_device { "${swift_local_net_ip}:6002/1":
zone => $swift_zone,
device_name => 1,
weight => 1,
}

View File

@ -0,0 +1,115 @@
#!/usr/bin/env ruby
#
# This is a script that uses
# instructions here: http://swift.openstack.org/howto_installmultinode.html
# Even though I expect this script will work with a wide range
# of swift versions, it is currently only tested with: 1.4.6
require 'open3'
require 'fileutils'
# connection variables
proxy_local_net_ip='127.0.0.1'
user='openstack:admin'
password='admin_password'
# headers for curl requests
user_header="-H 'X-Storage-User: #{user}'"
password_header="-H 'X-Storage-Pass: #{password}'"
get_cred_command="curl -k -v #{user_header} #{password_header} http://#{proxy_local_net_ip}:5000/v2.0/"
# verify that we can retrive credentials from our user
result_hash = {}
puts "getting credentials: #{get_cred_command}"
Open3.popen3(get_cred_command) do |stdin, stdout, stderr|
result_hash[:stderr] = stderr.read
result_hash[:stderr].split("\n").each do |line|
if line =~ /^< HTTP\/\d\.\d (\d\d\d)/
result_hash[:status_code]=$1
end
if line =~ /< X-Storage-Url: (http\S+)/
result_hash[:auth_url]=$1
end
if line =~ /< X-Storage-Token: (AUTH_\S+)/
result_hash[:auth_token]=$1
end
end
end
raise(Exception, "Call to get auth tokens failed:\n#{result_hash[:stderr]}") unless result_hash[:status_code] == '200'
# verify that the credentials are valid
auth_token_header="-H 'X-Auth-Token: #{result_hash[:auth_token]}'"
puts auth_token_header
get_account_head="curl -k -v #{auth_token_header} #{result_hash[:auth_url]}"
# what is the expected code?
puts "verifying connection auth: #{get_account_head}"
Open3.popen3(get_account_head) do |stdin, stdout, stderr|
#puts stdout.read
#puts stderr.read
end
swift_command_prefix="swift -A http://#{proxy_local_net_ip}:5000/v2.0/ -V 2 -U #{user} -K #{password}"
swift_test_command="#{swift_command_prefix} stat"
puts "Testing swift: #{swift_test_command}"
status_hash={}
Open3.popen3(swift_test_command) do |stdin, stdout, stderr|
status_hash[:stdout] = stdout.read
status_hash[:stderr] = stderr.read
status_hash[:stdout].split("\n").each do |line|
if line =~ /\s*Containers:\s+(\d+)/
status_hash[:containers] = $1
end
if line =~ /\s*Objects:\s+(\d+)/
status_hash[:objects] = $1
end
end
end
unless(status_hash[:containers] =~ /\d+/ and status_hash[:objects] =~ /\d+/)
raise(Exception, "Expected to find the number of containers/objects:\n#{status_hash[:stdout]}\n#{status_hash[:stderr]}")
else
puts "found containers/objects: #{status_hash[:containers]}/#{status_hash[:objects]}"
end
# test that we can upload something
File.open('/tmp/foo1', 'w') do |fh|
fh.write('test1')
end
container = 'my_container'
swift_upload_command="#{swift_command_prefix} upload #{container} /tmp/foo1"
puts "Uploading file to swift with command: #{swift_upload_command}"
Open3.popen3(swift_upload_command) do |stdin, stdout, stderr|
puts stdout.read
puts stderr.read
end
# test that we can download the thing that we uploaded
download_test_dir = '/tmp/test/downloadtest/'
FileUtils.rm_rf download_test_dir
FileUtils.mkdir_p download_test_dir
swift_download_command="#{swift_command_prefix} download #{container}"
puts "Downloading file with command: #{swift_download_command}"
Dir.chdir(download_test_dir) do
Open3.popen3(swift_download_command) do |stdin, stdout, stderr|
puts stdout.read
puts stderr.read
end
end
expected_file = File.join(download_test_dir, 'tmp', 'foo1')
if File.exists?(expected_file)
if File.read(expected_file) == 'test1'
puts "Dude!!!! It actually seems to work, we can upload and download files!!!!"
else
raise(Exception, "So close, but the contents of the downloaded file are not what I expected: Got: #{File.read(expected_file)}, expected: test1")
end
else
raise(Exception, "file #{expected_file} did not exist somehow, probably b/c swift is not installed correctly")
end

View File

@ -15,10 +15,9 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
if rows = swift_ring_builder(builder_file_path).split("\n")[4..-1]
rows.each do |row|
if row =~ /^\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+)\s+(\d+)\s+(-?\d+\.\d+)\s+(\S*)$/
object_hash["#{$3}:#{$4}"] = {
object_hash["#{$3}:#{$4}/#{$5}"] = {
:id => $1,
:zone => $2,
:device_name => $5,
:weight => $6,
:partitions => $7,
:balance => $8,
@ -46,13 +45,13 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
end
def create
[:zone, :device_name, :weight].each do |param|
[:zone, :weight].each do |param|
raise(Puppet::Error, "#{param} is required") unless resource[param]
end
swift_ring_builder(
builder_file_path,
'add',
"z#{resource[:zone]}-#{resource[:name]}/#{resource[:device_name]}",
"z#{resource[:zone]}-#{resource[:name]}",
resource[:weight]
)
end
@ -74,14 +73,6 @@ class Puppet::Provider::SwiftRingBuilder < Puppet::Provider
Puppet.warning('Setting zone is not yet supported, I am not even sure if it is supported')
end
def device_name
ring[resource[:name]][:device_name]
end
def device_name=(name)
Puppet.warning('I think it makes sense to set the name, it is just not yet supported')
end
def weight
ring[resource[:name]][:weight]
# get the weight

View File

@ -6,15 +6,15 @@ Puppet::Type.newtype(:ring_account_device) do
newparam(:name, :namevar => true) do
validate do |value|
address = value.split(':')
raise(Puppet::Error, "invalid name #{value}") unless address.size == 2
raise(Puppet::Error, "invalid name #{value}, should contain address:port/device") unless address.size == 2
port_device = address[1].split('/')
raise(Puppet::Error, "namevar should contain a device") unless port_device.size == 2
IPAddr.new(address[0])
end
end
newproperty(:zone)
newproperty(:device_name)
newproperty(:weight) do
munge do |value|
"%.2f" % value

View File

@ -6,15 +6,15 @@ Puppet::Type.newtype(:ring_container_device) do
newparam(:name, :namevar => true) do
validate do |value|
address = value.split(':')
raise(Puppet::Error, "invalid name #{value}") unless address.size == 2
raise(Puppet::Error, "invalid name #{value}, should contain address:port/device") unless address.size == 2
port_device = address[1].split('/')
raise(Puppet::Error, "namevar should contain a device") unless port_device.size == 2
IPAddr.new(address[0])
end
end
newproperty(:zone)
newproperty(:device_name)
newproperty(:weight) do
munge do |value|
"%.2f" % value

View File

@ -6,15 +6,15 @@ Puppet::Type.newtype(:ring_object_device) do
newparam(:name, :namevar => true) do
validate do |value|
address = value.split(':')
raise(Puppet::Error, "invalid name #{value}") unless address.size == 2
raise(Puppet::Error, "invalid name #{value}, should contain address:port/device") unless address.size == 2
port_device = address[1].split('/')
raise(Puppet::Error, "namevar should contain a device") unless port_device.size == 2
IPAddr.new(address[0])
end
end
newproperty(:zone)
newproperty(:device_name)
newproperty(:weight) do
munge do |value|
"%.2f" % value

View File

@ -5,7 +5,8 @@ describe 'swift::ringbuilder' do
{
:operatingsystem => 'Ubuntu',
:osfamily => 'Debian',
:processorcount => 1
:processorcount => 1,
:concat_basedir => '/tmp/foo'
}
end
describe 'when swift class is not included' do
@ -23,9 +24,11 @@ describe 'swift::ringbuilder' do
class { 'ssh::server::install': }"
end
it { should contain_swift__ringbuilder__rebalance('object') }
it { should contain_swift__ringbuilder__rebalance('account') }
it { should contain_swift__ringbuilder__rebalance('container') }
it 'should rebalance the ring for all ring types' do
should contain_swift__ringbuilder__rebalance('object')
should contain_swift__ringbuilder__rebalance('account')
should contain_swift__ringbuilder__rebalance('container')
end
describe 'with default parameters' do
['object', 'account', 'container'].each do |type|
@ -60,43 +63,42 @@ describe 'swift::ringbuilder' do
'class { memcached: max_memory => 1}
class { swift: swift_hash_suffix => string }
class { "ssh::server::install": }
ring_object_device { "127.0.0.1:6000":
ring_object_device { "127.0.0.1:6000/1":
zone => 1,
device_name => 1,
weight => 1,
}
ring_container_device { "127.0.0.1:6001":
ring_container_device { "127.0.0.1:6001/1":
zone => 2,
device_name => 1,
weight => 1,
}
ring_account_device { "127.0.0.1:6002":
ring_account_device { "127.0.0.1:6002/1":
zone => 3,
device_name => 1,
weight => 1,
}'
end
it { should contain_swift__ringbuilder__create('object').with(
{:before => 'Ring_object_device[127.0.0.1:6000]'}
)}
it { should contain_swift__ringbuilder__create('container').with(
{:before => 'Ring_container_device[127.0.0.1:6001]'}
)}
it { should contain_swift__ringbuilder__create('account').with(
{:before => 'Ring_account_device[127.0.0.1:6002]'}
)}
it { should contain_ring_object_device('127.0.0.1:6000').with(
it 'should set up all of the correct dependencies' do
should contain_swift__ringbuilder__create('object').with(
{:before => 'Ring_object_device[127.0.0.1:6000/1]'}
)
should contain_swift__ringbuilder__create('container').with(
{:before => 'Ring_container_device[127.0.0.1:6001/1]'}
)
should contain_swift__ringbuilder__create('account').with(
{:before => 'Ring_account_device[127.0.0.1:6002/1]'}
)
should contain_ring_object_device('127.0.0.1:6000/1').with(
{:notify => 'Swift::Ringbuilder::Rebalance[object]'}
)}
it { should contain_ring_container_device('127.0.0.1:6001').with(
)
should contain_ring_container_device('127.0.0.1:6001/1').with(
{:notify => 'Swift::Ringbuilder::Rebalance[container]'}
)}
it { should contain_ring_account_device('127.0.0.1:6002').with(
)
should contain_ring_account_device('127.0.0.1:6002/1').with(
{:notify => 'Swift::Ringbuilder::Rebalance[account]'}
)}
)
end
end
end
end

View File

@ -7,7 +7,8 @@ describe 'swift::storage::all' do
{
:concat_basedir => '/tmp/',
:operatingsystem => 'Ubuntu',
:osfamily => 'Debian'
:osfamily => 'Debian',
:concat_basedir => '/tmp/foo'
}
end
@ -113,7 +114,8 @@ describe 'swift::storage::all' do
let :facts do
{
:operatingsystem => 'Debian',
:osfamily => 'Debian'
:osfamily => 'Debian',
:concat_basedir => '/tmp/foo'
}
end

View File

@ -0,0 +1,33 @@
require 'puppet'
require 'mocha'
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'lib', 'puppet', 'provider', 'swift_ring_builder')
RSpec.configure do |config|
config.mock_with :mocha
end
provider_class = Puppet::Provider::SwiftRingBuilder
describe provider_class do
let :builder_file_path do
'/etc/swift/account.builder'
end
it 'should be able to lookup the local ring and build an object' do
File.expects(:exists?).with(builder_file_path).returns(true)
provider_class.expects(:builder_file_path).twice.returns(builder_file_path)
provider_class.expects(:swift_ring_builder).returns(
'/etc/swift/account.builder, build version 3
262144 partitions, 3 replicas, 3 zones, 3 devices, 0.00 balance
The minimum number of hours before a partition can be reassigned is 1
Devices: id zone ip address port name weight partitions balance meta
2 2 192.168.101.14 6002 1 1.00 262144 0.00
0 3 192.168.101.15 6002 1 1.00 262144 0.00
1 1 192.168.101.13 6002 1 1.00 262144 0.00
'
)
resources = provider_class.lookup_ring.inspect
resources['192.168.101.15:6002/1'].should_not be_nil
resources['192.168.101.13:6002/1'].should_not be_nil
resources['192.168.101.14:6002/1'].should_not be_nil
end
end

View File

@ -0,0 +1,15 @@
require 'puppet'
describe Puppet::Type.type(:ring_account_device) do
it 'should fail if the name has no ":"' do
expect do
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
end.should raise_error(Puppet::Error, /should contain address:port\/device/)
end
it 'should fail if the name does not contain a "/"' do
expect do
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
end.should raise_error(Puppet::Error, /should contain a device/)
end
end

View File

@ -0,0 +1,16 @@
require 'puppet'
describe Puppet::Type.type(:ring_container_device) do
it 'should fail if the name has no ":"' do
expect do
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
end.should raise_error(Puppet::Error, /should contain address:port\/device/)
end
it 'should fail if the name does not contain a "/"' do
expect do
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
end.should raise_error(Puppet::Error, /should contain a device/)
end
end

View File

@ -0,0 +1,15 @@
require 'puppet'
describe Puppet::Type.type(:ring_object_device) do
it 'should fail if the name has no ":"' do
expect do
Puppet::Type.type(:ring_account_device).new(:name => 'foo/bar')
end.should raise_error(Puppet::Error, /should contain address:port\/device/)
end
it 'should fail if the name does not contain a "/"' do
expect do
Puppet::Type.type(:ring_account_device).new(:name => 'foo:80')
end.should raise_error(Puppet::Error, /should contain a device/)
end
end