diff --git a/lib/fog/openstack/identity.rb b/lib/fog/openstack/identity.rb index 94544485e..bf3935d57 100644 --- a/lib/fog/openstack/identity.rb +++ b/lib/fog/openstack/identity.rb @@ -81,22 +81,22 @@ module Fog @current_user = { 'username' => 'admin', 'name' => 'admin', - 'id' => 1, + 'id' => Fog::Mock.random_hex(32), 'roles' => [ - { 'id' => 1, 'name' => 'admin' }, - { 'id' => 2, 'name' => 'Member' } + { 'id' => Fog::Mock.random_hex(32), 'name' => 'admin' }, + { 'id' => Fog::Mock.random_hex(32), 'name' => 'Member' } ] } @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 @current_tenant = { - 'id' => 1, + 'id' => Fog::Mock.random_hex(32), 'name' => 'admin' } unless self.data[:users].values.detect {|user| user['name'] == @openstack_username} - id = Fog::Mock.random_numbers(6).to_s + id = Fog::Mock.random_hex(32) self.data[:users][id] = { 'id' => id, 'name' => options[:openstack_username], diff --git a/lib/fog/openstack/requests/compute/create_volume.rb b/lib/fog/openstack/requests/compute/create_volume.rb index 8bf5f7d4f..1a8a2fced 100644 --- a/lib/fog/openstack/requests/compute/create_volume.rb +++ b/lib/fog/openstack/requests/compute/create_volume.rb @@ -33,16 +33,16 @@ module Fog response.status = 202 response.body = { 'volume' => { - 'id' => Fog::Mock.random_numbers(2), + 'id' => Fog::Mock.random_numbers(2), 'display_name' => name, 'display_description' => description, - 'size' => size, - 'status' => 'creating', + 'size' => size, + 'status' => 'creating', 'snapshot_id' => '4', 'volume_type' => nil, 'availability_zone' => 'nova', 'created_at' => Time.now, - 'attchments' => [] + 'attachments' => [] } } response diff --git a/lib/fog/openstack/requests/compute/get_volume_details.rb b/lib/fog/openstack/requests/compute/get_volume_details.rb index b0f913eb6..9ca085ed5 100644 --- a/lib/fog/openstack/requests/compute/get_volume_details.rb +++ b/lib/fog/openstack/requests/compute/get_volume_details.rb @@ -30,7 +30,7 @@ module Fog 'status' => 'online', 'availability_zone' => 'nova', 'created_at' => Time.now, - 'attchments' => [] + 'attachments' => [] } } response diff --git a/lib/fog/openstack/requests/identity/create_tenant.rb b/lib/fog/openstack/requests/identity/create_tenant.rb index b854fa55d..72fc7ae57 100644 --- a/lib/fog/openstack/requests/identity/create_tenant.rb +++ b/lib/fog/openstack/requests/identity/create_tenant.rb @@ -20,10 +20,10 @@ module Fog response.status = [200, 204][rand(1)] response.body = { 'tenant' => { - 'id' => "#{ Fog::Mock.random_hex(32) }", - 'description' => attributes['description'], + 'id' => "df9a815161eba9b76cc748fd5c5af73e", + 'description' => attributes['description'] || 'normal tenant', 'enabled' => true, - 'name' => attributes['name'] + 'name' => attributes['name'] || 'default' } } response diff --git a/lib/fog/openstack/requests/identity/get_tenant.rb b/lib/fog/openstack/requests/identity/get_tenant.rb index aac3c4d20..875f084d2 100644 --- a/lib/fog/openstack/requests/identity/get_tenant.rb +++ b/lib/fog/openstack/requests/identity/get_tenant.rb @@ -17,7 +17,7 @@ module Fog response.status = [200, 204][rand(1)] response.body = { 'tenant' => { - 'id' => '1', + 'id' => id, 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' diff --git a/lib/fog/openstack/requests/image/create_image.rb b/lib/fog/openstack/requests/image/create_image.rb index 702a7c41f..139ac896b 100644 --- a/lib/fog/openstack/requests/image/create_image.rb +++ b/lib/fog/openstack/requests/image/create_image.rb @@ -7,35 +7,32 @@ module Fog 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 if attributes[:location] - file = File.open(attributes[:location], "rb") - body = file + body = File.open(attributes[:location], "rb") end unless attributes[:properties].nil? attributes[:properties].each do |key,value| - data["x-image-meta-property-#{key}"] = value + data['x-image-meta-property-#{key}'] = value end end - - request( - :headers => data, + :headers => data, :body => body, :expects => 201, :method => 'POST', @@ -53,24 +50,24 @@ module Fog response = Excon::Response.new response.status = 201 response.body = { - "image"=> { - "name" => attributes[:name], - "size" => 0, - "min_disk" => 0, - "disk_format" => attributes[:disk_format], - "created_at" => Time.now, - "container_format" => attributes['container_format'], - "deleted_at" => nil, - "updated_at" => Time.now, - "checksum" => nil, - "id" => "#{ Fog::Mock.random_hex(32) }", - "deleted" => false, - "protected" => false, - "is_public" => attributes[:is_public], - "status" => "queued", - "min_ram" => 0, - "owner" => attributes[:owner], - "properties" => attributes[:properties] + '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] } } response diff --git a/lib/fog/openstack/requests/image/list_public_images.rb b/lib/fog/openstack/requests/image/list_public_images.rb index 8c69982cc..5047be913 100644 --- a/lib/fog/openstack/requests/image/list_public_images.rb +++ b/lib/fog/openstack/requests/image/list_public_images.rb @@ -16,31 +16,13 @@ module Fog response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { - "images"=>[{ - "name"=>"mock-image-name", - "size"=>25165824, - "disk_format"=>"ami", - "container_format"=>"ami", - "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e", - "checksum"=>"2f81976cae15c16ef0010c51e3a6c163"}, - {"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"=>{} - }] + "images"=>[{ + "name" => Fog::Mock.random_letters(10), + "size" => Fog::Mock.random_numbers(8).to_i, + "disk_format" => "iso", + "container_format" => "bare", + "id" => Fog::Mock.random_hex(36), + "checksum" => Fog::Mock.random_hex(32)}] } response end # def list_tenants diff --git a/lib/fog/openstack/requests/image/update_image.rb b/lib/fog/openstack/requests/image/update_image.rb index 44698e428..7071a3961 100644 --- a/lib/fog/openstack/requests/image/update_image.rb +++ b/lib/fog/openstack/requests/image/update_image.rb @@ -38,26 +38,27 @@ module Fog def update_image(attributes) response = Excon::Response.new response.status = 200 - response.body = {"image"=> - {"name"=>"edit test 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"=>{} - }.merge(Hash[attributes.map { |key, val| [key.to_s, val] }]) - } + response.body = { + 'image'=> { + 'name' => attributes[:name], + 'size' => Fog::Mock.random_numbers(8).to_i, + 'min_disk' => 0, + 'disk_format' => 'iso', + 'created_at' => Time.now.to_s, + 'container_format' => 'bare', + 'deleted_at' => nil, + 'updated_at' => Time.now.to_s, + 'checksum' => Fog::Mock.random_hex(32), + 'id' => attributes[:id], + 'deleted' => false, + 'protected' => false, + 'is_public' => false, + 'status' => 'queued', + 'min_ram' => 0, + 'owner' => Fog::Mock.random_hex(32), + 'properties' => {} + } + } response end diff --git a/lib/fog/openstack/requests/volume/get_snapshot_details.rb b/lib/fog/openstack/requests/volume/get_snapshot_details.rb index e82ee379f..ebfc13df9 100644 --- a/lib/fog/openstack/requests/volume/get_snapshot_details.rb +++ b/lib/fog/openstack/requests/volume/get_snapshot_details.rb @@ -22,10 +22,10 @@ module Fog response.body = { 'snapshot' => { 'id' => '1', - 'display_name' => Fog::Mock.random_letters(rand(8) + 5), - 'display_description' => Fog::Mock.random_letters(rand(12) + 10), - 'size' => 3, - 'volume_id' => '4', + 'display_name' => 'Snapshot1', + 'display_description' => 'Volume1 snapshot', + 'size' => 1, + 'volume_id' => '1', 'status' => 'available', 'created_at' => Time.now } diff --git a/lib/fog/openstack/requests/volume/get_volume_details.rb b/lib/fog/openstack/requests/volume/get_volume_details.rb index 3a64faeec..9f2426e60 100644 --- a/lib/fog/openstack/requests/volume/get_volume_details.rb +++ b/lib/fog/openstack/requests/volume/get_volume_details.rb @@ -21,16 +21,16 @@ module Fog response.status = 200 response.body = { 'volume' => { - 'id' => '1', + 'id' => '1', 'display_name' => Fog::Mock.random_letters(rand(8) + 5), 'display_description' => Fog::Mock.random_letters(rand(12) + 10), - 'size' => 3, + 'size' => 3, 'volume_type' => nil, 'snapshot_id' => '4', - 'status' => 'online', + 'status' => 'online', 'availability_zone' => 'nova', 'created_at' => Time.now, - 'attchments' => [] + 'attachments' => [] } } response diff --git a/lib/fog/openstack/requests/volume/list_volumes.rb b/lib/fog/openstack/requests/volume/list_volumes.rb index 7c9bdd4c7..3ead9f29d 100644 --- a/lib/fog/openstack/requests/volume/list_volumes.rb +++ b/lib/fog/openstack/requests/volume/list_volumes.rb @@ -24,7 +24,7 @@ module Fog { "status" => "available", "display_description" => "test 1 desc", "availability_zone" => "nova", - "display_name" => "test 1", + "display_name" => "Volume1", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, @@ -35,7 +35,7 @@ module Fog { "status" => "available", "display_description" => "test 2 desc", "availability_zone" => "nova", - "display_name" => "test 2", + "display_name" => "Volume2", "attachments" => [{}], "volume_type" => nil, "snapshot_id" => nil, diff --git a/tests/openstack/requests/compute/quota_tests.rb b/tests/openstack/requests/compute/quota_tests.rb index a62ec1283..3be76cc0c 100644 --- a/tests/openstack/requests/compute/quota_tests.rb +++ b/tests/openstack/requests/compute/quota_tests.rb @@ -11,6 +11,8 @@ Shindo.tests('Fog::Compute[:openstack] | quota requests', ['openstack']) do 'instances' => Fixnum, 'volumes' => Fixnum, 'cores' => Fixnum, + 'security_groups' => Fixnum, + 'security_group_rules' => Fixnum, 'id' => String } diff --git a/tests/openstack/requests/compute/volume_tests.rb b/tests/openstack/requests/compute/volume_tests.rb index 78972e8f4..13b4922b4 100644 --- a/tests/openstack/requests/compute/volume_tests.rb +++ b/tests/openstack/requests/compute/volume_tests.rb @@ -3,16 +3,16 @@ require 'fog/openstack' Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do @volume_format = { - 'id' => String, - 'displayName' => String, - 'size' => Integer, - 'displayDescription' => String, - 'status' => String, - 'snapshotId' => String, - 'availabilityZone' => String, - 'attachments' => Array, - 'volumeType' => NilClass, - 'createdAt' => Time + 'id' => String, + 'display_name' => String, + 'size' => Integer, + 'display_description' => String, + 'status' => String, + 'snapshot_id' => String, + 'availability_zone' => String, + 'attachments' => Array, + 'volume_type' => NilClass, + 'created_at' => Time } @@ -23,7 +23,7 @@ Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do tests('#get_volume_detail').formats({'volume' => @volume_format}) do pending unless Fog.mocking? - Fog::Compute[:openstack].get_volume_details(0).body + Fog::Compute[:openstack].get_volume_details(1).body end tests('#create_volume').formats({'volume' => @volume_format}) do diff --git a/tests/openstack/requests/identity/tenant_tests.rb b/tests/openstack/requests/identity/tenant_tests.rb index 6660e2092..8dd2616a3 100644 --- a/tests/openstack/requests/identity/tenant_tests.rb +++ b/tests/openstack/requests/identity/tenant_tests.rb @@ -23,7 +23,7 @@ Shindo.tests('Fog::Identity[:openstack] | tenant requests', ['openstack']) do openstack = Fog::Identity[:openstack] openstack.list_roles_for_user_on_tenant( - openstack.tenants.first, openstack.users.first).body + openstack.current_tenant['id'], openstack.current_user['id']).body end tests('#create_tenant').formats({'tenant' => @tenant_format}) do diff --git a/tests/openstack/requests/image/image_tests.rb b/tests/openstack/requests/image/image_tests.rb index b49e22380..c53b06ef0 100644 --- a/tests/openstack/requests/image/image_tests.rb +++ b/tests/openstack/requests/image/image_tests.rb @@ -1,52 +1,72 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do + openstack = Fog::Identity[:openstack] + @image_attributes = { + :name => 'new image', + :owner => openstack.current_tenant['id'], + :is_public => 'true', + :copy_from => 'http://website.com/image.iso', + :disk_format => 'iso', + :properties=> + {:user_id => openstack.current_user['id'], + :owner_id => openstack.current_tenant['id']}, + :container_format => 'bare' } @image_format = { + 'name' => String, + 'container_format' => String, + 'disk_format' => String, + 'checksum' => String, + 'id' => String, + 'size' => Integer + } + + @detailed_image_format = { 'id' => String, 'name' => String, - 'size' => Fog::Nullable::Integer, - 'disk_format' => Fog::Nullable::String, - 'container_format' => Fog::Nullable::String, - 'checksum' => Fog::Nullable::String, - 'min_disk' => Fog::Nullable::Integer, - 'created_at' => Fog::Nullable::String, + 'size' => Integer, + 'disk_format' => String, + 'container_format' => String, + 'checksum' => String, + 'min_disk' => Integer, + 'created_at' => String, 'deleted_at' => Fog::Nullable::String, - 'updated_at' => Fog::Nullable::String, - 'deleted' => Fog::Nullable::Boolean, - 'protected' => Fog::Nullable::Boolean, - 'is_public' => Fog::Nullable::Boolean, - 'status' => Fog::Nullable::String, - 'min_ram' => Fog::Nullable::Integer, - 'owner' => Fog::Nullable::String, - 'properties' => Fog::Nullable::Hash + 'updated_at' => String, + 'deleted' => Fog::Boolean, + 'protected' => Fog::Boolean, + 'is_public' => Fog::Boolean, + 'status' => String, + 'min_ram' => Integer, + 'owner' => 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-Owner'=>String, + 'X-Image-Meta-Status'=>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 } ] @@ -55,21 +75,21 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do Fog::Image[:openstack].list_public_images.body end - tests('#list_public_images_detailed').formats({'images' => [@image_format]}) do + tests('#list_public_images_detailed').formats({'images' => [@detailed_image_format]}) do Fog::Image[:openstack].list_public_images_detailed.body end - tests('#create_image').formats({'image' => @image_format}) do - @instance = Fog::Image[:openstack].create_image({:name => "test image"}).body + tests('#create_image').formats({'image' => @detailed_image_format}) do + @instance = Fog::Image[:openstack].create_image(@image_attributes).body end tests('#get_image').formats(@image_meta_format) do Fog::Image[:openstack].get_image(@instance['image']['id']).headers end - tests('#update_image').formats(@image_format) do + tests('#update_image').formats(@detailed_image_format) do Fog::Image[:openstack].update_image({:id => @instance['image']['id'], - :name => "edit image"}).body['image'] + :name => 'edit image'}).body['image'] end tests('#add_member_to_image').succeeds do