mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace] Moved methods to MockData module
This commit is contained in:
parent
cfc1d58847
commit
b7daf27003
11 changed files with 48 additions and 47 deletions
|
@ -5,34 +5,6 @@ module Fog
|
|||
module Rackspace
|
||||
extend Fog::Provider
|
||||
|
||||
def self.uuid
|
||||
[8,4,4,4,12].map{|i| Fog::Mock.random_hex(i)}.join("-")
|
||||
end
|
||||
|
||||
def self.ipv4_address
|
||||
4.times.map{ Fog::Mock.random_numbers(3) }.join(".")
|
||||
end
|
||||
|
||||
def self.ipv6_address
|
||||
8.times.map { Fog::Mock.random_hex(4) }.join(":")
|
||||
end
|
||||
|
||||
def self.keep(hash, *keys)
|
||||
{}.tap do |kept|
|
||||
keys.each{|k| kept[k]= hash[k] if hash.key?(k)}
|
||||
end
|
||||
end
|
||||
|
||||
def self.slice(hash, *keys)
|
||||
hash.dup.tap do |sliced|
|
||||
keys.each{|k| sliced.delete(k)}
|
||||
end
|
||||
end
|
||||
|
||||
def self.zulu_time
|
||||
Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
end
|
||||
|
||||
module Errors
|
||||
class ServiceError < Fog::Errors::Error
|
||||
attr_reader :response_data, :status_code
|
||||
|
|
|
@ -7,7 +7,7 @@ module Fog
|
|||
|
||||
#Compute V2
|
||||
flavor_id = Fog.credentials[:rackspace_flavor_id].to_s ||= Fog::Mock.random_numbers(1)
|
||||
image_id = Fog.credentials[:rackspace_image_id] ||= Fog::Rackspace.uuid
|
||||
image_id = Fog.credentials[:rackspace_image_id] ||= Fog::Rackspace::MockData.uuid
|
||||
image_name = Fog::Mock.random_letters(6)
|
||||
|
||||
flavor = {
|
||||
|
@ -111,6 +111,34 @@ module Fog
|
|||
end
|
||||
end[@rackspace_api_key]
|
||||
end
|
||||
|
||||
def self.uuid
|
||||
[8,4,4,4,12].map{|i| Fog::Mock.random_hex(i)}.join("-")
|
||||
end
|
||||
|
||||
def self.ipv4_address
|
||||
4.times.map{ Fog::Mock.random_numbers(3) }.join(".")
|
||||
end
|
||||
|
||||
def self.ipv6_address
|
||||
8.times.map { Fog::Mock.random_hex(4) }.join(":")
|
||||
end
|
||||
|
||||
def self.keep(hash, *keys)
|
||||
{}.tap do |kept|
|
||||
keys.each{|k| kept[k]= hash[k] if hash.key?(k)}
|
||||
end
|
||||
end
|
||||
|
||||
def self.slice(hash, *keys)
|
||||
hash.dup.tap do |sliced|
|
||||
keys.each{|k| sliced.delete(k)}
|
||||
end
|
||||
end
|
||||
|
||||
def self.zulu_time
|
||||
Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ module Fog
|
|||
if volume.nil?
|
||||
raise Fog::Rackspace::BlockStorage::NotFound
|
||||
else
|
||||
snapshot_id = Fog::Rackspace.uuid
|
||||
snapshot_id = Fog::Rackspace::MockData.uuid
|
||||
display_name = options[:display_name] || "test snapshot"
|
||||
display_description = options[:display_description] || "test snapshot description"
|
||||
|
||||
|
@ -39,7 +39,7 @@ module Fog
|
|||
"volume_id" => volume_id,
|
||||
"status" => "available",
|
||||
"size" => volume["size"],
|
||||
"created_at" => Fog::Rackspace.zulu_time,
|
||||
"created_at" => Fog::Rackspace::MockData.zulu_time,
|
||||
"availability_zone" => "nova",
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ module Fog
|
|||
elsif size < 100 || size > 1024
|
||||
raise Fog::Rackspace::BlockStorage::BadRequest.new("'size' parameter must be between 100 and 1024")
|
||||
else
|
||||
volume_id = Fog::Rackspace.uuid
|
||||
volume_id = Fog::Rackspace::MockData.uuid
|
||||
name = options[:display_name] || "test volume"
|
||||
description = options[:display_description] || "description goes here"
|
||||
volume_type = options[:volume_type] || "SATA"
|
||||
|
@ -44,7 +44,7 @@ module Fog
|
|||
"volume_type" => volume_type,
|
||||
"snapshot_id" => nil,
|
||||
"attachments" => [],
|
||||
"created_at" => Fog::Rackspace.zulu_time,
|
||||
"created_at" => Fog::Rackspace::MockData.zulu_time,
|
||||
"availability_zone" => "nova",
|
||||
"metadata" => {},
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_image(server_id, name, options = {})
|
||||
image_id = Fog::Rackspace.uuid
|
||||
image_id = Fog::Rackspace::MockData.uuid
|
||||
image = {
|
||||
"OS-DCF:diskConfig" => "AUTO",
|
||||
"created" => "2012-02-28T19:38:57Z",
|
||||
|
|
|
@ -29,11 +29,11 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_server(name, image_id, flavor_id, min_count, max_count, options={})
|
||||
server_id = Fog::Rackspace.uuid
|
||||
public_ip4 = Fog::Rackspace.ipv4_address
|
||||
public_ip6 = Fog::Rackspace.ipv6_address
|
||||
private_ip4 = Fog::Rackspace.ipv4_address
|
||||
private_ip6 = Fog::Rackspace.ipv6_address
|
||||
server_id = Fog::Rackspace::MockData.uuid
|
||||
public_ip4 = Fog::Rackspace::MockData.ipv4_address
|
||||
public_ip6 = Fog::Rackspace::MockData.ipv6_address
|
||||
private_ip4 = Fog::Rackspace::MockData.ipv4_address
|
||||
private_ip6 = Fog::Rackspace::MockData.ipv6_address
|
||||
admin_pass = Fog::Mock.random_letters(12)
|
||||
|
||||
flavor = self.data[:flavors][flavor_id]
|
||||
|
@ -65,10 +65,10 @@ module Fog
|
|||
]
|
||||
},
|
||||
"created" => "2012-07-28T15:32:25Z",
|
||||
"flavor" => Fog::Rackspace.keep(flavor, "id", "links"),
|
||||
"flavor" => Fog::Rackspace::MockData.keep(flavor, "id", "links"),
|
||||
"hostId" => Fog::Mock.random_hex(56),
|
||||
"id" => server_id,
|
||||
"image" => Fog::Rackspace.keep(image, "id", "links"),
|
||||
"image" => Fog::Rackspace::MockData.keep(image, "id", "links"),
|
||||
"links" => [
|
||||
{
|
||||
"href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/servers/#{server_id}",
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
if server.nil?
|
||||
raise Fog::Compute::RackspaceV2::NotFound
|
||||
else
|
||||
server_response = Fog::Rackspace.keep(server, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata', 'accessIPv4', 'accessIPv6', 'OS-DCF:diskConfig', 'rax-bandwidth:bandwidth', 'addresses', 'flavor', 'image')
|
||||
server_response = Fog::Rackspace::MockData.keep(server, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata', 'accessIPv4', 'accessIPv6', 'OS-DCF:diskConfig', 'rax-bandwidth:bandwidth', 'addresses', 'flavor', 'image')
|
||||
server_response['image']['links'].map! { |l| l.delete("type"); l }
|
||||
response(:body => {"server" => server_response})
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def list_flavors
|
||||
flavors = self.data[:flavors].values.map { |f| Fog::Rackspace.keep(f, 'id', 'name', 'links') }
|
||||
flavors = self.data[:flavors].values.map { |f| Fog::Rackspace::MockData.keep(f, 'id', 'name', 'links') }
|
||||
response(:body => {"flavors" => flavors})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def list_servers
|
||||
servers = self.data[:servers].values.map { |s| Fog::Rackspace.keep(s, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata') }
|
||||
servers = self.data[:servers].values.map { |s| Fog::Rackspace::MockData.keep(s, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata') }
|
||||
response(:body => {"servers" => servers})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ module Fog
|
|||
def update_server(server_id, name)
|
||||
server = self.data[:servers][server_id]
|
||||
server['name'] = name
|
||||
server_response = Fog::Rackspace.keep(server, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata', 'accessIPv4', 'accessIPv6', 'OS-DCF:diskConfig', 'rax-bandwidth:bandwidth', 'addresses', 'flavor', 'links', 'image')
|
||||
server_response = Fog::Rackspace::MockData.keep(server, 'id', 'name', 'hostId', 'created', 'updated', 'status', 'progress', 'user_id', 'tenant_id', 'links', 'metadata', 'accessIPv4', 'accessIPv6', 'OS-DCF:diskConfig', 'rax-bandwidth:bandwidth', 'addresses', 'flavor', 'links', 'image')
|
||||
|
||||
response(
|
||||
:status => 200,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
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
|
||||
|
||||
|
@ -59,8 +60,8 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
|
|||
end
|
||||
|
||||
tests('attachments') do
|
||||
begin
|
||||
@volume = cbs_service.volumes.create(:size => 100, :display_name => "fog-#{timestamp}")
|
||||
begin
|
||||
@volume = cbs_service.volumes.create(:size => 100, :display_name => "fog-#{Time.now.to_i.to_s}")
|
||||
@volume.wait_for(timeout=1500) { ready? }
|
||||
tests('#attach_volume').succeeds do
|
||||
@instance.attach_volume(@volume)
|
||||
|
|
Loading…
Add table
Reference in a new issue