1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge branch 'master' of github.com:fog/fog into auth20

This commit is contained in:
Kyle Rames 2013-03-01 14:24:12 -06:00
commit f97192177d
17 changed files with 109 additions and 40 deletions

View file

@ -1,3 +1,3 @@
source "http://rubygems.org"
source "https://rubygems.org"
gemspec

View file

@ -16,7 +16,7 @@ module Fog
end
class Mock
def allocate_address
def allocate_address(pool = nil)
response = Excon::Response.new
response.status = 200
response.headers = {

View file

@ -16,7 +16,7 @@ module Fog
class Mock
def get_snapshot_details(detailed=true)
def get_snapshot_details(snapshot_id)
response = Excon::Response.new
response.status = 200
response.body = {

View file

@ -16,7 +16,7 @@ module Fog
class Mock
def get_volume_details(detailed=true)
def get_volume_details(volume_id)
response = Excon::Response.new
response.status = 200
response.body = {

View file

@ -19,7 +19,7 @@ module Fog
class Mock
def list_servers
def list_servers(options = {})
response = Excon::Response.new
data = list_servers_detail.body['servers']
servers = []

View file

@ -20,7 +20,7 @@ module Fog
end # class Real
class Mock
def remove_fixed_ip(server_id, network_id)
def remove_fixed_ip(server_id, address)
true
end # def remove_fixed_ip
end # class Mock

View file

@ -16,7 +16,7 @@ module Fog
class Mock
def update_server(server_id, options)
def update_server(server_id, options = {})
response = Excon::Response.new
if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
if options['name']

View file

@ -38,6 +38,7 @@ module Fog
"OS-DCF:diskConfig" => "AUTO",
"created" => "2012-02-28T19:38:57Z",
"id" => image_id,
"name" => "Ubuntu",
"links" => [
{
"href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/images/#{image_id}",

View file

@ -55,7 +55,7 @@ module Fog
def get(key, &block)
requires :directory
data = service.get_object(directory.key, key, &block)
metadata = Metadata.from_headers(data.headers)
metadata = Metadata.from_headers(self, data.headers)
file_data = data.headers.merge({
:body => data.body,
:key => key,

View file

@ -1,3 +1,8 @@
require 'fog/rackspace/models/storage/directory'
require 'fog/rackspace/models/storage/file'
require 'fog/rackspace/models/storage/directories'
require 'fog/rackspace/models/storage/files'
module Fog
module Storage
class Rackspace
@ -60,33 +65,45 @@ module Fog
private
def directory?
[Fog::Storage::Rackspace::Directory, Fog::Storage::Rackspace::Directories].include? parent_class
end
def file?
[Fog::Storage::Rackspace::File, Fog::Storage::Rackspace::Files].include? parent_class
end
def parent_class
parent.is_a?(Class) ? parent : parent.class
end
def meta_prefix
if parent.is_a? Fog::Storage::Rackspace::Directory
if directory?
CONTAINER_META_PREFIX
elsif parent.is_a? Fog::Storage::Rackspace::File
elsif file?
OBJECT_META_PREFIX
else
raise "Metadata prefix is unknown for #{parent.class}"
raise "Metadata prefix is unknown for #{parent_class}"
end
end
def remove_meta_prefix
if parent.is_a? Fog::Storage::Rackspace::Directory
if directory?
CONTAINER_REMOVE_META_PREFIX
elsif parent.is_a? Fog::Storage::Rackspace::File
elsif file?
OBJECT_REMOVE_META_PREFIX
else
raise "Remove Metadata prefix is unknown for #{parent.class}"
raise "Remove Metadata prefix is unknown for #{parent_class}"
end
end
def meta_prefix_regex
if parent.is_a? Fog::Storage::Rackspace::Directory
if directory?
CONTAINER_KEY_REGEX
elsif parent.is_a? Fog::Storage::Rackspace::File
elsif file?
OBJECT_KEY_REGEX
else
raise "Metadata prefix is unknown for #{parent.class}"
raise "Metadata prefix is unknown for #{parent_class}"
end
end

View file

@ -36,5 +36,14 @@ module Shindo
sleep 30 unless Fog.mocking?
end
def rackspace_test_image_id(service)
# I chose to use the first Ubuntu because it will work with the smallest flavor and it doesn't require a license
@image_id ||= Fog.credentials[:rackspace_image_id] || service.images.find {|img| img.name =~ /Ubuntu/ }.id
end
def rackspace_test_flavor_id(service)
@flavor_id ||= Fog.credentials[:rackspace_flavor_id] || service.flavors.first.id
end
end
end

View file

@ -1,13 +1,11 @@
Shindo.tests('Fog::Compute::RackspaceV2 | image', ['rackspace']) do
service = Fog::Compute::RackspaceV2.new
flavor_id = Fog.credentials[:rackspace_flavor_id] || service.flavors.first.id
image_id = Fog.credentials[:rackspace_image_id] || service.images.first.id
test_time = Time.now.to_i.to_s
options = {
:name => "fog_server_#{test_time}",
:flavor_id => flavor_id,
:image_id => image_id
:flavor_id => rackspace_test_flavor_id(service),
:image_id => rackspace_test_image_id(service)
}
tests("success") do

View file

@ -7,7 +7,10 @@ Shindo.tests('Fog::Compute::RackspaceV2 | metadata', ['rackspace']) do
tests('success') do
begin
@server = service.servers.create(:name => "fog_server_#{test_time}", :flavor_id => 2, :image_id => "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001")
@server = service.servers.create(:name => "fog_server_#{test_time}",
:flavor_id => rackspace_test_flavor_id(service),
:image_id => rackspace_test_image_id(service))
@server.wait_for(timeout=1500) { ready? }
tests('server') do

View file

@ -2,14 +2,10 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
service = Fog::Compute::RackspaceV2.new
cbs_service = Fog::Rackspace::BlockStorage.new
flavor_id = Fog.credentials[:rackspace_flavor_id] || service.flavors.first.id
image_id = Fog.credentials[:rackspace_image_id] || service.images.first.id
image_id ||= Fog.mocking? ? service.images.first.id : service.images.find {|image| image.name =~ /Ubuntu/}.id # use the first Ubuntu image
options = {
:name => "fog_server_#{Time.now.to_i.to_s}",
:flavor_id => flavor_id,
:image_id => image_id,
:flavor_id => rackspace_test_flavor_id(service),
:image_id => rackspace_test_image_id(service),
:metadata => { 'fog_test' => 'true' }
}
@ -59,7 +55,7 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
@instance.wait_for(timeout=1500) { ready? }
sleep 60 unless Fog.mocking?
tests('#rebuild').succeeds do
@instance.rebuild(image_id)
@instance.rebuild rackspace_test_image_id(service)
returns('REBUILD') { @instance.state }
end

View file

@ -1,20 +1,18 @@
Shindo.tests('Fog::Compute::RackspaceV2 | servers', ['rackspace']) do
connection = Fog::Compute::RackspaceV2.new
flavor_id = Fog.credentials[:rackspace_flavor_id] || connection.flavors.first.id
image_id = Fog.credentials[:rackspace_image_id] || connection.images.first.id
service = Fog::Compute::RackspaceV2.new
options = {
:name => "fog_server_#{Time.now.to_i.to_s}",
:flavor_id => flavor_id,
:image_id => image_id
:flavor_id => rackspace_test_flavor_id(service),
:image_id => rackspace_test_image_id(service)
}
collection_tests(connection.servers, options, true) do
collection_tests(service.servers, options, true) do
@instance.wait_for { ready? }
end
tests("#bootstrap").succeeds do
pending if Fog.mocking?
@server = connection.servers.bootstrap(options)
@server = service.servers.bootstrap(options)
end
if @server

View file

@ -2,7 +2,19 @@ require 'fog/rackspace/models/storage/metadata'
require 'fog/rackspace/models/storage/directory'
require 'fog/rackspace/models/storage/file'
Shindo.tests('Fog::Rackspace::Storage | metadata', ['rackspace']) do
def assert_directory(obj, assert_value)
metadata = Fog::Storage::Rackspace::Metadata.new obj
returns(assert_value) { metadata.send :directory? }
end
def assert_file(obj, assert_value)
metadata = Fog::Storage::Rackspace::Metadata.new obj
returns(assert_value) { metadata.send :file? }
end
tests('Directory') do
@directory = Fog::Storage::Rackspace::Directory.new
tests('#to_key') do
@ -124,4 +136,39 @@ Shindo.tests('Fog::Rackspace::Storage | metadata', ['rackspace']) do
metadata[:test] = true
metadata[:test]
end
tests('#directory?') do
assert_directory Fog::Storage::Rackspace::Directories, true
assert_directory Fog::Storage::Rackspace::Directory, true
assert_directory Fog::Storage::Rackspace::Directory.new, true
assert_directory nil, false
assert_directory Fog::Storage::Rackspace::Files, false
assert_directory Fog::Storage::Rackspace::File, false
assert_directory Fog::Storage::Rackspace::File.new, false
assert_directory "I am a string!", false
end
tests('#file?') do
assert_file Fog::Storage::Rackspace::Directories, false
assert_file Fog::Storage::Rackspace::Directory, false
assert_file Fog::Storage::Rackspace::Directory.new, false
assert_file nil, false
assert_file Fog::Storage::Rackspace::Files, true
assert_file Fog::Storage::Rackspace::File, true
assert_file Fog::Storage::Rackspace::File.new, true
assert_file "I am a string!", false
end
tests('#parent_class') do
tests('Fog::Storage::Rackspace::Directory object') do
metadata = Fog::Storage::Rackspace::Metadata.new Fog::Storage::Rackspace::Directory.new
returns(Fog::Storage::Rackspace::Directory) { metadata.send :parent_class }
end
tests('Fog::Storage::Rackspace::Directory class') do
metadata = Fog::Storage::Rackspace::Metadata.new Fog::Storage::Rackspace::Directory
returns(Fog::Storage::Rackspace::Directory) { metadata.send :parent_class }
end
end
end

View file

@ -1,8 +1,6 @@
Shindo.tests('Fog::Compute::RackspaceV2 | image_tests', ['rackspace']) do
service = Fog::Compute.new(:provider => 'Rackspace', :version => 'V2')
flavor_id = Fog.credentials[:rackspace_flavor_id] || service.flavors.first.id
image_id = Fog.credentials[:rackspace_image_id] || service.images.first.id
image_format = {
'id' => String,
'name' => String,
@ -33,7 +31,9 @@ Shindo.tests('Fog::Compute::RackspaceV2 | image_tests', ['rackspace']) do
begin
test_time = Time.now.to_i.to_s
@server = service.servers.create(:name => "fog-image-tests_#{test_time}", :flavor_id => flavor_id, :image_id => image_id)
@server = service.servers.create(:name => "fog-image-tests_#{test_time}",
:flavor_id => rackspace_test_flavor_id(service),
:image_id => rackspace_test_image_id(service))
@server.wait_for { ready? }
@image_id = nil