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

[openstack] Fix Failing Shindo Tests

Signed-off-by: Nelvin Driz <nelvindriz@live.com>
This commit is contained in:
Nelvin Driz 2012-10-02 13:52:45 +08:00
parent 92aed2a18d
commit 0035231954
18 changed files with 125 additions and 166 deletions

View file

@ -1,5 +1,4 @@
module Fog
def self.wait_for(timeout=Fog.timeout, interval=1, &block)
duration = 0
start = Time.now
@ -13,5 +12,4 @@ module Fog
{ :duration => duration }
end
end
end

View file

@ -3,7 +3,6 @@ require 'fog/openstack'
module Fog
module Image
class OpenStack < Fog::Service
requires :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url, :persistent,
:openstack_service_name, :openstack_tenant,
@ -15,7 +14,6 @@ module Fog
model :image
collection :images
request_path 'fog/openstack/requests/image'
request :list_public_images
@ -36,8 +34,7 @@ module Fog
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:users => {},
:tenants => {}
:images => {}
}
end
end

View file

@ -12,9 +12,11 @@ module Fog
end
def find_by_id(id)
self.find {|tenant| tenant.id == id} ||
Fog::Identity::OpenStack::Tenant.new(
connection.get_tenant(id).body['tenant'])
cached_tenant = self.find {|tenant| tenant.id == id}
return cached_tenant if cached_tenant
tenant_hash = connection.get_tenant(id).body['tenant']
Fog::Identity::OpenStack::Tenant.new(
tenant_hash.merge(:connection => connection))
end
def destroy(id)

View file

@ -18,7 +18,7 @@ module Fog
self.find {|user| user.id == id} ||
Fog::Identity::OpenStack::User.new(
connection.get_user_by_id(id).body['user'].merge(
connection: connection
'connection' => connection
)
)
end

View file

@ -44,7 +44,7 @@ module Fog
def create
requires :name
merge_attributes(connection.create_image(self.attributes).body['image'])
self
self
end
def update

View file

@ -23,21 +23,25 @@ module Fog
class Mock
def create_security_group(name, description)
tenant_id = Fog::Identity.new(:provider => 'OpenStack').current_tenant['id']
security_group_id = Fog::Mock.random_numbers(2).to_i
self.data[:security_groups][security_group_id] = {
'tenant_id' => tenant_id,
'rules' => [],
'id' => security_group_id,
'name' => name,
'description' => description
}
response = Excon::Response.new
response.status = 200
response.headers = {
"X-Compute-Request-Id" => "req-c373a42c-2825-4e60-8d34-99416ea850be",
"Content-Type" => "application/json",
"Content-Length" => "139",
"Date" => Date.new}
'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
'Content-Type' => 'application/json',
'Content-Length' => Fog::Mock.random_numbers(3).to_s,
'Date' => Date.new}
response.body = {
"security_group" => [{
"rules" => [],
"tenant_id" => "d5183375ab0343f3a0b4b05f547aefc2",
"id" => 999,
"name" => name,
"description" => description
}]
'security_group' => self.data[:security_groups].values
}
response
end

View file

