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:
commit
b1c8268f6d
3 changed files with 84 additions and 71 deletions
|
@ -5,18 +5,18 @@ module Fog
|
|||
|
||||
def create_image(attributes)
|
||||
data = {
|
||||
'Content-Type'=>'application/octet-stream',
|
||||
'x-image-meta-name' => attributes[:name],
|
||||
'x-image-meta-disk-format' => attributes[:disk_format],
|
||||
'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]
|
||||
}.reject { |k,v| v.nil? }
|
||||
'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]
|
||||
}.reject {|k,v| v.nil? }
|
||||
|
||||
body = String.new
|
||||
if attributes[:location]
|
||||
|
@ -52,23 +52,23 @@ module Fog
|
|||
|
||||
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',
|
||||
'name' => attributes[:name],
|
||||
'size' => attributes[:size] || Fog::Mock.random_numbers(8).to_i,
|
||||
'min_disk' => attributes[:min_disk] || 0,
|
||||
'disk_format' => attributes[:disk_format] || 'raw',
|
||||
'created_at' => Time.now.strftime('%FT%T.%6N'),
|
||||
'container_format' => attributes[:container_format] || 'bare',
|
||||
'deleted_at' => nil,
|
||||
'updated_at' => Time.now.to_s,
|
||||
'checksum' => Fog::Mock.random_hex(32),
|
||||
'updated_at' => Time.now.strftime('%FT%T.%6N'),
|
||||
'checksum' => attributes[:checksum] || Fog::Mock.random_hex(32),
|
||||
'id' => image_id,
|
||||
'deleted' => false,
|
||||
'protected' => false,
|
||||
'is_public' => false,
|
||||
'is_public' => attributes[:is_public].to_s == 'true',
|
||||
'status' => 'queued',
|
||||
'min_ram' => 0,
|
||||
'owner' => attributes['owner'] || attributes[:owner],
|
||||
'properties' => attributes['properties'] || attributes[:properties] || {}
|
||||
'min_ram' => attributes[:min_ram] || 0,
|
||||
'owner' => attributes[:owner],
|
||||
'properties' => attributes[:properties] || {}
|
||||
}
|
||||
response.body = { 'image'=> image }
|
||||
response
|
||||
|
|
|
@ -4,18 +4,17 @@ module Fog
|
|||
class Real
|
||||
|
||||
def update_image(attributes)
|
||||
|
||||
data = {
|
||||
"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]
|
||||
}
|
||||
data = {
|
||||
'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]
|
||||
}.reject {|k,v| v.nil? }
|
||||
|
||||
unless attributes[:properties].nil?
|
||||
attributes[:properties].each do |key,value|
|
||||
|
@ -40,28 +39,27 @@ module Fog
|
|||
response.status = 200
|
||||
image = self.images.last
|
||||
response.body = {
|
||||
'image'=> {
|
||||
'name' => attributes[:name] || image.name,
|
||||
'size' => image.size,
|
||||
'min_disk' => (attributes[:min_disk] || image.min_disk).to_i,
|
||||
'disk_format' => attributes[:disk_format] || image.disk_format,
|
||||
'created_at' => image.created_at,
|
||||
'container_format' => attributes[:container_format] || image.container_format,
|
||||
'deleted_at' => nil,
|
||||
'updated_at' => Time.now.to_s,
|
||||
'checksum' => image.checksum,
|
||||
'id' => attributes[:id],
|
||||
'deleted' => false,
|
||||
'protected' => false,
|
||||
'is_public' => attributes[:is_public] || image.is_public,
|
||||
'status' => image.status,
|
||||
'min_ram' => (attributes[:min_ram] || image.min_ram).to_i,
|
||||
'owner' => attributes[:owner] || image.owner,
|
||||
'properties' => attributes[:properties] || image.properties
|
||||
}
|
||||
}
|
||||
'image'=> {
|
||||
'name' => attributes[:name] || image.name,
|
||||
'size' => image.size,
|
||||
'min_disk' => (attributes[:min_disk] || image.min_disk).to_i,
|
||||
'disk_format' => attributes[:disk_format] || image.disk_format,
|
||||
'created_at' => image.created_at,
|
||||
'container_format' => attributes[:container_format] || image.container_format,
|
||||
'deleted_at' => nil,
|
||||
'updated_at' => Time.now.to_s,
|
||||
'checksum' => image.checksum,
|
||||
'id' => attributes[:id],
|
||||
'deleted' => false,
|
||||
'protected' => false,
|
||||
'is_public' => attributes[:is_public] || image.is_public,
|
||||
'status' => image.status,
|
||||
'min_ram' => (attributes[:min_ram] || image.min_ram).to_i,
|
||||
'owner' => attributes[:owner] || image.owner,
|
||||
'properties' => attributes[:properties] || image.properties
|
||||
}
|
||||
}
|
||||
response
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
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' }
|
||||
: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,
|
||||
|
@ -72,23 +72,38 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) 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
|
||||
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
|
||||
end
|
||||
|
||||
tests('#create_image').formats({'image' => @detailed_image_format}) do
|
||||
@instance = Fog::Image[:openstack].create_image(@image_attributes).body
|
||||
tests('#create_image').data_matches_schema({'image' => @detailed_image_format}) do
|
||||
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
|
||||
|
||||
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
|
||||
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'],
|
||||
:name => 'edit image'}).body['image']
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue