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

Merge pull request #2073 from burns/openstack_image_tests

[openstack|image] strip unused headers in #update_image
This commit is contained in:
Wesley Beary 2013-08-14 11:20:22 -07:00
commit b1c8268f6d
3 changed files with 84 additions and 71 deletions

View file

@ -5,18 +5,18 @@ module Fog
def create_image(attributes) def create_image(attributes)
data = { data = {
'Content-Type'=>'application/octet-stream', 'Content-Type' =>'application/octet-stream',
'x-image-meta-name' => attributes[:name], 'x-image-meta-name' => attributes[:name],
'x-image-meta-disk-format' => attributes[:disk_format], 'x-image-meta-disk-format' => attributes[:disk_format],
'x-image-meta-container-format' => attributes[:container_format], 'x-image-meta-container-format' => attributes[:container_format],
'x-image-meta-size' => attributes[:size], 'x-image-meta-size' => attributes[:size],
'x-image-meta-is-public' => attributes[:is_public], 'x-image-meta-is-public' => attributes[:is_public],
'x-image-meta-min-ram' => attributes[:min_ram], 'x-image-meta-min-ram' => attributes[:min_ram],
'x-image-meta-min-disk' => attributes[:min_disk], 'x-image-meta-min-disk' => attributes[:min_disk],
'x-image-meta-checksum' => attributes[:checksum], 'x-image-meta-checksum' => attributes[:checksum],
'x-image-meta-owner' => attributes[:owner], 'x-image-meta-owner' => attributes[:owner],
'x-glance-api-copy-from' => attributes[:copy_from] 'x-glance-api-copy-from' => attributes[:copy_from]
}.reject { |k,v| v.nil? } }.reject {|k,v| v.nil? }
body = String.new body = String.new
if attributes[:location] if attributes[:location]
@ -52,23 +52,23 @@ module Fog
image_id = Fog::Mock.random_hex(32) image_id = Fog::Mock.random_hex(32)
image = self.data[:images][image_id] = { image = self.data[:images][image_id] = {
'name' => attributes['name'] || attributes[:name], 'name' => attributes[:name],
'size' => Fog::Mock.random_numbers(8).to_i, 'size' => attributes[:size] || Fog::Mock.random_numbers(8).to_i,
'min_disk' => 0, 'min_disk' => attributes[:min_disk] || 0,
'disk_format' => attributes['disk_format'] || attributes[:disk_format] || 'raw', 'disk_format' => attributes[:disk_format] || 'raw',
'created_at' => Time.now.to_s, 'created_at' => Time.now.strftime('%FT%T.%6N'),
'container_format' => attributes['container_format'] || attributes[:container_format] || 'bare', 'container_format' => attributes[:container_format] || 'bare',
'deleted_at' => nil, 'deleted_at' => nil,
'updated_at' => Time.now.to_s, 'updated_at' => Time.now.strftime('%FT%T.%6N'),
'checksum' => Fog::Mock.random_hex(32), 'checksum' => attributes[:checksum] || Fog::Mock.random_hex(32),
'id' => image_id, 'id' => image_id,
'deleted' => false, 'deleted' => false,
'protected' => false, 'protected' => false,
'is_public' => false, 'is_public' => attributes[:is_public].to_s == 'true',
'status' => 'queued', 'status' => 'queued',
'min_ram' => 0, 'min_ram' => attributes[:min_ram] || 0,
'owner' => attributes['owner'] || attributes[:owner], 'owner' => attributes[:owner],
'properties' => attributes['properties'] || attributes[:properties] || {} 'properties' => attributes[:properties] || {}
} }
response.body = { 'image'=> image } response.body = { 'image'=> image }
response response

View file

@ -4,18 +4,17 @@ module Fog
class Real class Real
def update_image(attributes) def update_image(attributes)
data = {
data = { 'x-image-meta-name' => attributes[:name],
"x-image-meta-name" => attributes[:name], 'x-image-meta-disk-format' => attributes[:disk_format],
"x-image-meta-disk-format" => attributes[:disk_format], 'x-image-meta-container-format' => attributes[:container_format],
"x-image-meta-container-format" => attributes[:container_format], 'x-image-meta-size' => attributes[:size],
"x-image-meta-size" => attributes[:size], 'x-image-meta-is-public' => attributes[:is_public],
"x-image-meta-is-public" => attributes[:is_public], 'x-image-meta-min-ram' => attributes[:min_ram],
"x-image-meta-min-ram" => attributes[:min_ram], 'x-image-meta-min-disk' => attributes[:min_disk],
"x-image-meta-min-disk" => attributes[:min_disk], 'x-image-meta-checksum' => attributes[:checksum],
"x-image-meta-checksum" => attributes[:checksum], 'x-image-meta-owner' => attributes[:owner]
"x-image-meta-owner" => attributes[:owner] }.reject {|k,v| v.nil? }
}
unless attributes[:properties].nil? unless attributes[:properties].nil?
attributes[:properties].each do |key,value| attributes[:properties].each do |key,value|
@ -40,28 +39,27 @@ module Fog
response.status = 200 response.status = 200
image = self.images.last image = self.images.last
response.body = { response.body = {
'image'=> { 'image'=> {
'name' => attributes[:name] || image.name, 'name' => attributes[:name] || image.name,
'size' => image.size, 'size' => image.size,
'min_disk' => (attributes[:min_disk] || image.min_disk).to_i, 'min_disk' => (attributes[:min_disk] || image.min_disk).to_i,
'disk_format' => attributes[:disk_format] || image.disk_format, 'disk_format' => attributes[:disk_format] || image.disk_format,
'created_at' => image.created_at, 'created_at' => image.created_at,
'container_format' => attributes[:container_format] || image.container_format, 'container_format' => attributes[:container_format] || image.container_format,
'deleted_at' => nil, 'deleted_at' => nil,
'updated_at' => Time.now.to_s, 'updated_at' => Time.now.to_s,
'checksum' => image.checksum, 'checksum' => image.checksum,
'id' => attributes[:id], 'id' => attributes[:id],
'deleted' => false, 'deleted' => false,
'protected' => false, 'protected' => false,
'is_public' => attributes[:is_public] || image.is_public, 'is_public' => attributes[:is_public] || image.is_public,
'status' => image.status, 'status' => image.status,
'min_ram' => (attributes[:min_ram] || image.min_ram).to_i, 'min_ram' => (attributes[:min_ram] || image.min_ram).to_i,
'owner' => attributes[:owner] || image.owner, 'owner' => attributes[:owner] || image.owner,
'properties' => attributes[:properties] || image.properties 'properties' => attributes[:properties] || image.properties
} }
} }
response response
end end
end end

View file

@ -1,15 +1,15 @@
Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
openstack = Fog::Identity[:openstack] openstack = Fog::Identity[:openstack]
@image_attributes = { @image_attributes = {
'name' => 'new image', :name => 'new image',
'owner' => openstack.current_tenant['id'], :owner => openstack.current_tenant['id'],
'is_public' => 'true', :is_public => true,
'copy_from' => 'http://website.com/image.iso', :copy_from => 'http://website.com/image.iso',
'disk_format' => 'iso', :disk_format => 'iso',
'properties' => :properties =>
{'user_id' => openstack.current_user['id'], {:user_id => openstack.current_user['id'],
'owner_id' => openstack.current_tenant['id']}, :owner_id => openstack.current_tenant['id']},
'container_format'=> 'bare' } :container_format => 'bare' }
@image_format = { @image_format = {
'name' => String, 'name' => String,
@ -72,23 +72,38 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
] ]
tests('success') do tests('success') do
tests('#list_public_images').formats({'images' => [@image_format]}) do tests('#list_public_images').data_matches_schema({'images' => [@image_format]}) do
Fog::Image[:openstack].list_public_images.body Fog::Image[:openstack].list_public_images.body
end end
tests('#list_public_images_detailed').formats({'images' => [@detailed_image_format]}) do tests('#list_public_images_detailed').data_matches_schema({'images' => [@detailed_image_format]}) do
Fog::Image[:openstack].list_public_images_detailed.body Fog::Image[:openstack].list_public_images_detailed.body
end end
tests('#create_image').formats({'image' => @detailed_image_format}) do tests('#create_image').data_matches_schema({'image' => @detailed_image_format}) do
@instance = Fog::Image[:openstack].create_image(@image_attributes).body begin
if Fog.mocking?
image_attributes = @image_attributes
else
require 'tempfile'
image_attributes = @image_attributes.dup
image_attributes.delete(:copy_from)
test_iso = Tempfile.new(['fog_test_iso', '.iso'])
test_iso.write Fog::Mock.random_hex(32)
test_iso.close
image_attributes[:location] = test_iso.path
end
@instance = Fog::Image[:openstack].create_image(image_attributes).body
ensure
test_iso.delete if test_iso
end
end end
tests('#get_image').formats(@image_meta_format) do tests('#get_image').data_matches_schema(@image_meta_format) do
Fog::Image[:openstack].get_image(@instance['image']['id']).headers Fog::Image[:openstack].get_image(@instance['image']['id']).headers
end end
tests('#update_image').formats(@detailed_image_format) do tests('#update_image').data_matches_schema(@detailed_image_format) do
Fog::Image[:openstack].update_image({:id => @instance['image']['id'], Fog::Image[:openstack].update_image({:id => @instance['image']['id'],
:name => 'edit image'}).body['image'] :name => 'edit image'}).body['image']
end end