@ -30,24 +30,26 @@ module Fog
response = Excon::Response.new
response.status = 200
response.headers = {
"X-Compute-Request-Id" => "req-63a90344-7c4d-42e2-936c-fd748bced1b3",
"Content-Type" => "application/json",
"Content-Length" => "163",
"Date" => Date.new
'X-Compute-Request-Id' => "req-#{Fog::Mock.random_hex(32)}",
'Content-Type' => 'application/json',
'Content-Length' => Fog::Mock.random_numbers(3).to_s,
'Date' => Date.new
}
response.body = {
"security_group_rule" => {
"from_port" => from_port,
"group" => group_id || {},
"ip_protocol" => ip_protocol,
"to_port" => to_port,
"parent_group_id" => parent_group_id,
"ip_range" => {
"cidr" => cidr
},
"id"=>1
rule = {
'id' => Fog::Mock.random_numbers(2).to_i,
'from_port' => from_port,
'group' => group_id || {},
'ip_protocol' => ip_protocol,
'to_port' => to_port,
'parent_group_id' => parent_group_id,
'ip_range' => {
'cidr' => cidr
}
}
self.data[:security_groups][parent_group_id]['rules'].push(rule)
response.body = {
'security_group_rule' => rule
}
response
end
end # mock

View file

@ -59,7 +59,7 @@ module Fog
}
]
Excon::Response.new(
:body => { 'security_groups' => self.data[:security_groups] },
:body => { 'security_groups' => self.data[:security_groups].values },
:headers => {
"X-Compute-Request-Id" => "req-#{Fog::Mock.random_base64(36)}",
"Content-Type" => "application/json",

View file

@ -28,9 +28,8 @@ module Fog
"volume_type" => nil,
"snapshot_id" => nil,
"size" => 1,
"id" => 6,
"created_at" => "2012-03-30 05:31:00.655058",
"metadata" => {} },
"id" => Fog::Mock.random_hex(32),
"created_at" => Time.now },
{ "status" => "available",
"display_description" => "",
"availability_zone" => "nova",
@ -39,9 +38,8 @@ module Fog
"volume_type" => nil,
"snapshot_id" => nil,
"size" => 1,
"id" => 8,
"created_at" => "2012-03-30 16:14:55.582717",
"metadata" => {} }
"id" => Fog::Mock.random_hex(32),
"created_at" => Time.now }
]
response.body = { 'volumes' => self.data[:volumes] }
response

View file

@ -4,20 +4,18 @@ module Fog
class Real
def create_image(attributes)
data = {
'Content-Type'=>'application/octet-stream',
'x-image-meta-name' => attributes[:name],
'x-image-meta-disk-format' => attributes[:disk_format],
'x-image-meta-container-format' => attributes[:container_format],
'x-image-meta-size' => attributes[:size],
'x-image-meta-is-public' => attributes[:is_public],
'x-image-meta-min-ram' => attributes[:min_ram],
'x-image-meta-min-disk' => attributes[:min_disk],
'x-image-meta-checksum' => attributes[:checksum],
'x-image-meta-owner' => attributes[:owner],
'x-glance-api-copy-from' => attributes[:copy_from]
'Content-Type'=>'application/octet-stream',
'x-image-meta-name' => attributes[:name],
'x-image-meta-disk-format' => attributes[:disk_format],
'x-image-meta-container-format' => attributes[:container_format],
'x-image-meta-size' => attributes[:size],
'x-image-meta-is-public' => attributes[:is_public],
'x-image-meta-min-ram' => attributes[:min_ram],
'x-image-meta-min-disk' => attributes[:min_disk],
'x-image-meta-checksum' => attributes[:checksum],
'x-image-meta-owner' => attributes[:owner],
'x-glance-api-copy-from' => attributes[:copy_from]
}
body = String.new
@ -49,27 +47,28 @@ module Fog
def create_image(attributes)
response = Excon::Response.new
response.status = 201
response.body = {
'image'=> {
'name' => attributes['name'],
'size' => Fog::Mock.random_numbers(8).to_i,
'min_disk' => 0,
'disk_format' => attributes['disk_format'],
'created_at' => Time.now.to_s,
'container_format' => attributes['container_format'],
'deleted_at' => nil,
'updated_at' => Time.now.to_s,
'checksum' => Fog::Mock.random_hex(32),
'id' => Fog::Mock.random_hex(32),
'deleted' => false,
'protected' => false,
'is_public' => false,
'status' => 'queued',
'min_ram' => 0,
'owner' => attributes['owner'],
'properties' => attributes['properties']
}
}
image_id = Fog::Mock.random_hex(32)
image = self.data[:images][image_id] = {
'name' => attributes['name'] || attributes[:name],
'size' => Fog::Mock.random_numbers(8).to_i,
'min_disk' => 0,
'disk_format' => attributes['disk_format'] || attributes[:disk_format] || 'raw',
'created_at' => Time.now.to_s,
'container_format' => attributes['container_format'] || attributes[:container_format] || 'bare',
'deleted_at' => nil,
'updated_at' => Time.now.to_s,
'checksum' => Fog::Mock.random_hex(32),
'id' => image_id,
'deleted' => false,
'protected' => false,
'is_public' => false,
'status' => 'queued',
'min_ram' => 0,
'owner' => attributes['owner'] || attributes[:owner],
'properties' => attributes['properties'] || attributes[:properties] || {}
}
response.body = { 'image'=> image }
response
end
end

View file

@ -14,13 +14,11 @@ module Fog
end
class Mock
def delete_image(image_id)
response = Excon::Response.new
response.status = 200
response
end
end
end
end

View file

@ -22,46 +22,7 @@ module Fog
def list_public_images_detailed(attribute=nil, query=nil)
response = Excon::Response.new
response.status = [200, 204][rand(1)]
response.body = {"images"=>[{
"name"=>"cirros-0.3.0-x86_64-blank",
"size"=>25165824,
"min_disk"=>0,
"disk_format"=>"ami",
"created_at"=>"2012-02-21T07:32:26",
"container_format"=>"ami",
"deleted_at"=>nil,
"updated_at"=>"2012-02-21T07:32:29",
"checksum"=>"2f81976cae15c16ef0010c51e3a6c163",
"id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e",
"deleted"=>false,
"protected"=>false,
"is_public"=>true,
"status"=>"active",
"min_ram"=>0,
"owner"=>"ff528b20431645ebb5fa4b0a71ca002f",
"properties"=>{
"ramdisk_id"=>"b45aa128-cd36-4ad9-a026-1a1c2bfd8fdc",
"kernel_id"=>"cd28951e-e1c2-4bc5-95d3-f0495abbcdc5"}
},
{"name"=>"new image",
"size"=>0,
"min_disk"=>0,
"disk_format"=>nil,
"created_at"=>"2012-02-24T06:45:00",
"container_format"=>nil,
"deleted_at"=>nil,
"updated_at"=>"2012-02-24T06:45:00",
"checksum"=>nil,
"id"=>"e41304f3-2453-42b4-9829-2e220a737395",
"deleted"=>false,
"protected"=>false,
"is_public"=>false,
"status"=>"queued",
"min_ram"=>0,
"owner"=>"728ecc7c10614a1faa6fbabd1a68a4a0",
"properties"=>{}
}]
}
response.body = {'images' => self.data[:images].values}
response
end # def list_tenants
end # class Mock

View file

@ -31,5 +31,6 @@ Shindo.tests("Fog::Image[:openstack] | image", ['openstack']) do
tests('#destroy').succeeds do
@instance.destroy == true
end
end
end

View file

@ -17,12 +17,12 @@ Shindo.tests('Fog::Compute[:openstack] | image requests', ['openstack']) do
}
tests('success') do
# Setup
@image_id = Fog::Compute[:openstack].images[0].id
unless Fog.mocking?
Fog::Compute[:openstack].images.get(@image_id).wait_for { ready? }
end
tests("#get_image_details(#{@image_id})").formats(@image_format) do
pending if Fog.mocking?
Fog::Compute[:openstack].get_image_details(@image_id).body['image']
@ -36,14 +36,13 @@ Shindo.tests('Fog::Compute[:openstack] | image requests', ['openstack']) do
Fog::Compute[:openstack].list_images_detail.body
end
# Teardown
unless Fog.mocking?
Fog::Compute[:openstack].images.get(@image_id).wait_for { ready? }
end
end
tests('failure') do
tests('#delete_image(0)').raises(Fog::Compute::OpenStack::NotFound) do
pending if Fog.mocking?
Fog::Compute[:openstack].delete_image(0)

View file

@ -11,8 +11,8 @@ Shindo.tests('Fog::Compute[:openstack] | quota requests', ['openstack']) do
'instances' => Fixnum,
'volumes' => Fixnum,
'cores' => Fixnum,
'security_groups' => Fixnum,
'security_group_rules' => Fixnum,
'security_groups' => Fog::Nullable::Integer,
'security_group_rules' => Fog::Nullable::Integer,
'id' => String
}

View file

@ -2,21 +2,21 @@ Shindo.tests('Fog::Compute[:openstack] | security group requests', ['openstack']
@security_group = Hash.new
@security_group_rule = Hash.new
@security_group_format = {
"rules" => Array,
"tenant_id" => String,
"id" => Integer,
"name" => String,
"id" => Integer,
"rules" => Array,
"tenant_id" => String,
"name" => String,
"description" => String
}
@security_group_rule_format = {
"from_port" => Integer,
"group" => Hash,
"id" => Integer,
"from_port" => Integer,
"to_port" => Integer,
"ip_protocol" => String,
"to_port" => Integer,
"parent_group_id" => Integer,
"ip_range" => Hash,
"id" => Integer
"group" => Hash,
"ip_range" => Hash,
"parent_group_id" => Integer
}
tests('success') do

View file

@ -8,14 +8,13 @@ Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do
'size' => Integer,
'display_description' => String,
'status' => String,
'snapshot_id' => String,
'snapshot_id' => Fog::Nullable::String,
'availability_zone' => String,
'attachments' => Array,
'volume_type' => NilClass,
'volume_type' => Fog::Nullable::String,
'created_at' => Time
}
tests('success') do
tests('#list_volumes').formats({'volumes' => [@volume_format]}) do
Fog::Compute[:openstack].list_volumes.body

View file

@ -36,39 +36,40 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
'is_public' => Fog::Boolean,
'status' => String,
'min_ram' => Integer,
'owner' => String,
'owner' => Fog::Nullable::String,
'properties' => Hash
}
@image_meta_format ={
'X-Image-Meta-Is_public'=>String,
'X-Image-Meta-Min_disk'=>Fog::Nullable::String,
'X-Image-Meta-Property-Ramdisk_id'=>Fog::Nullable::String,
'X-Image-Meta-Disk_format'=>Fog::Nullable::String,
'X-Image-Meta-Created_at'=>String,
'X-Image-Meta-Container_format'=>Fog::Nullable::String,
'Etag'=>String,
'Location'=>String,
'X-Image-Meta-Protected'=>String,
'Date'=>String,
'X-Image-Meta-Name'=>String,
'X-Image-Meta-Min_ram'=>String,
'Content-Type'=>String,
'X-Image-Meta-Updated_at'=>String,
'X-Image-Meta-Property-Kernel_id'=>Fog::Nullable::String,
'X-Image-Meta-Size'=>String,
'X-Image-Meta-Checksum'=>Fog::Nullable::String,
'X-Image-Meta-Deleted'=>String,
'Content-Length'=>String,
'X-Image-Meta-Owner'=>String,
'X-Image-Meta-Status'=>String,
'X-Image-Meta-Id'=>String}
'X-Image-Meta-Is_public'=>String,
'X-Image-Meta-Min_disk'=>Fog::Nullable::String,
'X-Image-Meta-Property-Ramdisk_id'=>Fog::Nullable::String,
'X-Image-Meta-Disk_format'=>Fog::Nullable::String,
'X-Image-Meta-Created_at'=>String,
'X-Image-Meta-Container_format'=>Fog::Nullable::String,
'Etag'=>String,
'Location'=>String,
'X-Image-Meta-Protected'=>String,
'Date'=>String,
'X-Image-Meta-Name'=>String,
'X-Image-Meta-Min_ram'=>String,
'Content-Type'=>String,
'X-Image-Meta-Updated_at'=>String,
'X-Image-Meta-Property-Kernel_id'=>Fog::Nullable::String,
'X-Image-Meta-Size'=>String,
'X-Image-Meta-Checksum'=>Fog::Nullable::String,
'X-Image-Meta-Deleted'=>String,
'Content-Length'=>String,
'X-Image-Meta-Status'=>String,
'X-Image-Meta-Owner'=>String,
'X-Image-Meta-Id'=>String
}
@image_members_format =[
{'can_share'=>Fog::Nullable::Boolean,
'member_id'=>String
}
]
{'can_share'=>Fog::Nullable::Boolean,
'member_id'=>String
}
]
tests('success') do
tests('#list_public_images').formats({'images' => [@image_format]}) do